This site uses cookies for analytics. By continuing to browse this site, you agree to this use.
A JS Foundation Project

Parsers

Parsers

A parser is capable of understanding more deeply a resource and expose that information via events so rules can be built on top of this information. E.g.: a JavaScript parser built on top of ESLint so rules for analyzing JavaScript files can be built.

You can specify what parsers you want to use via the .sonarwhalrc configuration file:

{
"parsers": ["parser1", "parser2"]
}

List of official parsers

  • javascript: A JavaScript parser built on top of ESLint so rules for analyzing JavaScript files can be built.

  • typescript-config: A parser that validates if the TypeScript configuration is valid.

How to use a parser

To use a parse you need to subscribe to the event(s) that the parser dispatches.

javascript parser

To create a rule that understands JavaScript you will need to use the event parse::javascript emitted by the javascript parser. This event is of type ScriptParse which has the following information:

  • resource: the parsed resource. If the JavaScript is in a script tag and not a file, the value will be Internal javascript.
  • sourceCode: a eslint SourceCode object.

typescript-config parser

To create a rule that understands a TypeScript configuration you will need to use the event parse::typescript-config emiited by the typescript-config. This event is of type TypeScriptConfigParse wich has the following information:

  • resource: the parsed resource.
  • config: an object with a valid the configuration.