How to use the @typescript-eslint/parser.parseForESLint function in @typescript-eslint/parser

To help you get started, we’ve selected a few @typescript-eslint/parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SonarSource / SonarJS / eslint-bridge / src / parser.ts View on Github external
export function parseTypeScriptSourceFile(
  fileContent: string,
  filePath: string,
  tsConfigs?: string[],
): SourceCode | ParsingError {
  try {
    checkTypeScriptVersionCompatibility(require("typescript").version);
    // we load the typescript parser dynamically, so we don't need typescript dependency when analyzing pure JS project
    const tsParser = require("@typescript-eslint/parser");
    const result = tsParser.parseForESLint(fileContent, {
      ...PARSER_CONFIG_MODULE,
      filePath: filePath,
      project: tsConfigs,
      loggerFn: console.log,
    });
    return new SourceCode({ ...result, parserServices: result.services, text: fileContent });
  } catch (exception) {
    return {
      line: exception.lineNumber,
      message: exception.message,
      code: parseExceptionCodeOf(exception.message),
    };
  }
}

@typescript-eslint/parser

An ESLint custom parser which leverages TypeScript ESTree

BSD-2-Clause
Latest version published 8 days ago

Package Health Score

95 / 100
Full package analysis