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 {
    // 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, {
      filePath: filePath,
      project: tsConfigs,
      loggerFn: console.log,
    return new SourceCode({ ...result, parserServices:, text: fileContent });
  } catch (exception) {
    return {
      line: exception.lineNumber,
      message: exception.message,
      code: parseExceptionCodeOf(exception.message),