How to use @typescript-eslint/parser - 4 common examples

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),
    };
  }
}
github typescript-eslint / typescript-eslint / packages / benchmark / parsers.js View on Github external
function runTSParser(directory, files) {
  for (const file of files) {
    const result = tsParser.parse(
      fs.readFileSync(path.join(__dirname, file), 'utf8'),
      {
        comment: true,
        tokens: true
      }
    );
    if (result.type !== 'Program') {
      throw new Error('something went wrong');
    }
  }
}
github fkling / astexplorer / website / src / parsers / js / typescript-eslint-parser.js View on Github external
import defaultParserInterface from './utils/defaultESTreeParserInterface';
import pkg from '@typescript-eslint/parser/package.json';

const ID = '@typescript-eslint/parser';

export default {
  ...defaultParserInterface,

  id: ID,
  displayName: ID,
  version: pkg.version,
  homepage: pkg.homepage || 'https://typescript-eslint.io/',
  locationProps: new Set(['loc', 'start', 'end', 'range']),

  loadParser(callback) {
    require(['@typescript-eslint/parser'], callback);
  },

  parse(parser, code, options) {
    return parser.parse(code, options);
  },

  getDefaultOptions() {
    return {
      range: true,
      loc: false,
      tokens: false,
      comment: false,
github fkling / astexplorer / website / src / parsers / js / typescript-eslint-parser.js View on Github external
import defaultParserInterface from './utils/defaultESTreeParserInterface';
import pkg from '@typescript-eslint/parser/package.json';

const ID = '@typescript-eslint/parser';

export default {
  ...defaultParserInterface,

  id: ID,
  displayName: ID,
  version: pkg.version,
  homepage: pkg.homepage || 'https://typescript-eslint.io/',
  locationProps: new Set(['loc', 'start', 'end', 'range']),

  loadParser(callback) {
    require(['@typescript-eslint/parser'], callback);
  },

  parse(parser, code, options) {
    return parser.parse(code, options);
  },

  getDefaultOptions() {
    return {
      range: true,
      loc: false,
      tokens: false,

@typescript-eslint/parser

An ESLint custom parser which leverages TypeScript ESTree

BSD-2-Clause
Latest version published 4 days ago

Package Health Score

98 / 100
Full package analysis