Skip to content

Commit 156d601

Browse files
nzakasfasttime
andauthored
fix: Update RuleVisitor type (#135)
Co-authored-by: Francesco Trotta <[email protected]>
1 parent 8852527 commit 156d601

File tree

11 files changed

+66
-69
lines changed

11 files changed

+66
-69
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#### Prerequisites checklist
88

9-
- [ ] I have read the [contributing guidelines](https://github.com/eslint/eslint/blob/HEAD/CONTRIBUTING.md).
9+
- [ ] I have read the [contributing guidelines](https://github.com/eslint/eslint/blob/HEAD/CONTRIBUTING.md).
1010

1111
<!--
1212
Please ensure your pull request is ready:

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ Monorepo for the rewrite of ESLint.
66

77
This repository is the home of the following packages:
88

9-
- [`@eslint/core`](packages/core)
10-
- [`@eslint/compat`](packages/compat)
11-
- [`@eslint/config-array`](packages/config-array)
12-
- [`@eslint/object-schema`](packages/object-schema)
13-
- [`@eslint/migrate-config`](packages/migrate-config)
9+
- [`@eslint/core`](packages/core)
10+
- [`@eslint/compat`](packages/compat)
11+
- [`@eslint/config-array`](packages/config-array)
12+
- [`@eslint/object-schema`](packages/object-schema)
13+
- [`@eslint/migrate-config`](packages/migrate-config)
1414

1515
<!-- NOTE: This section is autogenerated. Do not manually edit.-->
1616
<!--sponsorsstart-->

decisions/001-rewrite-core.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ When the new core is ready, we will need to be careful about the migration plan
2525

2626
## See Also
2727

28-
- <https://github.com/eslint/eslint/discussions/16557>
28+
- <https://github.com/eslint/eslint/discussions/16557>

decisions/004-types.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ We do not intend to take over full maintenance of `@types/eslint`. Instead, we w
2626

2727
For the ESLint team, this decision will:
2828

29-
- Ensure we have control over our type definitions.
30-
- Allow us to design a more coherent and well-integrated type system in the new `@eslint/core`.
31-
- Provide a clear path for integrating these types with `@types/eslint`, improving consistency across the ecosystem.
29+
- Ensure we have control over our type definitions.
30+
- Allow us to design a more coherent and well-integrated type system in the new `@eslint/core`.
31+
- Provide a clear path for integrating these types with `@types/eslint`, improving consistency across the ecosystem.
3232

3333
For the community, this decision may:
3434

35-
- Require adjustments to adapt to the new type definitions in `@eslint/core`.
36-
- Improve the accuracy and reliability of type definitions used in ESLint-related projects.
35+
- Require adjustments to adapt to the new type definitions in `@eslint/core`.
36+
- Improve the accuracy and reliability of type definitions used in ESLint-related projects.
3737

3838
We recognize that this may frustrate or anger some contributors, but we believe that this approach balances the need for accurate type definitions with the practicalities of maintaining a complex project like ESLint.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"eslint-config-eslint": "^11.0.0",
3434
"got": "^14.4.1",
3535
"lint-staged": "^15.2.0",
36-
"prettier": "^3.1.1",
36+
"prettier": "^3.4.1",
3737
"typescript": "^5.5.3",
3838
"typescript-eslint": "^8.0.0",
3939
"yorkie": "^2.0.0"

packages/compat/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ deno add @eslint/compat
3030

3131
This package exports the following functions in both ESM and CommonJS format:
3232

33-
- `fixupRule(rule)` - wraps the given rule in a compatibility layer and returns the result
34-
- `fixupPluginRules(plugin)` - wraps each rule in the given plugin using `fixupRule()` and returns a new object that represents the plugin with the fixed-up rules
35-
- `fixupConfigRules(configs)` - wraps all plugins found in an array of config objects using `fixupPluginRules()`
36-
- `includeIgnoreFile(path)` - reads an ignore file (like `.gitignore`) and converts the patterns into the correct format for the config file
33+
- `fixupRule(rule)` - wraps the given rule in a compatibility layer and returns the result
34+
- `fixupPluginRules(plugin)` - wraps each rule in the given plugin using `fixupRule()` and returns a new object that represents the plugin with the fixed-up rules
35+
- `fixupConfigRules(configs)` - wraps all plugins found in an array of config objects using `fixupPluginRules()`
36+
- `includeIgnoreFile(path)` - reads an ignore file (like `.gitignore`) and converts the patterns into the correct format for the config file
3737

3838
### Fixing Rules
3939

packages/config-array/README.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,10 @@ The config array always returns an object, even if there are no configs matching
283283

284284
A few things to keep in mind:
285285

286-
- If a filename is not an absolute path, it will be resolved relative to the base path directory.
287-
- The returned config object never has `files`, `ignores`, or `name` properties; the only properties on the object will be the other configuration options specified.
288-
- The config array caches configs, so subsequent calls to `getConfig()` with the same filename will return in a fast lookup rather than another calculation.
289-
- A config will only be generated if the filename matches an entry in a `files` key. A config will not be generated without matching a `files` key (configs without a `files` key are only applied when another config with a `files` key is applied; configs without `files` are never applied on their own). Any config with a `files` key entry that is `*` or ends with `/**` or `/*` will only be applied if another entry in the same `files` key matches or another config matches.
286+
- If a filename is not an absolute path, it will be resolved relative to the base path directory.
287+
- The returned config object never has `files`, `ignores`, or `name` properties; the only properties on the object will be the other configuration options specified.
288+
- The config array caches configs, so subsequent calls to `getConfig()` with the same filename will return in a fast lookup rather than another calculation.
289+
- A config will only be generated if the filename matches an entry in a `files` key. A config will not be generated without matching a `files` key (configs without a `files` key are only applied when another config with a `files` key is applied; configs without `files` are never applied on their own). Any config with a `files` key entry that is `*` or ends with `/**` or `/*` will only be applied if another entry in the same `files` key matches or another config matches.
290290

291291
## Determining Ignored Paths
292292

@@ -298,11 +298,11 @@ const ignored = configs.isFileIgnored("/foo/bar/baz.txt");
298298

299299
A file is considered ignored if any of the following is true:
300300

301-
- **It's parent directory is ignored.** For example, if `foo` is in `ignores`, then `foo/a.js` is considered ignored.
302-
- **It has an ancestor directory that is ignored.** For example, if `foo` is in `ignores`, then `foo/baz/a.js` is considered ignored.
303-
- **It matches an ignored file pattern.** For example, if `**/a.js` is in `ignores`, then `foo/a.js` and `foo/baz/a.js` are considered ignored.
304-
- **If it matches an entry in `files` and also in `ignores`.** For example, if `**/*.js` is in `files` and `**/a.js` is in `ignores`, then `foo/a.js` and `foo/baz/a.js` are considered ignored.
305-
- **The file is outside the `basePath`.** If the `basePath` is `/usr/me`, then `/foo/a.js` is considered ignored.
301+
- **It's parent directory is ignored.** For example, if `foo` is in `ignores`, then `foo/a.js` is considered ignored.
302+
- **It has an ancestor directory that is ignored.** For example, if `foo` is in `ignores`, then `foo/baz/a.js` is considered ignored.
303+
- **It matches an ignored file pattern.** For example, if `**/a.js` is in `ignores`, then `foo/a.js` and `foo/baz/a.js` are considered ignored.
304+
- **If it matches an entry in `files` and also in `ignores`.** For example, if `**/*.js` is in `files` and `**/a.js` is in `ignores`, then `foo/a.js` and `foo/baz/a.js` are considered ignored.
305+
- **The file is outside the `basePath`.** If the `basePath` is `/usr/me`, then `/foo/a.js` is considered ignored.
306306

307307
For directories, use the `isDirectoryIgnored()` method and pass in the path of any directory, as in this example:
308308

@@ -312,11 +312,11 @@ const ignored = configs.isDirectoryIgnored("/foo/bar/");
312312

313313
A directory is considered ignored if any of the following is true:
314314

315-
- **It's parent directory is ignored.** For example, if `foo` is in `ignores`, then `foo/baz` is considered ignored.
316-
- **It has an ancestor directory that is ignored.** For example, if `foo` is in `ignores`, then `foo/bar/baz/a.js` is considered ignored.
317-
- **It matches and ignored file pattern.** For example, if `**/a.js` is in `ignores`, then `foo/a.js` and `foo/baz/a.js` are considered ignored.
318-
- **If it matches an entry in `files` and also in `ignores`.** For example, if `**/*.js` is in `files` and `**/a.js` is in `ignores`, then `foo/a.js` and `foo/baz/a.js` are considered ignored.
319-
- **The file is outside the `basePath`.** If the `basePath` is `/usr/me`, then `/foo/a.js` is considered ignored.
315+
- **It's parent directory is ignored.** For example, if `foo` is in `ignores`, then `foo/baz` is considered ignored.
316+
- **It has an ancestor directory that is ignored.** For example, if `foo` is in `ignores`, then `foo/bar/baz/a.js` is considered ignored.
317+
- **It matches and ignored file pattern.** For example, if `**/a.js` is in `ignores`, then `foo/a.js` and `foo/baz/a.js` are considered ignored.
318+
- **If it matches an entry in `files` and also in `ignores`.** For example, if `**/*.js` is in `files` and `**/a.js` is in `ignores`, then `foo/a.js` and `foo/baz/a.js` are considered ignored.
319+
- **The file is outside the `basePath`.** If the `basePath` is `/usr/me`, then `/foo/a.js` is considered ignored.
320320

321321
**Important:** A pattern such as `foo/**` means that `foo` and `foo/` are _not_ ignored whereas `foo/bar` is ignored. If you want to ignore `foo` and all of its subdirectories, use the pattern `foo` or `foo/` in `ignores`.
322322

@@ -331,9 +331,9 @@ Each `ConfigArray` aggressively caches configuration objects to avoid unnecessar
331331

332332
The design of this project was influenced by feedback on the ESLint RFC, and incorporates ideas from:
333333

334-
- Teddy Katz (@not-an-aardvark)
335-
- Toru Nagashima (@mysticatea)
336-
- Kai Cataldo (@kaicataldo)
334+
- Teddy Katz (@not-an-aardvark)
335+
- Toru Nagashima (@mysticatea)
336+
- Kai Cataldo (@kaicataldo)
337337

338338
## License
339339

packages/core/src/types.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,17 @@ export type RuleType = "problem" | "suggestion" | "layout";
9292
*/
9393
export type RuleFixType = "code" | "whitespace";
9494

95-
/* eslint-disable @typescript-eslint/consistent-indexed-object-style -- Needs to be interface so people can extend it. */
9695
/* eslint-disable @typescript-eslint/no-explicit-any -- Necessary to allow subclasses to work correctly */
9796
/**
9897
* An object containing visitor information for a rule. Each method is either the
9998
* name of a node type or a selector, or is a method that will be called at specific
10099
* times during the traversal.
101100
*/
102-
export interface RuleVisitor {
103-
/**
104-
* Called for each node in the AST or at specific times during the traversal.
105-
*/
106-
[key: string]: (...args: any[]) => void;
107-
}
108-
/* eslint-enable @typescript-eslint/consistent-indexed-object-style -- Needs to be interface so people can extend it. */
101+
export type RuleVisitor = Record<
102+
string,
103+
((...args: any[]) => void) | undefined
104+
>;
105+
109106
/* eslint-enable @typescript-eslint/no-explicit-any -- Necessary to allow subclasses to work correctly */
110107

111108
/**

packages/migrate-config/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ This package aids in the migration of the legacy ESLint configuration file forma
1010

1111
This tool currently works well for the following config file formats:
1212

13-
- `.eslintrc`
14-
- `.eslintrc.json`
15-
- `.eslintrc.yml`
13+
- `.eslintrc`
14+
- `.eslintrc.json`
15+
- `.eslintrc.yml`
1616

1717
If you are using a JavaScript configuration file (`.eslintrc.js`, `.eslintrc.cjs`, `.eslintrc.mjs`), this tool currently is only capable of migrating the _evaluated_ configuration. That means any logic you may have inside of the file will be lost. If your configuration file is mostly static, then you'll get a good result; if your configuration file is more complex (using functions, calculating paths, etc.) then this tool will not provide an equivalent configuration file.
1818

packages/object-schema/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ const result = {
9494

9595
Instead of specifying a `merge()` method, you can specify one of the following strings to use a default merge strategy:
9696

97-
- `"assign"` - use `Object.assign()` to merge the two values into one object.
98-
- `"overwrite"` - the second value always replaces the first.
99-
- `"replace"` - the second value replaces the first if the second is not `undefined`.
97+
- `"assign"` - use `Object.assign()` to merge the two values into one object.
98+
- `"overwrite"` - the second value always replaces the first.
99+
- `"replace"` - the second value replaces the first if the second is not `undefined`.
100100

101101
For example:
102102

@@ -113,13 +113,13 @@ const schema = new ObjectSchema({
113113

114114
Instead of specifying a `validate()` method, you can specify one of the following strings to use a default validation strategy:
115115

116-
- `"array"` - value must be an array.
117-
- `"boolean"` - value must be a boolean.
118-
- `"number"` - value must be a number.
119-
- `"object"` - value must be an object.
120-
- `"object?"` - value must be an object or null.
121-
- `"string"` - value must be a string.
122-
- `"string!"` - value must be a non-empty string.
116+
- `"array"` - value must be an array.
117+
- `"boolean"` - value must be a boolean.
118+
- `"number"` - value must be a number.
119+
- `"object"` - value must be an object.
120+
- `"object?"` - value must be an object or null.
121+
- `"string"` - value must be a string.
122+
- `"string!"` - value must be a non-empty string.
123123

124124
For example:
125125

packages/plugin-kit/README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ deno add @eslint/plugin-kit
2828

2929
This package exports the following utilities:
3030

31-
- `ConfigCommentParser` - used to parse ESLint configuration comments (i.e., `/* eslint-disable rule */`)
32-
- `VisitNodeStep` and `CallMethodStep` - used to help implement `SourceCode#traverse()`
33-
- `Directive` - used to help implement `SourceCode#getDisableDirectives()`
34-
- `TextSourceCodeBase` - base class to help implement the `SourceCode` interface
31+
- `ConfigCommentParser` - used to parse ESLint configuration comments (i.e., `/* eslint-disable rule */`)
32+
- `VisitNodeStep` and `CallMethodStep` - used to help implement `SourceCode#traverse()`
33+
- `Directive` - used to help implement `SourceCode#getDisableDirectives()`
34+
- `TextSourceCodeBase` - base class to help implement the `SourceCode` interface
3535

3636
### `ConfigCommentParser`
3737

@@ -85,9 +85,9 @@ The `VisitNodeStep` and `CallMethodStep` classes represent steps in the traversa
8585

8686
The `VisitNodeStep` class is the more common of the two, where you are describing a visit to a particular node during the traversal. The constructor accepts three arguments:
8787

88-
- `target` - the node being visited. This is used to determine the method to call inside of a rule. For instance, if the node's type is `Literal` then ESLint will call a method named `Literal()` on the rule (if present).
89-
- `phase` - either 1 for enter or 2 for exit.
90-
- `args` - an array of arguments to pass into the visitor method of a rule.
88+
- `target` - the node being visited. This is used to determine the method to call inside of a rule. For instance, if the node's type is `Literal` then ESLint will call a method named `Literal()` on the rule (if present).
89+
- `phase` - either 1 for enter or 2 for exit.
90+
- `args` - an array of arguments to pass into the visitor method of a rule.
9191

9292
For example:
9393

@@ -115,8 +115,8 @@ class MySourceCode {
115115

116116
The `CallMethodStep` class is less common and is used to tell ESLint to call a specific method on the rule. The constructor accepts two arguments:
117117

118-
- `target` - the name of the method to call, frequently beginning with `"on"` such as `"onCodePathStart"`.
119-
- `args` - an array of arguments to pass to the method.
118+
- `target` - the name of the method to call, frequently beginning with `"on"` such as `"onCodePathStart"`.
119+
- `args` - an array of arguments to pass to the method.
120120

121121
For example:
122122

@@ -205,11 +205,11 @@ class MySourceCode {
205205

206206
The `TextSourceCodeBase` class is intended to be a base class that has several of the common members found in `SourceCode` objects already implemented. Those members are:
207207

208-
- `lines` - an array of text lines that is created automatically when the constructor is called.
209-
- `getLoc(node)` - gets the location of a node. Works for nodes that have the ESLint-style `loc` property and nodes that have the Unist-style [`position` property](https://github.com/syntax-tree/unist?tab=readme-ov-file#position). If you're using an AST with a different location format, you'll still need to implement this method yourself.
210-
- `getRange(node)` - gets the range of a node within the source text. Works for nodes that have the ESLint-style `range` property and nodes that have the Unist-style [`position` property](https://github.com/syntax-tree/unist?tab=readme-ov-file#position). If you're using an AST with a different range format, you'll still need to implement this method yourself.
211-
- `getText(nodeOrToken, charsBefore, charsAfter)` - gets the source text for the given node or token that has range information attached. Optionally, can return additional characters before and after the given node or token. As long as `getRange()` is properly implemented, this method will just work.
212-
- `getAncestors(node)` - returns the ancestry of the node. In order for this to work, you must implement the `getParent()` method yourself.
208+
- `lines` - an array of text lines that is created automatically when the constructor is called.
209+
- `getLoc(node)` - gets the location of a node. Works for nodes that have the ESLint-style `loc` property and nodes that have the Unist-style [`position` property](https://github.com/syntax-tree/unist?tab=readme-ov-file#position). If you're using an AST with a different location format, you'll still need to implement this method yourself.
210+
- `getRange(node)` - gets the range of a node within the source text. Works for nodes that have the ESLint-style `range` property and nodes that have the Unist-style [`position` property](https://github.com/syntax-tree/unist?tab=readme-ov-file#position). If you're using an AST with a different range format, you'll still need to implement this method yourself.
211+
- `getText(nodeOrToken, charsBefore, charsAfter)` - gets the source text for the given node or token that has range information attached. Optionally, can return additional characters before and after the given node or token. As long as `getRange()` is properly implemented, this method will just work.
212+
- `getAncestors(node)` - returns the ancestry of the node. In order for this to work, you must implement the `getParent()` method yourself.
213213

214214
Here's an example:
215215

0 commit comments

Comments
 (0)