Skip to content

Commit

Permalink
Add visitorKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
nzakas committed Mar 15, 2023
1 parent 07be891 commit 6b1b0aa
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions designs/2022-languages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ interface ESLintLanguage {
*/
nodeTypeKey: string;

/**
* The traversal path that tools should take when evaluating the AST
*/
visitorKeys: Record<string,Array<string>>;

/**
* Validates languageOptions for this language.
*/
Expand Down Expand Up @@ -273,6 +278,11 @@ interface SourceCode {
*/
body: string | ArrayBuffer;

/**
* The traversal path that tools should take when evaluating the AST
*/
visitorKeys?: Record<string,Array<string>>;

/**
* Traversal of AST.
*/
Expand Down Expand Up @@ -334,6 +344,10 @@ interface Location {
Other than these interface members, languages may define any additional methods or properties that they need to provide to rule developers. For instance,
the JavaScript `SourceCode` object currently has methods allowing retrieval of tokens, comments, and lines. It is up to the individual language object implementations to determine what additional properties and methods may be required inside of rules. (We may want to provide some best practices for other methods, but they won't be required.)

#### The `SoureCode#visitorKeys` Property

The JavaScript language allows a `parser` option to be passed in, and so the result AST may not be the exact structure represented on the `ESLintLanguage` object. In such a case, an additional `visitorKeys` property can be provided on `SourceCode` that overrides the `ESLintLanguage#visitorKeys` property just for this file.

#### The `SoureCode#traverse()` Method

Today, ESLint uses a [custom traverser](https://github.com/eslint/eslint/blob/b3a08376cfb61275a7557d6d166b6116f36e5ac2/lib/shared/traverser.js) based on data from [`eslint-visitor-keys`](https://npmjs.com/package/eslint-visitor-keys). All of this is specific to an ESTree-compatible AST structure. There are two problems with this:
Expand Down

0 comments on commit 6b1b0aa

Please sign in to comment.