eslint 9.39.1 → 10.0.0-alpha.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 (42) hide show
  1. package/README.md +3 -3
  2. package/bin/eslint.js +1 -2
  3. package/lib/api.js +4 -15
  4. package/lib/cli.js +14 -56
  5. package/lib/config/config-loader.js +6 -154
  6. package/lib/eslint/eslint-helpers.js +5 -8
  7. package/lib/eslint/eslint.js +1 -1
  8. package/lib/eslint/index.js +0 -2
  9. package/lib/languages/js/source-code/source-code.js +39 -87
  10. package/lib/languages/js/source-code/token-store/utils.js +29 -8
  11. package/lib/linter/apply-disable-directives.js +0 -1
  12. package/lib/linter/file-context.js +0 -56
  13. package/lib/linter/file-report.js +0 -4
  14. package/lib/linter/linter.js +45 -1086
  15. package/lib/linter/rule-fixer.js +30 -0
  16. package/lib/options.js +62 -182
  17. package/lib/rule-tester/rule-tester.js +255 -194
  18. package/lib/rules/dot-notation.js +2 -2
  19. package/lib/rules/func-names.js +2 -0
  20. package/lib/rules/no-eval.js +1 -1
  21. package/lib/rules/no-invalid-regexp.js +1 -0
  22. package/lib/rules/no-shadow-restricted-names.js +1 -1
  23. package/lib/rules/no-unassigned-vars.js +1 -1
  24. package/lib/rules/no-useless-assignment.js +1 -1
  25. package/lib/rules/preserve-caught-error.js +1 -1
  26. package/lib/rules/radix.js +25 -48
  27. package/lib/services/parser-service.js +0 -1
  28. package/lib/services/processor-service.js +0 -1
  29. package/lib/services/warning-service.js +0 -11
  30. package/lib/shared/flags.js +0 -19
  31. package/lib/shared/translate-cli-options.js +106 -164
  32. package/lib/types/index.d.ts +7 -60
  33. package/lib/types/rules.d.ts +11 -2
  34. package/lib/types/use-at-your-own-risk.d.ts +1 -54
  35. package/lib/unsupported-api.js +3 -6
  36. package/package.json +14 -19
  37. package/conf/default-cli-options.js +0 -32
  38. package/lib/cli-engine/cli-engine.js +0 -1109
  39. package/lib/cli-engine/file-enumerator.js +0 -541
  40. package/lib/cli-engine/index.js +0 -7
  41. package/lib/cli-engine/load-rules.js +0 -46
  42. package/lib/eslint/legacy-eslint.js +0 -786
@@ -38,6 +38,18 @@ function insertTextAt(index, text) {
38
38
  };
39
39
  }
40
40
 
41
+ /**
42
+ * Asserts that the provided text is a string.
43
+ * @param {unknown} text The text to validate.
44
+ * @returns {void}
45
+ * @throws {TypeError} If `text` is not a string.
46
+ */
47
+ function assertIsString(text) {
48
+ if (typeof text !== "string") {
49
+ throw new TypeError("'text' must be a string");
50
+ }
51
+ }
52
+
41
53
  //------------------------------------------------------------------------------
42
54
  // Public Interface
43
55
  //------------------------------------------------------------------------------
@@ -67,8 +79,11 @@ class RuleFixer {
67
79
  * @param {ASTNode|Token} nodeOrToken The node or token to insert after.
68
80
  * @param {string} text The text to insert.
69
81
  * @returns {Object} The fix command.
82
+ * @throws {TypeError} If `text` is not a string.
70
83
  */
71
84
  insertTextAfter(nodeOrToken, text) {
85
+ assertIsString(text);
86
+
72
87
  const range = this.#sourceCode.getRange(nodeOrToken);
73
88
 
74
89
  return this.insertTextAfterRange(range, text);
@@ -81,8 +96,11 @@ class RuleFixer {
81
96
  * is end of range.
82
97
  * @param {string} text The text to insert.
83
98
  * @returns {Object} The fix command.
99
+ * @throws {TypeError} If `text` is not a string.
84
100
  */
85
101
  insertTextAfterRange(range, text) {
102
+ assertIsString(text);
103
+
86
104
  return insertTextAt(range[1], text);
87
105
  }
88
106
 
@@ -92,8 +110,11 @@ class RuleFixer {
92
110
  * @param {ASTNode|Token} nodeOrToken The node or token to insert before.
93
111
  * @param {string} text The text to insert.
94
112
  * @returns {Object} The fix command.
113
+ * @throws {TypeError} If `text` is not a string.
95
114
  */
96
115
  insertTextBefore(nodeOrToken, text) {
116
+ assertIsString(text);
117
+
97
118
  const range = this.#sourceCode.getRange(nodeOrToken);
98
119
 
99
120
  return this.insertTextBeforeRange(range, text);
@@ -106,8 +127,11 @@ class RuleFixer {
106
127
  * is end of range.
107
128
  * @param {string} text The text to insert.
108
129
  * @returns {Object} The fix command.
130
+ * @throws {TypeError} If `text` is not a string.
109
131
  */
110
132
  insertTextBeforeRange(range, text) {
133
+ assertIsString(text);
134
+
111
135
  return insertTextAt(range[0], text);
112
136
  }
113
137
 
@@ -117,8 +141,11 @@ class RuleFixer {
117
141
  * @param {ASTNode|Token} nodeOrToken The node or token to remove.
118
142
  * @param {string} text The text to insert.
119
143
  * @returns {Object} The fix command.
144
+ * @throws {TypeError} If `text` is not a string.
120
145
  */
121
146
  replaceText(nodeOrToken, text) {
147
+ assertIsString(text);
148
+
122
149
  const range = this.#sourceCode.getRange(nodeOrToken);
123
150
 
124
151
  return this.replaceTextRange(range, text);
@@ -131,8 +158,11 @@ class RuleFixer {
131
158
  * is end of range.
132
159
  * @param {string} text The text to insert.
133
160
  * @returns {Object} The fix command.
161
+ * @throws {TypeError} If `text` is not a string.
134
162
  */
135
163
  replaceTextRange(range, text) {
164
+ assertIsString(text);
165
+
136
166
  return {
137
167
  range,
138
168
  text,
package/lib/options.js CHANGED
@@ -24,12 +24,10 @@ const optionator = require("optionator");
24
24
  * @property {"metadata" | "content"} cacheStrategy Strategy to use for detecting changed files in the cache
25
25
  * @property {boolean} [color] Force enabling/disabling of color
26
26
  * @property {number | "auto" | "off"} [concurrency] Number of linting threads, "auto" to choose automatically, "off" for no multithreading
27
- * @property {string} [config] Use this configuration, overriding .eslintrc.* config options if present
27
+ * @property {string} [config] Use this configuration, overriding eslint.config.* config options if present
28
28
  * @property {boolean} debug Output debugging information
29
- * @property {string[]} [env] Specify environments
30
29
  * @property {boolean} envInfo Output execution environment information
31
30
  * @property {boolean} errorOnUnmatchedPattern Prevent errors when pattern is unmatched
32
- * @property {boolean} eslintrc Disable use of configuration from .eslintrc.*
33
31
  * @property {string[]} [ext] Specify JavaScript file extensions
34
32
  * @property {string[]} [flag] Feature flags
35
33
  * @property {boolean} fix Automatically fix problems
@@ -39,8 +37,7 @@ const optionator = require("optionator");
39
37
  * @property {string[]} [global] Define global variables
40
38
  * @property {boolean} [help] Show help
41
39
  * @property {boolean} ignore Disable use of ignore files and patterns
42
- * @property {string} [ignorePath] Specify path of ignore file
43
- * @property {string[]} [ignorePattern] Patterns of files to ignore. In eslintrc mode, these are in addition to `.eslintignore`
40
+ * @property {string[]} [ignorePattern] Patterns of files to ignore
44
41
  * @property {boolean} init Run config initialization wizard
45
42
  * @property {boolean} inlineConfig Prevent comments from changing config or rules
46
43
  * @property {number} maxWarnings Number of warnings to trigger nonzero exit code
@@ -56,9 +53,7 @@ const optionator = require("optionator");
56
53
  * @property {boolean} quiet Report errors only
57
54
  * @property {boolean | undefined} reportUnusedDisableDirectives Adds reported errors for unused eslint-disable and eslint-enable directives
58
55
  * @property {string | undefined} reportUnusedDisableDirectivesSeverity A severity string indicating if and how unused disable and enable directives should be tracked and reported.
59
- * @property {string} [resolvePluginsRelativeTo] A folder where plugins should be resolved from, CWD by default
60
56
  * @property {Object} [rule] Specify rules
61
- * @property {string[]} [rulesdir] Load additional rules from this directory. Deprecated: Use rules from plugins
62
57
  * @property {boolean} [stats] Report additional statistics
63
58
  * @property {boolean} stdin Lint code provided on <STDIN>
64
59
  * @property {string} [stdinFilename] Specify filename to process STDIN as
@@ -78,165 +73,9 @@ const optionator = require("optionator");
78
73
 
79
74
  /**
80
75
  * Creates the CLI options for ESLint.
81
- * @param {boolean} usingFlatConfig Indicates if flat config is being used.
82
76
  * @returns {Object} The optionator instance.
83
77
  */
84
- module.exports = function (usingFlatConfig) {
85
- let lookupFlag;
86
-
87
- if (usingFlatConfig) {
88
- lookupFlag = {
89
- option: "config-lookup",
90
- type: "Boolean",
91
- default: "true",
92
- description: "Disable look up for eslint.config.js",
93
- };
94
- } else {
95
- lookupFlag = {
96
- option: "eslintrc",
97
- type: "Boolean",
98
- default: "true",
99
- description: "Disable use of configuration from .eslintrc.*",
100
- };
101
- }
102
-
103
- let envFlag;
104
-
105
- if (!usingFlatConfig) {
106
- envFlag = {
107
- option: "env",
108
- type: "[String]",
109
- description: "Specify environments",
110
- };
111
- }
112
-
113
- let inspectConfigFlag;
114
-
115
- if (usingFlatConfig) {
116
- inspectConfigFlag = {
117
- option: "inspect-config",
118
- type: "Boolean",
119
- description:
120
- "Open the config inspector with the current configuration",
121
- };
122
- }
123
-
124
- let extFlag;
125
-
126
- if (!usingFlatConfig) {
127
- extFlag = {
128
- option: "ext",
129
- type: "[String]",
130
- description: "Specify JavaScript file extensions",
131
- };
132
- } else {
133
- extFlag = {
134
- option: "ext",
135
- type: "[String]",
136
- description: "Specify additional file extensions to lint",
137
- };
138
- }
139
-
140
- let resolvePluginsFlag;
141
-
142
- if (!usingFlatConfig) {
143
- resolvePluginsFlag = {
144
- option: "resolve-plugins-relative-to",
145
- type: "path::String",
146
- description:
147
- "A folder where plugins should be resolved from, CWD by default",
148
- };
149
- }
150
-
151
- let rulesDirFlag;
152
-
153
- if (!usingFlatConfig) {
154
- rulesDirFlag = {
155
- option: "rulesdir",
156
- type: "[path::String]",
157
- description:
158
- "Load additional rules from this directory. Deprecated: Use rules from plugins",
159
- };
160
- }
161
-
162
- let ignorePathFlag;
163
-
164
- if (!usingFlatConfig) {
165
- ignorePathFlag = {
166
- option: "ignore-path",
167
- type: "path::String",
168
- description: "Specify path of ignore file",
169
- };
170
- }
171
-
172
- let statsFlag;
173
-
174
- if (usingFlatConfig) {
175
- statsFlag = {
176
- option: "stats",
177
- type: "Boolean",
178
- default: "false",
179
- description: "Add statistics to the lint report",
180
- };
181
- }
182
-
183
- let warnIgnoredFlag;
184
-
185
- if (usingFlatConfig) {
186
- warnIgnoredFlag = {
187
- option: "warn-ignored",
188
- type: "Boolean",
189
- default: "true",
190
- description:
191
- "Suppress warnings when the file list includes ignored files",
192
- };
193
- }
194
-
195
- let flagFlag;
196
-
197
- if (usingFlatConfig) {
198
- flagFlag = {
199
- option: "flag",
200
- type: "[String]",
201
- description: "Enable a feature flag",
202
- };
203
- }
204
-
205
- let reportUnusedInlineConfigsFlag;
206
-
207
- if (usingFlatConfig) {
208
- reportUnusedInlineConfigsFlag = {
209
- option: "report-unused-inline-configs",
210
- type: "String",
211
- default: void 0,
212
- description:
213
- "Adds reported errors for unused eslint inline config comments",
214
- enum: ["off", "warn", "error", "0", "1", "2"],
215
- };
216
- }
217
-
218
- let mcpFlag;
219
-
220
- if (usingFlatConfig) {
221
- mcpFlag = {
222
- option: "mcp",
223
- type: "Boolean",
224
- description: "Start the ESLint MCP server",
225
- };
226
- }
227
-
228
- let concurrencyFlag;
229
-
230
- if (usingFlatConfig) {
231
- concurrencyFlag = {
232
- option: "concurrency",
233
- type: "Int|String",
234
- default: "off",
235
- description:
236
- "Number of linting threads, auto to choose automatically, off for no multithreading",
237
- };
238
- }
239
-
78
+ module.exports = function () {
240
79
  return optionator({
241
80
  prepend: "eslint [options] file.js [file.js] [dir]",
242
81
  defaults: {
@@ -247,18 +86,30 @@ module.exports = function (usingFlatConfig) {
247
86
  {
248
87
  heading: "Basic configuration",
249
88
  },
250
- lookupFlag,
89
+ {
90
+ option: "config-lookup",
91
+ type: "Boolean",
92
+ default: "true",
93
+ description: "Disable look up for eslint.config.js",
94
+ },
251
95
  {
252
96
  option: "config",
253
97
  alias: "c",
254
98
  type: "path::String",
255
- description: usingFlatConfig
256
- ? "Use this configuration instead of eslint.config.js, eslint.config.mjs, or eslint.config.cjs"
257
- : "Use this configuration, overriding .eslintrc.* config options if present",
99
+ description:
100
+ "Use this configuration instead of eslint.config.js, eslint.config.mjs, or eslint.config.cjs",
101
+ },
102
+ {
103
+ option: "inspect-config",
104
+ type: "Boolean",
105
+ description:
106
+ "Open the config inspector with the current configuration",
107
+ },
108
+ {
109
+ option: "ext",
110
+ type: "[String]",
111
+ description: "Specify additional file extensions to lint",
258
112
  },
259
- inspectConfigFlag,
260
- envFlag,
261
- extFlag,
262
113
  {
263
114
  option: "global",
264
115
  type: "[String]",
@@ -274,7 +125,6 @@ module.exports = function (usingFlatConfig) {
274
125
  type: "Object",
275
126
  description: "Specify parser options",
276
127
  },
277
- resolvePluginsFlag,
278
128
  {
279
129
  heading: "Specify Rules and Plugins",
280
130
  },
@@ -288,7 +138,6 @@ module.exports = function (usingFlatConfig) {
288
138
  type: "Object",
289
139
  description: "Specify rules",
290
140
  },
291
- rulesDirFlag,
292
141
  {
293
142
  heading: "Fix Problems",
294
143
  },
@@ -314,7 +163,6 @@ module.exports = function (usingFlatConfig) {
314
163
  {
315
164
  heading: "Ignore Files",
316
165
  },
317
- ignorePathFlag,
318
166
  {
319
167
  option: "ignore",
320
168
  type: "Boolean",
@@ -324,7 +172,7 @@ module.exports = function (usingFlatConfig) {
324
172
  {
325
173
  option: "ignore-pattern",
326
174
  type: "[String]",
327
- description: `Patterns of files to ignore${usingFlatConfig ? "" : " (in addition to those in .eslintignore)"}`,
175
+ description: "Patterns of files to ignore",
328
176
  concatRepeatedArrays: [
329
177
  true,
330
178
  {
@@ -407,7 +255,14 @@ module.exports = function (usingFlatConfig) {
407
255
  "Chooses severity level for reporting unused eslint-disable and eslint-enable directives",
408
256
  enum: ["off", "warn", "error", "0", "1", "2"],
409
257
  },
410
- reportUnusedInlineConfigsFlag,
258
+ {
259
+ option: "report-unused-inline-configs",
260
+ type: "String",
261
+ default: void 0,
262
+ description:
263
+ "Adds reported errors for unused eslint inline config comments",
264
+ enum: ["off", "warn", "error", "0", "1", "2"],
265
+ },
411
266
  {
412
267
  heading: "Caching",
413
268
  },
@@ -496,7 +351,13 @@ module.exports = function (usingFlatConfig) {
496
351
  default: "false",
497
352
  description: "Exit with exit code 2 in case of fatal error",
498
353
  },
499
- warnIgnoredFlag,
354
+ {
355
+ option: "warn-ignored",
356
+ type: "Boolean",
357
+ default: "true",
358
+ description:
359
+ "Suppress warnings when the file list includes ignored files",
360
+ },
500
361
  {
501
362
  option: "pass-on-no-patterns",
502
363
  type: "Boolean",
@@ -527,10 +388,29 @@ module.exports = function (usingFlatConfig) {
527
388
  type: "path::String",
528
389
  description: "Print the configuration for the given file",
529
390
  },
530
- statsFlag,
531
- flagFlag,
532
- mcpFlag,
533
- concurrencyFlag,
534
- ].filter(value => !!value),
391
+ {
392
+ option: "stats",
393
+ type: "Boolean",
394
+ default: "false",
395
+ description: "Add statistics to the lint report",
396
+ },
397
+ {
398
+ option: "flag",
399
+ type: "[String]",
400
+ description: "Enable a feature flag",
401
+ },
402
+ {
403
+ option: "mcp",
404
+ type: "Boolean",
405
+ description: "Start the ESLint MCP server",
406
+ },
407
+ {
408
+ option: "concurrency",
409
+ type: "Int|String",
410
+ default: "off",
411
+ description:
412
+ "Number of linting threads, auto to choose automatically, off for no multithreading",
413
+ },
414
+ ],
535
415
  });
536
416
  };