diff --git a/designs/2022-languages/README.md b/designs/2022-languages/README.md index 6b368e6e..aa4f48bf 100644 --- a/designs/2022-languages/README.md +++ b/designs/2022-languages/README.md @@ -114,6 +114,11 @@ interface ESLintLanguage { */ nodeTypeKey: string; + /** + * The traversal path that tools should take when evaluating the AST + */ + visitorKeys: Record>; + /** * Validates languageOptions for this language. */ @@ -273,6 +278,11 @@ interface SourceCode { */ body: string | ArrayBuffer; + /** + * The traversal path that tools should take when evaluating the AST + */ + visitorKeys?: Record>; + /** * Traversal of AST. */ @@ -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: