eslint 9.25.1 → 9.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +44 -39
  2. package/bin/eslint.js +15 -0
  3. package/conf/rule-type-list.json +2 -1
  4. package/lib/cli-engine/cli-engine.js +8 -8
  5. package/lib/cli.js +6 -5
  6. package/lib/config/config-loader.js +10 -18
  7. package/lib/config/config.js +328 -5
  8. package/lib/eslint/eslint-helpers.js +3 -1
  9. package/lib/eslint/eslint.js +31 -17
  10. package/lib/eslint/legacy-eslint.js +7 -7
  11. package/lib/languages/js/index.js +4 -3
  12. package/lib/languages/js/source-code/source-code.js +10 -6
  13. package/lib/linter/apply-disable-directives.js +1 -1
  14. package/lib/linter/esquery.js +329 -0
  15. package/lib/linter/file-context.js +11 -0
  16. package/lib/linter/linter.js +81 -89
  17. package/lib/linter/node-event-generator.js +94 -251
  18. package/lib/linter/report-translator.js +2 -1
  19. package/lib/options.js +11 -0
  20. package/lib/rule-tester/rule-tester.js +17 -9
  21. package/lib/rules/eqeqeq.js +31 -8
  22. package/lib/rules/index.js +2 -1
  23. package/lib/rules/max-params.js +32 -7
  24. package/lib/rules/no-array-constructor.js +51 -1
  25. package/lib/rules/no-shadow-restricted-names.js +25 -2
  26. package/lib/rules/no-unassigned-vars.js +72 -0
  27. package/lib/rules/no-unused-expressions.js +7 -1
  28. package/lib/rules/no-useless-escape.js +24 -2
  29. package/lib/rules/prefer-named-capture-group.js +7 -1
  30. package/lib/rules/utils/lazy-loading-rule-map.js +2 -2
  31. package/lib/services/processor-service.js +1 -2
  32. package/lib/services/suppressions-service.js +5 -3
  33. package/lib/shared/flags.js +1 -0
  34. package/lib/shared/serialization.js +29 -6
  35. package/lib/types/index.d.ts +126 -6
  36. package/lib/types/rules.d.ts +33 -2
  37. package/package.json +7 -6
  38. package/lib/config/flat-config-helpers.js +0 -128
  39. package/lib/config/rule-validator.js +0 -199
  40. package/lib/shared/types.js +0 -246
package/README.md CHANGED
@@ -20,9 +20,9 @@
20
20
 
21
21
  ESLint is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code. In many ways, it is similar to JSLint and JSHint with a few exceptions:
22
22
 
23
- - ESLint uses [Espree](https://github.com/eslint/js/tree/main/packages/espree) for JavaScript parsing.
24
- - ESLint uses an AST to evaluate patterns in code.
25
- - ESLint is completely pluggable, every single rule is a plugin and you can add more at runtime.
23
+ - ESLint uses [Espree](https://github.com/eslint/js/tree/main/packages/espree) for JavaScript parsing.
24
+ - ESLint uses an AST to evaluate patterns in code.
25
+ - ESLint is completely pluggable, every single rule is a plugin and you can add more at runtime.
26
26
 
27
27
  ## Table of Contents
28
28
 
@@ -87,9 +87,9 @@ export default defineConfig([
87
87
 
88
88
  The names `"prefer-const"` and `"no-constant-binary-expression"` are the names of [rules](https://eslint.org/docs/rules) in ESLint. The first value is the error level of the rule and can be one of these values:
89
89
 
90
- - `"off"` or `0` - turn the rule off
91
- - `"warn"` or `1` - turn the rule on as a warning (doesn't affect exit code)
92
- - `"error"` or `2` - turn the rule on as an error (exit code will be 1)
90
+ - `"off"` or `0` - turn the rule off
91
+ - `"warn"` or `1` - turn the rule on as a warning (doesn't affect exit code)
92
+ - `"error"` or `2` - turn the rule on as an error (exit code will be 1)
93
93
 
94
94
  The three error levels allow you fine-grained control over how ESLint applies rules (for more configuration options and details, see the [configuration docs](https://eslint.org/docs/latest/use/configure)).
95
95
 
@@ -109,10 +109,10 @@ ESLint adheres to the [OpenJS Foundation Code of Conduct](https://eslint.org/con
109
109
 
110
110
  Before filing an issue, please be sure to read the guidelines for what you're reporting:
111
111
 
112
- - [Bug Report](https://eslint.org/docs/latest/contribute/report-bugs)
113
- - [Propose a New Rule](https://eslint.org/docs/latest/contribute/propose-new-rule)
114
- - [Proposing a Rule Change](https://eslint.org/docs/latest/contribute/propose-rule-change)
115
- - [Request a Change](https://eslint.org/docs/latest/contribute/request-change)
112
+ - [Bug Report](https://eslint.org/docs/latest/contribute/report-bugs)
113
+ - [Propose a New Rule](https://eslint.org/docs/latest/contribute/propose-new-rule)
114
+ - [Proposing a Rule Change](https://eslint.org/docs/latest/contribute/propose-rule-change)
115
+ - [Request a Change](https://eslint.org/docs/latest/contribute/request-change)
116
116
 
117
117
  ## Frequently Asked Questions
118
118
 
@@ -174,32 +174,32 @@ ESLint takes security seriously. We work hard to ensure that ESLint is safe for
174
174
 
175
175
  ESLint follows [semantic versioning](https://semver.org). However, due to the nature of ESLint as a code quality tool, it's not always clear when a minor or major version bump occurs. To help clarify this for everyone, we've defined the following semantic versioning policy for ESLint:
176
176
 
177
- - Patch release (intended to not break your lint build)
178
- - A bug fix in a rule that results in ESLint reporting fewer linting errors.
179
- - A bug fix to the CLI or core (including formatters).
180
- - Improvements to documentation.
181
- - Non-user-facing changes such as refactoring code, adding, deleting, or modifying tests, and increasing test coverage.
182
- - Re-releasing after a failed release (i.e., publishing a release that doesn't work for anyone).
183
- - Minor release (might break your lint build)
184
- - A bug fix in a rule that results in ESLint reporting more linting errors.
185
- - A new rule is created.
186
- - A new option to an existing rule that does not result in ESLint reporting more linting errors by default.
187
- - A new addition to an existing rule to support a newly-added language feature (within the last 12 months) that will result in ESLint reporting more linting errors by default.
188
- - An existing rule is deprecated.
189
- - A new CLI capability is created.
190
- - New capabilities to the public API are added (new classes, new methods, new arguments to existing methods, etc.).
191
- - A new formatter is created.
192
- - `eslint:recommended` is updated and will result in strictly fewer linting errors (e.g., rule removals).
193
- - Major release (likely to break your lint build)
194
- - `eslint:recommended` is updated and may result in new linting errors (e.g., rule additions, most rule option updates).
195
- - A new option to an existing rule that results in ESLint reporting more linting errors by default.
196
- - An existing formatter is removed.
197
- - Part of the public API is removed or changed in an incompatible way. The public API includes:
198
- - Rule schemas
199
- - Configuration schema
200
- - Command-line options
201
- - Node.js API
202
- - Rule, formatter, parser, plugin APIs
177
+ - Patch release (intended to not break your lint build)
178
+ - A bug fix in a rule that results in ESLint reporting fewer linting errors.
179
+ - A bug fix to the CLI or core (including formatters).
180
+ - Improvements to documentation.
181
+ - Non-user-facing changes such as refactoring code, adding, deleting, or modifying tests, and increasing test coverage.
182
+ - Re-releasing after a failed release (i.e., publishing a release that doesn't work for anyone).
183
+ - Minor release (might break your lint build)
184
+ - A bug fix in a rule that results in ESLint reporting more linting errors.
185
+ - A new rule is created.
186
+ - A new option to an existing rule that does not result in ESLint reporting more linting errors by default.
187
+ - A new addition to an existing rule to support a newly-added language feature (within the last 12 months) that will result in ESLint reporting more linting errors by default.
188
+ - An existing rule is deprecated.
189
+ - A new CLI capability is created.
190
+ - New capabilities to the public API are added (new classes, new methods, new arguments to existing methods, etc.).
191
+ - A new formatter is created.
192
+ - `eslint:recommended` is updated and will result in strictly fewer linting errors (e.g., rule removals).
193
+ - Major release (likely to break your lint build)
194
+ - `eslint:recommended` is updated and may result in new linting errors (e.g., rule additions, most rule option updates).
195
+ - A new option to an existing rule that results in ESLint reporting more linting errors by default.
196
+ - An existing formatter is removed.
197
+ - Part of the public API is removed or changed in an incompatible way. The public API includes:
198
+ - Rule schemas
199
+ - Configuration schema
200
+ - Command-line options
201
+ - Node.js API
202
+ - Rule, formatter, parser, plugin APIs
203
203
 
204
204
  According to our policy, any minor update may report more linting errors than the previous release (ex: from a bug fix). As such, we recommend using the tilde (`~`) in `package.json` e.g. `"eslint": "~3.1.0"` to guarantee the results of your builds.
205
205
 
@@ -286,6 +286,11 @@ Josh Goldberg ✨
286
286
  <img src="https://github.com/Tanujkanti4441.png?s=75" width="75" height="75" alt="Tanuj Kanti's Avatar"><br />
287
287
  Tanuj Kanti
288
288
  </a>
289
+ </td><td align="center" valign="top" width="11%">
290
+ <a href="https://github.com/lumirlumir">
291
+ <img src="https://github.com/lumirlumir.png?s=75" width="75" height="75" alt="루밀LuMir's Avatar"><br />
292
+ 루밀LuMir
293
+ </a>
289
294
  </td></tr></tbody></table>
290
295
 
291
296
  ### Website Team
@@ -299,8 +304,8 @@ Amaresh S M
299
304
  </a>
300
305
  </td><td align="center" valign="top" width="11%">
301
306
  <a href="https://github.com/harish-sethuraman">
302
- <img src="https://github.com/harish-sethuraman.png?s=75" width="75" height="75" alt="Strek's Avatar"><br />
303
- Strek
307
+ <img src="https://github.com/harish-sethuraman.png?s=75" width="75" height="75" alt="Harish's Avatar"><br />
308
+ Harish
304
309
  </a>
305
310
  </td><td align="center" valign="top" width="11%">
306
311
  <a href="https://github.com/kecrily">
@@ -320,7 +325,7 @@ The following companies, organizations, and individuals support ESLint's ongoing
320
325
  to get your logo on our READMEs and [website](https://eslint.org/sponsors).
321
326
 
322
327
  <h3>Diamond Sponsors</h3>
323
- <p><a href="https://www.ag-grid.com/"><img src="https://images.opencollective.com/ag-grid/2c8d545/logo.png" alt="AG Grid" height="128"></a></p><h3>Platinum Sponsors</h3>
328
+ <p><a href="https://www.ag-grid.com/"><img src="https://images.opencollective.com/ag-grid/bec0580/logo.png" alt="AG Grid" height="128"></a></p><h3>Platinum Sponsors</h3>
324
329
  <p><a href="https://automattic.com"><img src="https://images.opencollective.com/automattic/d0ef3e1/logo.png" alt="Automattic" height="128"></a> <a href="https://www.airbnb.com/"><img src="https://images.opencollective.com/airbnb/d327d66/logo.png" alt="Airbnb" height="128"></a></p><h3>Gold Sponsors</h3>
325
330
  <p><a href="https://qlty.sh/"><img src="https://images.opencollective.com/qltysh/33d157d/logo.png" alt="Qlty Software" height="96"></a> <a href="https://trunk.io/"><img src="https://images.opencollective.com/trunkio/fb92d60/avatar.png" alt="trunk.io" height="96"></a> <a href="https://shopify.engineering/"><img src="https://avatars.githubusercontent.com/u/8085" alt="Shopify" height="96"></a></p><h3>Silver Sponsors</h3>
326
331
  <p><a href="https://vite.dev/"><img src="https://images.opencollective.com/vite/e6d15e1/logo.png" alt="Vite" height="64"></a> <a href="https://liftoff.io/"><img src="https://images.opencollective.com/liftoff/5c4fa84/logo.png" alt="Liftoff" height="64"></a> <a href="https://americanexpress.io"><img src="https://avatars.githubusercontent.com/u/3853301" alt="American Express" height="64"></a> <a href="https://stackblitz.com"><img src="https://avatars.githubusercontent.com/u/28635252" alt="StackBlitz" height="64"></a></p><h3>Bronze Sponsors</h3>
package/bin/eslint.js CHANGED
@@ -155,6 +155,21 @@ ${getErrorMessage(error)}`;
155
155
  return;
156
156
  }
157
157
 
158
+ // start the MCP server if `--mcp` is present
159
+ if (process.argv.includes("--mcp")) {
160
+ console.warn(
161
+ "You can also run this command directly using 'npx @eslint/mcp@latest'.",
162
+ );
163
+
164
+ const spawn = require("cross-spawn");
165
+
166
+ spawn.sync("npx", ["@eslint/mcp@latest"], {
167
+ encoding: "utf8",
168
+ stdio: "inherit",
169
+ });
170
+ return;
171
+ }
172
+
158
173
  // Otherwise, call the CLI.
159
174
  const cli = require("../lib/cli");
160
175
  const exitCode = await cli.execute(
@@ -69,7 +69,8 @@
69
69
  "removed": "space-in-brackets",
70
70
  "replacedBy": [
71
71
  { "rule": { "name": "object-curly-spacing" } },
72
- { "rule": { "name": "array-bracket-spacing" } }
72
+ { "rule": { "name": "array-bracket-spacing" } },
73
+ { "rule": { "name": "computed-property-spacing" } }
73
74
  ]
74
75
  },
75
76
  {
@@ -58,15 +58,15 @@ const validFixTypes = new Set(["directive", "problem", "suggestion", "layout"]);
58
58
  //------------------------------------------------------------------------------
59
59
 
60
60
  // For VSCode IntelliSense
61
- /** @typedef {import("../shared/types").ConfigData} ConfigData */
62
- /** @typedef {import("../shared/types").DeprecatedRuleInfo} DeprecatedRuleInfo */
63
- /** @typedef {import("../shared/types").LintMessage} LintMessage */
64
- /** @typedef {import("../shared/types").SuppressedLintMessage} SuppressedLintMessage */
65
- /** @typedef {import("../shared/types").ParserOptions} ParserOptions */
66
- /** @typedef {import("../shared/types").Plugin} Plugin */
67
- /** @typedef {import("../shared/types").RuleConf} RuleConf */
68
- /** @typedef {import("../types").Rule.RuleModule} Rule */
61
+ /** @typedef {import("../types").ESLint.ConfigData} ConfigData */
62
+ /** @typedef {import("../types").ESLint.DeprecatedRuleUse} DeprecatedRuleInfo */
69
63
  /** @typedef {import("../types").ESLint.FormatterFunction} FormatterFunction */
64
+ /** @typedef {import("../types").Linter.LintMessage} LintMessage */
65
+ /** @typedef {import("../types").Linter.ParserOptions} ParserOptions */
66
+ /** @typedef {import("../types").ESLint.Plugin} Plugin */
67
+ /** @typedef {import("../types").Rule.RuleModule} Rule */
68
+ /** @typedef {import("../types").Linter.RuleEntry} RuleConf */
69
+ /** @typedef {import("../types").Linter.SuppressedLintMessage} SuppressedLintMessage */
70
70
  /** @typedef {ReturnType<CascadingConfigArrayFactory.getConfigArrayForFile>} ConfigArray */
71
71
  /** @typedef {ReturnType<ConfigArray.extractConfig>} ExtractedConfig */
72
72
 
package/lib/cli.js CHANGED
@@ -40,12 +40,13 @@ const debug = require("debug")("eslint:cli");
40
40
  // Types
41
41
  //------------------------------------------------------------------------------
42
42
 
43
- /** @typedef {import("./eslint/eslint").ESLintOptions} ESLintOptions */
44
- /** @typedef {import("./eslint/eslint").LintMessage} LintMessage */
45
- /** @typedef {import("./eslint/eslint").LintResult} LintResult */
43
+ /** @import { ESLintOptions } from "./eslint/eslint.js" */
44
+
46
45
  /** @typedef {import("./options").ParsedCLIOptions} ParsedCLIOptions */
47
- /** @typedef {import("./shared/types").Plugin} Plugin */
48
- /** @typedef {import("./shared/types").ResultsMeta} ResultsMeta */
46
+ /** @typedef {import("./types").Linter.LintMessage} LintMessage */
47
+ /** @typedef {import("./types").ESLint.LintResult} LintResult */
48
+ /** @typedef {import("./types").ESLint.Plugin} Plugin */
49
+ /** @typedef {import("./types").ESLint.ResultsMeta} ResultsMeta */
49
50
 
50
51
  //------------------------------------------------------------------------------
51
52
  // Helpers
@@ -20,19 +20,17 @@ const { FlatConfigArray } = require("./flat-config-array");
20
20
  // Types
21
21
  //-----------------------------------------------------------------------------
22
22
 
23
- /**
24
- * @import { ConfigData, ConfigData as FlatConfigObject } from "../shared/types.js";
25
- */
23
+ /** @typedef {import("../types").Linter.Config} Config */
26
24
 
27
25
  /**
28
26
  * @typedef {Object} ConfigLoaderOptions
29
27
  * @property {string|false|undefined} configFile The path to the config file to use.
30
28
  * @property {string} cwd The current working directory.
31
29
  * @property {boolean} ignoreEnabled Indicates if ignore patterns should be honored.
32
- * @property {FlatConfigArray} [baseConfig] The base config to use.
33
- * @property {Array<FlatConfigObject>} [defaultConfigs] The default configs to use.
30
+ * @property {Config|Array<Config>} [baseConfig] The base config to use.
31
+ * @property {Array<Config>} [defaultConfigs] The default configs to use.
34
32
  * @property {Array<string>} [ignorePatterns] The ignore patterns to use.
35
- * @property {FlatConfigObject|Array<FlatConfigObject>} [overrideConfig] The override config to use.
33
+ * @property {Config|Array<Config>} [overrideConfig] The override config to use.
36
34
  * @property {boolean} [hasUnstableNativeNodeJsTSConfigFlag] The flag to indicate whether the `unstable_native_nodejs_ts_config` flag is enabled.
37
35
  */
38
36
 
@@ -394,8 +392,7 @@ class ConfigLoader {
394
392
  * This is the same logic used by the ESLint CLI executable to determine
395
393
  * configuration for each file it processes.
396
394
  * @param {string} filePath The path of the file or directory to retrieve config for.
397
- * @returns {Promise<ConfigData|undefined>} A configuration object for the file
398
- * or `undefined` if there is no configuration data for the file.
395
+ * @returns {Promise<FlatConfigArray>} A configuration object for the file.
399
396
  * @throws {Error} If no configuration for `filePath` exists.
400
397
  */
401
398
  async loadConfigArrayForFile(filePath) {
@@ -415,8 +412,7 @@ class ConfigLoader {
415
412
  * This is the same logic used by the ESLint CLI executable to determine
416
413
  * configuration for each file it processes.
417
414
  * @param {string} dirPath The path of the directory to retrieve config for.
418
- * @returns {Promise<ConfigData|undefined>} A configuration object for the directory
419
- * or `undefined` if there is no configuration data for the directory.
415
+ * @returns {Promise<FlatConfigArray>} A configuration object for the directory.
420
416
  */
421
417
  async loadConfigArrayForDirectory(dirPath) {
422
418
  assertValidFilePath(dirPath);
@@ -440,8 +436,7 @@ class ConfigLoader {
440
436
  * intended to be used in locations where we know the config file has already
441
437
  * been loaded and we just need to get the configuration for a file.
442
438
  * @param {string} filePath The path of the file to retrieve a config object for.
443
- * @returns {ConfigData|undefined} A configuration object for the file
444
- * or `undefined` if there is no configuration data for the file.
439
+ * @returns {FlatConfigArray} A configuration object for the file.
445
440
  * @throws {Error} If `filePath` is not a non-empty string.
446
441
  * @throws {Error} If `filePath` is not an absolute path.
447
442
  * @throws {Error} If the config file was not already loaded.
@@ -460,8 +455,7 @@ class ConfigLoader {
460
455
  * intended to be used in locations where we know the config file has already
461
456
  * been loaded and we just need to get the configuration for a file.
462
457
  * @param {string} fileOrDirPath The path of the directory to retrieve a config object for.
463
- * @returns {ConfigData|undefined} A configuration object for the directory
464
- * or `undefined` if there is no configuration data for the directory.
458
+ * @returns {FlatConfigArray} A configuration object for the directory.
465
459
  * @throws {Error} If `dirPath` is not a non-empty string.
466
460
  * @throws {Error} If `dirPath` is not an absolute path.
467
461
  * @throws {Error} If the config file was not already loaded.
@@ -789,8 +783,7 @@ class LegacyConfigLoader extends ConfigLoader {
789
783
  * This is the same logic used by the ESLint CLI executable to determine
790
784
  * configuration for each file it processes.
791
785
  * @param {string} dirPath The path of the directory to retrieve config for.
792
- * @returns {Promise<ConfigData|undefined>} A configuration object for the file
793
- * or `undefined` if there is no configuration data for the file.
786
+ * @returns {Promise<FlatConfigArray>} A configuration object for the file.
794
787
  */
795
788
  async loadConfigArrayForDirectory(dirPath) {
796
789
  assertValidFilePath(dirPath);
@@ -812,8 +805,7 @@ class LegacyConfigLoader extends ConfigLoader {
812
805
  * intended to be used in locations where we know the config file has already
813
806
  * been loaded and we just need to get the configuration for a file.
814
807
  * @param {string} dirPath The path of the directory to retrieve a config object for.
815
- * @returns {ConfigData|undefined} A configuration object for the file
816
- * or `undefined` if there is no configuration data for the file.
808
+ * @returns {FlatConfigArray} A configuration object for the file.
817
809
  * @throws {Error} If `dirPath` is not a non-empty string.
818
810
  * @throws {Error} If `dirPath` is not an absolute path.
819
811
  * @throws {Error} If the config file was not already loaded.