Skip to content

Commit 6b1b0aa

Browse files
committed
Add visitorKeys
1 parent 07be891 commit 6b1b0aa

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

designs/2022-languages/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ interface ESLintLanguage {
114114
*/
115115
nodeTypeKey: string;
116116

117+
/**
118+
* The traversal path that tools should take when evaluating the AST
119+
*/
120+
visitorKeys: Record<string,Array<string>>;
121+
117122
/**
118123
* Validates languageOptions for this language.
119124
*/
@@ -273,6 +278,11 @@ interface SourceCode {
273278
*/
274279
body: string | ArrayBuffer;
275280

281+
/**
282+
* The traversal path that tools should take when evaluating the AST
283+
*/
284+
visitorKeys?: Record<string,Array<string>>;
285+
276286
/**
277287
* Traversal of AST.
278288
*/
@@ -334,6 +344,10 @@ interface Location {
334344
Other than these interface members, languages may define any additional methods or properties that they need to provide to rule developers. For instance,
335345
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.)
336346

347+
#### The `SoureCode#visitorKeys` Property
348+
349+
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.
350+
337351
#### The `SoureCode#traverse()` Method
338352

339353
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:

0 commit comments

Comments
 (0)