You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/extend/custom-rules.md
+2-10Lines changed: 2 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,7 +65,7 @@ The source file for a rule exports an object with the following properties. Both
65
65
66
66
-`defaultOptions`: (`array`) Specifies [default options](#option-defaults) for the rule. If present, any user-provided options in their config will be merged on top of them recursively.
67
67
68
-
-`deprecated`: (`boolean | DeprecatedInfo`) Indicates whether the rule has been deprecated. You may omit the `deprecated` property if the rule has not been deprecated.
68
+
-`deprecated`: (`boolean | DeprecatedInfo`) Indicates whether the rule has been deprecated. You may omit the `deprecated` property if the rule has not been deprecated.
69
69
There is a dedicated page for the [DeprecatedInfo](./rule-deprecation)
70
70
71
71
-`replacedBy`: (`array`, **Deprecated** Use `meta.deprecated.replacedBy` instead.) In the case of a deprecated rule, specify replacement rule(s).
@@ -144,15 +144,9 @@ The `context` object has the following properties:
144
144
-`parser`: (`object`): The parser used to parse the current file.
145
145
-`parserOptions`: (`object`) The parser options configured for this file.
146
146
-`globals`: (`object`) The specified globals.
147
-
-`parserPath`: (`string`, **Removed** Use `context.languageOptions.parser` instead.) The name of the `parser` from the configuration.
148
-
-`parserOptions`: (**Deprecated** Use `context.languageOptions.parserOptions` instead.) The parser options configured for this run (more details [here](../use/configure/language-options#specifying-parser-options)).
149
147
150
148
Additionally, the `context` object has the following methods:
151
149
152
-
-`getCwd()`: (**Deprecated:** Use `context.cwd` instead.) Returns the `cwd` option passed to the [Linter](../integrate/nodejs-api#linter). It is a path to a directory that should be considered the current working directory.
153
-
-`getFilename()`: (**Deprecated:** Use `context.filename` instead.) Returns the filename associated with the source.
154
-
-`getPhysicalFilename()`: (**Deprecated:** Use `context.physicalFilename` instead.) When linting a file, it returns the full path of the file on disk without any code block information. When linting text, it returns the value passed to `—stdin-filename` or `<text>` if not specified.
155
-
-`getSourceCode()`: (**Deprecated:** Use `context.sourceCode` instead.) Returns a `SourceCode` object that you can use to work with the source that was passed to ESLint (see [Accessing the Source Code](#accessing-the-source-code)).
156
150
-`report(descriptor)`. Reports a problem in the code (see the [dedicated section](#reporting-problems)).
157
151
158
152
**Note:** Earlier versions of ESLint supported additional methods on the `context` object. Those methods were removed in the new format and should not be relied upon.
@@ -533,8 +527,6 @@ module.exports = {
533
527
};
534
528
```
535
529
536
-
**Deprecated:** The `context.getSourceCode()` method is deprecated; make sure to use `context.sourceCode` property instead.
537
-
538
530
Once you have an instance of `SourceCode`, you can use the following methods on it to work with the code:
539
531
540
532
-`getText(node)`: Returns the source code for the given node. Omit `node` to get the whole source (see the [dedicated section](#accessing-the-source-text)).
@@ -890,7 +882,7 @@ The following table contains a list of AST node types and the scope type that th
890
882
|`CatchClause`|`catch`|
891
883
| others | ※3 ※4 |
892
884
893
-
**※1** Only if the configured parser provided the block-scope feature. The default parser provides the block-scope feature if `parserOptions.ecmaVersion` is not less than `6`.<br>
885
+
**※1** Only if the configured parser provided the block-scope feature. The default parser provides the block-scope feature if `languageOptions.ecmaVersion` is not less than `6`.<br>
894
886
**※2** Only if the `for` statement defines the iteration variable as a block-scoped variable (E.g., `for (let i = 0;;) {}`).<br>
895
887
**※3** The scope of the closest ancestor node which has own scope. If the closest ancestor node has multiple scopes then it chooses the innermost scope (E.g., the `Program` node has a `global` scope and a `module` scope if `Program#sourceType` is `"module"`. The innermost scope is the `module` scope.).<br>
896
888
**※4** Each `PropertyDefinition#value` node (it can be any expression node type), has a `class-field-initializer` scope. For example, in `class C { field = 1 }`, the `Literal` node that represents `1` has a `class-field-initializer` scope. If the node has other scopes, the `class-field-initializer` scope will be the outermost one. For example, in `class C { field = () => {} }`, the `ArrowFunctionExpression` node has two scopes: `class-field-initializer` and `function`.
Copy file name to clipboardExpand all lines: docs/src/integrate/nodejs-api.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -641,7 +641,7 @@ The `Linter` object does the actual evaluation of the JavaScript code. It doesn'
641
641
642
642
The `Linter` is a constructor, and you can create a new instance by passing in the options you want to use. The available options are:
643
643
644
-
- `cwd` - Path to a directory that should be considered as the current working directory. It is accessible to rules from `context.cwd`or by calling `context.getCwd()`(see [The Context Object](../extend/custom-rules#the-context-object)). If `cwd` is `undefined`, it will be normalized to `process.cwd()` if the global `process` object is defined (for example, in the Node.js runtime) , or `undefined` otherwise.
644
+
- `cwd` - Path to a directory that should be considered as the current working directory. It is accessible to rules from `context.cwd` (see [The Context Object](../extend/custom-rules#the-context-object)). If `cwd` is `undefined`, it will be normalized to `process.cwd()` if the global `process` object is defined (for example, in the Node.js runtime) , or `undefined` otherwise.
In this example, rules run on `linter1` will get `path/to/project` from `context.cwd` or when calling `context.getCwd()`.
654
+
In this example, rules run on `linter1` will get `path/to/project` from `context.cwd`.
655
655
Those run on `linter2` will get `process.cwd()` if the global `process` object is defined or `undefined` otherwise (e.g. on the browser <https://eslint.org/demo>).
Copy file name to clipboardExpand all lines: docs/src/use/migrate-to-10.0.0.md
+50-8Lines changed: 50 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,6 +34,7 @@ The lists below are ordered roughly by the number of users each change is expect
34
34
-[`Program` AST node range spans entire source text](#program-node-range)
35
35
-[Fixer methods now require string `text` arguments](#fixer-text-must-be-string)
36
36
-[New requirements for `ScopeManager` implementations](#scope-manager)
37
+
-[Removal of deprecated `context` members](#rule-context)
37
38
38
39
### Breaking changes for integration developers
39
40
@@ -70,7 +71,7 @@ Three new rules have been enabled in `eslint:recommended`:
70
71
71
72
## <aname="config-lookup-from-file"></a> New configuration file lookup algorithm
72
73
73
-
In ESLint v9, the alternate config lookup behavior could be enabled with the `v10_config_lookup_from_file` feature flag. This behavior made ESLint locate `eslint.config.*` by starting from the directory of each linted file and searching up towards the filesystem root. In ESLint v10, this behavior is now the default and the `v10_config_lookup_from_file` flag has been removed. Attempting to use this flag will now result in an error.
74
+
In ESLint v9, the alternate config lookup behavior could be enabled with the `v10_config_lookup_from_file` feature flag. This behavior made ESLint locate `eslint.config.*` by starting from the directory of each linted file and searching up towards the filesystem root. In ESLint v10.0.0, this behavior is now the default and the `v10_config_lookup_from_file` flag has been removed. Attempting to use this flag will now result in an error.
74
75
75
76
**To address:**
76
77
@@ -134,7 +135,7 @@ The default behavior of this rule has not been changed.
134
135
135
136
## <aname="no-shadow-restricted-names"></a> `no-shadow-restricted-names` now reports `globalThis` by default
136
137
137
-
In ESLint v10, the [`no-shadow-restricted-names`](../rules/no-shadow-restricted-names) rule now treats `globalThis` as a restricted name by default. Consequently, the `reportGlobalThis` option now defaults to `true` (previously `false`). As a result, declarations such as `const globalThis = "foo";` or `function globalThis() {}` will now be reported by default.
138
+
In ESLint v10.0.0, the [`no-shadow-restricted-names`](../rules/no-shadow-restricted-names) rule now treats `globalThis` as a restricted name by default. Consequently, the `reportGlobalThis` option now defaults to `true` (previously `false`). As a result, declarations such as `const globalThis = "foo";` or `function globalThis() {}` will now be reported by default.
138
139
139
140
**To address:**
140
141
@@ -153,7 +154,7 @@ In ESLint v10, the [`no-shadow-restricted-names`](../rules/no-shadow-restricted-
153
154
154
155
## <aname="func-names"></a> `func-names` schema is stricter
155
156
156
-
In ESLint v10, the [`func-names`](../rules/func-names) rule schema now disallows extra items in the options array. Previously, configurations that included additional array elements beyond the allowed options were accepted but ignored. Such configurations are now considered invalid.
157
+
In ESLint v10.0.0, the [`func-names`](../rules/func-names) rule schema now disallows extra items in the options array. Previously, configurations that included additional array elements beyond the allowed options were accepted but ignored. Such configurations are now considered invalid.
157
158
158
159
For example, this configuration is now invalid due to the extra element `"foo"`:
159
160
@@ -171,7 +172,7 @@ For example, this configuration is now invalid due to the extra element `"foo"`:
171
172
172
173
## <aname="no-invalid-regexp"></a> `allowConstructorFlags` option of `no-invalid-regexp` now accepts only unique items
173
174
174
-
In ESLint v10, the `allowConstructorFlags` option of `no-invalid-regexp` no longer accepts duplicate flags as input. Previously, configurations with duplicate flags in the array were accepted but treated the same as having unique flags. Such configurations are now considered invalid and will result in a configuration error.
175
+
In ESLint v10.0.0, the `allowConstructorFlags` option of `no-invalid-regexp` no longer accepts duplicate flags as input. Previously, configurations with duplicate flags in the array were accepted but treated the same as having unique flags. Such configurations are now considered invalid and will result in a configuration error.
175
176
176
177
For example, this configuration is now invalid due to the duplicate `"u"` flag:
177
178
@@ -185,7 +186,7 @@ For example, this configuration is now invalid due to the duplicate `"u"` flag:
185
186
186
187
## <aname="ruletester-type-removed"></a> Removal of `type` property in errors of invalid `RuleTester` cases
187
188
188
-
In ESLint v10, the deprecated `type` property in errors of invalid test cases for rules has been removed. Using the `type` property in test cases now throws an error.
189
+
In ESLint v10.0.0, the deprecated `type` property in errors of invalid test cases for rules has been removed. Using the `type` property in test cases now throws an error.
189
190
190
191
**To address:** Remove the `type` property from error objects in invalid test cases.
191
192
@@ -216,7 +217,7 @@ Starting with ESLint v10, `Program.range` covers the entire source text, includi
216
217
217
218
## <aname="fixer-text-must-be-string"></a> Fixer methods now require string `text` arguments
218
219
219
-
In ESLint v10, all rule fixer methods that accept a `text` argument now require that it be a string. Providing a non-string value will throw a `TypeError`.
220
+
In ESLint v10.0.0, all rule fixer methods that accept a `text` argument now require that it be a string. Providing a non-string value will throw a `TypeError`.
220
221
221
222
Affected methods:
222
223
@@ -233,7 +234,7 @@ Affected methods:
233
234
234
235
## <aname="scope-manager"></a> New requirements for `ScopeManager` implementations
235
236
236
-
As of ESLint v10.0.0, custom `ScopeManager` implementations must automatically resolve references to global variables declared in the code, including `var` and `function` declarations, and provide an instance method `addGlobals(names: string[])` that creates variables with the given names in the global scope and resolves references to them.
237
+
In ESLint v10.0.0, custom `ScopeManager` implementations must automatically resolve references to global variables declared in the code, including `var` and `function` declarations, and provide an instance method `addGlobals(names: string[])` that creates variables with the given names in the global scope and resolves references to them.
237
238
238
239
The default `ScopeManager` implementation [`eslint-scope`](https://www.npmjs.com/package/eslint-scope) has already been updated.
239
240
@@ -243,9 +244,50 @@ This change does not affect custom rules.
## <aname="rule-context"></a> Removal of deprecated `context` members
248
+
249
+
In ESLint v9.x, we deprecated the following [methods](https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/#context-methods-becoming-properties) and [properties](https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/#context-properties%3A-parseroptions-and-parserpath-being-removed):
250
+
251
+
-`context.getCwd()`
252
+
-`context.getFilename()`
253
+
-`context.getPhysicalFilename()`
254
+
-`context.getSourceCode()`
255
+
-`context.parserOptions`
256
+
-`context.parserPath`
257
+
258
+
In ESLint v10.0.0, all of these members have been removed.
259
+
260
+
**To address:** In your custom rules, make the following changes:
261
+
262
+
|**Removed on `context`**|**Replacement on `context`**|
|`context.parserOptions`|`context.languageOptions` or `context.languageOptions.parserOptions`|
269
+
|`context.parserPath`| No replacement. |
270
+
271
+
You can make changes for the removed `context` methods using the [`eslint-transforms`](https://www.npmjs.com/package/eslint-transforms) utility. To use the utility, first install it and then run the `v9-rule-migration` transform, like this:
272
+
273
+
```shell
274
+
# install the utility
275
+
npm install eslint-transforms -g
276
+
277
+
# apply the transform to one file
278
+
eslint-transforms v9-rule-migration rule.js
279
+
280
+
# apply the transform to all files in a directory
281
+
eslint-transforms v9-rule-migration rules/
282
+
```
283
+
284
+
The removed `context` properties must be done manually as there may not be a direct one-to-one replacement.
## <aname="lintmessage-nodetype-removed"></a> Removal of `nodeType` property in `LintMessage` objects
247
289
248
-
In ESLint v10, the deprecated `nodeType` property on `LintMessage` objects has been removed. This affects consumers of the Node.js API (for example, custom formatters and editor/tool integrations) that previously relied on `message.nodeType`.
290
+
In ESLint v10.0.0, the deprecated `nodeType` property on `LintMessage` objects has been removed. This affects consumers of the Node.js API (for example, custom formatters and editor/tool integrations) that previously relied on `message.nodeType`.
249
291
250
292
**To address:** Remove all usages of `message.nodeType` in your integrations and formatters.
0 commit comments