eslint 9.17.0 → 9.19.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 (75) hide show
  1. package/README.md +27 -8
  2. package/lib/cli.js +11 -4
  3. package/lib/config/config-loader.js +9 -22
  4. package/lib/config/flat-config-schema.js +16 -1
  5. package/lib/eslint/eslint.js +2 -5
  6. package/lib/linter/linter.js +74 -5
  7. package/lib/options.js +13 -0
  8. package/lib/rules/arrow-body-style.js +1 -0
  9. package/lib/rules/camelcase.js +1 -0
  10. package/lib/rules/capitalized-comments.js +1 -0
  11. package/lib/rules/consistent-this.js +1 -0
  12. package/lib/rules/curly.js +1 -0
  13. package/lib/rules/default-case-last.js +2 -2
  14. package/lib/rules/default-param-last.js +1 -0
  15. package/lib/rules/dot-notation.js +1 -0
  16. package/lib/rules/func-name-matching.js +1 -0
  17. package/lib/rules/func-style.js +1 -0
  18. package/lib/rules/id-denylist.js +1 -0
  19. package/lib/rules/id-length.js +1 -0
  20. package/lib/rules/id-match.js +1 -0
  21. package/lib/rules/init-declarations.js +1 -0
  22. package/lib/rules/logical-assignment-operators.js +1 -0
  23. package/lib/rules/no-console.js +3 -1
  24. package/lib/rules/no-continue.js +1 -0
  25. package/lib/rules/no-div-regex.js +1 -0
  26. package/lib/rules/no-else-return.js +1 -0
  27. package/lib/rules/no-extra-boolean-cast.js +1 -0
  28. package/lib/rules/no-extra-label.js +1 -0
  29. package/lib/rules/no-implicit-coercion.js +1 -0
  30. package/lib/rules/no-inline-comments.js +1 -0
  31. package/lib/rules/no-label-var.js +1 -0
  32. package/lib/rules/no-labels.js +1 -0
  33. package/lib/rules/no-lonely-if.js +1 -0
  34. package/lib/rules/no-magic-numbers.js +1 -0
  35. package/lib/rules/no-multi-str.js +1 -0
  36. package/lib/rules/no-negated-condition.js +1 -0
  37. package/lib/rules/no-nested-ternary.js +1 -0
  38. package/lib/rules/no-plusplus.js +1 -0
  39. package/lib/rules/no-shadow-restricted-names.js +17 -7
  40. package/lib/rules/no-ternary.js +1 -0
  41. package/lib/rules/no-undef-init.js +1 -0
  42. package/lib/rules/no-undefined.js +1 -0
  43. package/lib/rules/no-underscore-dangle.js +1 -0
  44. package/lib/rules/no-unneeded-ternary.js +1 -0
  45. package/lib/rules/no-useless-computed-key.js +1 -0
  46. package/lib/rules/no-useless-concat.js +1 -0
  47. package/lib/rules/no-void.js +1 -0
  48. package/lib/rules/no-warning-comments.js +1 -0
  49. package/lib/rules/object-shorthand.js +1 -0
  50. package/lib/rules/one-var.js +1 -0
  51. package/lib/rules/operator-assignment.js +1 -0
  52. package/lib/rules/prefer-arrow-callback.js +1 -0
  53. package/lib/rules/prefer-destructuring.js +1 -0
  54. package/lib/rules/prefer-exponentiation-operator.js +1 -0
  55. package/lib/rules/prefer-numeric-literals.js +1 -0
  56. package/lib/rules/prefer-object-spread.js +1 -0
  57. package/lib/rules/prefer-spread.js +1 -0
  58. package/lib/rules/prefer-template.js +1 -0
  59. package/lib/rules/sort-imports.js +3 -2
  60. package/lib/rules/sort-keys.js +1 -0
  61. package/lib/rules/sort-vars.js +1 -0
  62. package/lib/rules/vars-on-top.js +1 -0
  63. package/lib/rules/yoda.js +1 -0
  64. package/lib/shared/flags.js +3 -3
  65. package/lib/shared/option-utils.js +56 -0
  66. package/lib/types/index.d.ts +7 -1
  67. package/lib/types/rules/best-practices.d.ts +109 -95
  68. package/lib/types/rules/deprecated.d.ts +32 -15
  69. package/lib/types/rules/ecmascript-6.d.ts +39 -39
  70. package/lib/types/rules/node-commonjs.d.ts +23 -12
  71. package/lib/types/rules/possible-errors.d.ts +86 -54
  72. package/lib/types/rules/strict-mode.d.ts +1 -1
  73. package/lib/types/rules/stylistic-issues.d.ts +105 -99
  74. package/lib/types/rules/variables.d.ts +12 -12
  75. package/package.json +8 -6
@@ -17,6 +17,7 @@ module.exports = {
17
17
  docs: {
18
18
  description: "Disallow equal signs explicitly at the beginning of regular expressions",
19
19
  recommended: false,
20
+ frozen: true,
20
21
  url: "https://eslint.org/docs/latest/rules/no-div-regex"
21
22
  },
22
23
 
@@ -26,6 +26,7 @@ module.exports = {
26
26
  docs: {
27
27
  description: "Disallow `else` blocks after `return` statements in `if` statements",
28
28
  recommended: false,
29
+ frozen: true,
29
30
  url: "https://eslint.org/docs/latest/rules/no-else-return"
30
31
  },
31
32
 
@@ -28,6 +28,7 @@ module.exports = {
28
28
  docs: {
29
29
  description: "Disallow unnecessary boolean casts",
30
30
  recommended: true,
31
+ frozen: true,
31
32
  url: "https://eslint.org/docs/latest/rules/no-extra-boolean-cast"
32
33
  },
33
34
 
@@ -23,6 +23,7 @@ module.exports = {
23
23
  docs: {
24
24
  description: "Disallow unnecessary labels",
25
25
  recommended: false,
26
+ frozen: true,
26
27
  url: "https://eslint.org/docs/latest/rules/no-extra-label"
27
28
  },
28
29
 
@@ -179,6 +179,7 @@ module.exports = {
179
179
  docs: {
180
180
  description: "Disallow shorthand type conversions",
181
181
  recommended: false,
182
+ frozen: true,
182
183
  url: "https://eslint.org/docs/latest/rules/no-implicit-coercion"
183
184
  },
184
185
 
@@ -20,6 +20,7 @@ module.exports = {
20
20
  docs: {
21
21
  description: "Disallow inline comments after code",
22
22
  recommended: false,
23
+ frozen: true,
23
24
  url: "https://eslint.org/docs/latest/rules/no-inline-comments"
24
25
  },
25
26
 
@@ -23,6 +23,7 @@ module.exports = {
23
23
  docs: {
24
24
  description: "Disallow labels that share a name with a variable",
25
25
  recommended: false,
26
+ frozen: true,
26
27
  url: "https://eslint.org/docs/latest/rules/no-label-var"
27
28
  },
28
29
 
@@ -27,6 +27,7 @@ module.exports = {
27
27
  docs: {
28
28
  description: "Disallow labeled statements",
29
29
  recommended: false,
30
+ frozen: true,
30
31
  url: "https://eslint.org/docs/latest/rules/no-labels"
31
32
  },
32
33
 
@@ -22,6 +22,7 @@ module.exports = {
22
22
  docs: {
23
23
  description: "Disallow `if` statements as the only statement in `else` blocks",
24
24
  recommended: false,
25
+ frozen: true,
25
26
  url: "https://eslint.org/docs/latest/rules/no-lonely-if"
26
27
  },
27
28
 
@@ -34,6 +34,7 @@ module.exports = {
34
34
  docs: {
35
35
  description: "Disallow magic numbers",
36
36
  recommended: false,
37
+ frozen: true,
37
38
  url: "https://eslint.org/docs/latest/rules/no-magic-numbers"
38
39
  },
39
40
 
@@ -23,6 +23,7 @@ module.exports = {
23
23
  docs: {
24
24
  description: "Disallow multiline strings",
25
25
  recommended: false,
26
+ frozen: true,
26
27
  url: "https://eslint.org/docs/latest/rules/no-multi-str"
27
28
  },
28
29
 
@@ -16,6 +16,7 @@ module.exports = {
16
16
  docs: {
17
17
  description: "Disallow negated conditions",
18
18
  recommended: false,
19
+ frozen: true,
19
20
  url: "https://eslint.org/docs/latest/rules/no-negated-condition"
20
21
  },
21
22
 
@@ -17,6 +17,7 @@ module.exports = {
17
17
  docs: {
18
18
  description: "Disallow nested ternary expressions",
19
19
  recommended: false,
20
+ frozen: true,
20
21
  url: "https://eslint.org/docs/latest/rules/no-nested-ternary"
21
22
  },
22
23
 
@@ -57,6 +57,7 @@ module.exports = {
57
57
  docs: {
58
58
  description: "Disallow the unary operators `++` and `--`",
59
59
  recommended: false,
60
+ frozen: true,
60
61
  url: "https://eslint.org/docs/latest/rules/no-plusplus"
61
62
  },
62
63
 
@@ -45,17 +45,27 @@ module.exports = {
45
45
  const RESTRICTED = new Set(["undefined", "NaN", "Infinity", "arguments", "eval"]);
46
46
  const sourceCode = context.sourceCode;
47
47
 
48
+ // Track reported nodes to avoid duplicate reports. For example, on class declarations.
49
+ const reportedNodes = new Set();
50
+
48
51
  return {
49
- "VariableDeclaration, :function, CatchClause"(node) {
52
+ "VariableDeclaration, :function, CatchClause, ImportDeclaration, ClassDeclaration, ClassExpression"(node) {
50
53
  for (const variable of sourceCode.getDeclaredVariables(node)) {
51
54
  if (variable.defs.length > 0 && RESTRICTED.has(variable.name) && !safelyShadowsUndefined(variable)) {
52
- context.report({
53
- node: variable.defs[0].name,
54
- messageId: "shadowingRestrictedName",
55
- data: {
56
- name: variable.name
55
+ for (const def of variable.defs) {
56
+ const nodeToReport = def.name;
57
+
58
+ if (!reportedNodes.has(nodeToReport)) {
59
+ reportedNodes.add(nodeToReport);
60
+ context.report({
61
+ node: nodeToReport,
62
+ messageId: "shadowingRestrictedName",
63
+ data: {
64
+ name: variable.name
65
+ }
66
+ });
57
67
  }
58
- });
68
+ }
59
69
  }
60
70
  }
61
71
  }
@@ -17,6 +17,7 @@ module.exports = {
17
17
  docs: {
18
18
  description: "Disallow ternary operators",
19
19
  recommended: false,
20
+ frozen: true,
20
21
  url: "https://eslint.org/docs/latest/rules/no-ternary"
21
22
  },
22
23
 
@@ -19,6 +19,7 @@ module.exports = {
19
19
  docs: {
20
20
  description: "Disallow initializing variables to `undefined`",
21
21
  recommended: false,
22
+ frozen: true,
22
23
  url: "https://eslint.org/docs/latest/rules/no-undef-init"
23
24
  },
24
25
 
@@ -16,6 +16,7 @@ module.exports = {
16
16
  docs: {
17
17
  description: "Disallow the use of `undefined` as an identifier",
18
18
  recommended: false,
19
+ frozen: true,
19
20
  url: "https://eslint.org/docs/latest/rules/no-undefined"
20
21
  },
21
22
 
@@ -29,6 +29,7 @@ module.exports = {
29
29
  docs: {
30
30
  description: "Disallow dangling underscores in identifiers",
31
31
  recommended: false,
32
+ frozen: true,
32
33
  url: "https://eslint.org/docs/latest/rules/no-underscore-dangle"
33
34
  },
34
35
 
@@ -33,6 +33,7 @@ module.exports = {
33
33
  docs: {
34
34
  description: "Disallow ternary operators when simpler alternatives exist",
35
35
  recommended: false,
36
+ frozen: true,
36
37
  url: "https://eslint.org/docs/latest/rules/no-unneeded-ternary"
37
38
  },
38
39
 
@@ -100,6 +100,7 @@ module.exports = {
100
100
  docs: {
101
101
  description: "Disallow unnecessary computed property keys in objects and classes",
102
102
  recommended: false,
103
+ frozen: true,
103
104
  url: "https://eslint.org/docs/latest/rules/no-useless-computed-key"
104
105
  },
105
106
 
@@ -72,6 +72,7 @@ module.exports = {
72
72
  docs: {
73
73
  description: "Disallow unnecessary concatenation of literals or template literals",
74
74
  recommended: false,
75
+ frozen: true,
75
76
  url: "https://eslint.org/docs/latest/rules/no-useless-concat"
76
77
  },
77
78
 
@@ -20,6 +20,7 @@ module.exports = {
20
20
  docs: {
21
21
  description: "Disallow `void` operators",
22
22
  recommended: false,
23
+ frozen: true,
23
24
  url: "https://eslint.org/docs/latest/rules/no-void"
24
25
  },
25
26
 
@@ -27,6 +27,7 @@ module.exports = {
27
27
  docs: {
28
28
  description: "Disallow specified warning terms in comments",
29
29
  recommended: false,
30
+ frozen: true,
30
31
  url: "https://eslint.org/docs/latest/rules/no-warning-comments"
31
32
  },
32
33
 
@@ -30,6 +30,7 @@ module.exports = {
30
30
  docs: {
31
31
  description: "Require or disallow method and property shorthand syntax for object literals",
32
32
  recommended: false,
33
+ frozen: true,
33
34
  url: "https://eslint.org/docs/latest/rules/object-shorthand"
34
35
  },
35
36
 
@@ -36,6 +36,7 @@ module.exports = {
36
36
  docs: {
37
37
  description: "Enforce variables to be declared either together or separately in functions",
38
38
  recommended: false,
39
+ frozen: true,
39
40
  url: "https://eslint.org/docs/latest/rules/one-var"
40
41
  },
41
42
 
@@ -67,6 +67,7 @@ module.exports = {
67
67
  docs: {
68
68
  description: "Require or disallow assignment operator shorthand where possible",
69
69
  recommended: false,
70
+ frozen: true,
70
71
  url: "https://eslint.org/docs/latest/rules/operator-assignment"
71
72
  },
72
73
 
@@ -155,6 +155,7 @@ module.exports = {
155
155
  docs: {
156
156
  description: "Require using arrow functions for callbacks",
157
157
  recommended: false,
158
+ frozen: true,
158
159
  url: "https://eslint.org/docs/latest/rules/prefer-arrow-callback"
159
160
  },
160
161
 
@@ -28,6 +28,7 @@ module.exports = {
28
28
  docs: {
29
29
  description: "Require destructuring from arrays and/or objects",
30
30
  recommended: false,
31
+ frozen: true,
31
32
  url: "https://eslint.org/docs/latest/rules/prefer-destructuring"
32
33
  },
33
34
 
@@ -93,6 +93,7 @@ module.exports = {
93
93
  docs: {
94
94
  description: "Disallow the use of `Math.pow` in favor of the `**` operator",
95
95
  recommended: false,
96
+ frozen: true,
96
97
  url: "https://eslint.org/docs/latest/rules/prefer-exponentiation-operator"
97
98
  },
98
99
 
@@ -47,6 +47,7 @@ module.exports = {
47
47
  docs: {
48
48
  description: "Disallow `parseInt()` and `Number.parseInt()` in favor of binary, octal, and hexadecimal literals",
49
49
  recommended: false,
50
+ frozen: true,
50
51
  url: "https://eslint.org/docs/latest/rules/prefer-numeric-literals"
51
52
  },
52
53
 
@@ -248,6 +248,7 @@ module.exports = {
248
248
  description:
249
249
  "Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead",
250
250
  recommended: false,
251
+ frozen: true,
251
252
  url: "https://eslint.org/docs/latest/rules/prefer-object-spread"
252
253
  },
253
254
 
@@ -51,6 +51,7 @@ module.exports = {
51
51
  docs: {
52
52
  description: "Require spread operators instead of `.apply()`",
53
53
  recommended: false,
54
+ frozen: true,
54
55
  url: "https://eslint.org/docs/latest/rules/prefer-spread"
55
56
  },
56
57
 
@@ -130,6 +130,7 @@ module.exports = {
130
130
  docs: {
131
131
  description: "Require template literals instead of string concatenation",
132
132
  recommended: false,
133
+ frozen: true,
133
134
  url: "https://eslint.org/docs/latest/rules/prefer-template"
134
135
  },
135
136
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @fileoverview Rule to require sorting of import declarations
2
+ * @fileoverview Rule to enforce sorted `import` declarations within modules
3
3
  * @author Christian Schuller
4
4
  */
5
5
 
@@ -23,8 +23,9 @@ module.exports = {
23
23
  }],
24
24
 
25
25
  docs: {
26
- description: "Enforce sorted import declarations within modules",
26
+ description: "Enforce sorted `import` declarations within modules",
27
27
  recommended: false,
28
+ frozen: true,
28
29
  url: "https://eslint.org/docs/latest/rules/sort-imports"
29
30
  },
30
31
 
@@ -91,6 +91,7 @@ module.exports = {
91
91
  docs: {
92
92
  description: "Require object keys to be sorted",
93
93
  recommended: false,
94
+ frozen: true,
94
95
  url: "https://eslint.org/docs/latest/rules/sort-keys"
95
96
  },
96
97
 
@@ -21,6 +21,7 @@ module.exports = {
21
21
  docs: {
22
22
  description: "Require variables within the same declaration block to be sorted",
23
23
  recommended: false,
24
+ frozen: true,
24
25
  url: "https://eslint.org/docs/latest/rules/sort-vars"
25
26
  },
26
27
 
@@ -17,6 +17,7 @@ module.exports = {
17
17
  docs: {
18
18
  description: "Require `var` declarations be placed at the top of their containing scope",
19
19
  recommended: false,
20
+ frozen: true,
20
21
  url: "https://eslint.org/docs/latest/rules/vars-on-top"
21
22
  },
22
23
 
package/lib/rules/yoda.js CHANGED
@@ -119,6 +119,7 @@ module.exports = {
119
119
  docs: {
120
120
  description: 'Require or disallow "Yoda" conditions',
121
121
  recommended: false,
122
+ frozen: true,
122
123
  url: "https://eslint.org/docs/latest/rules/yoda"
123
124
  },
124
125
 
@@ -10,8 +10,7 @@
10
10
  */
11
11
  const activeFlags = new Map([
12
12
  ["test_only", "Used only for testing."],
13
- ["unstable_config_lookup_from_file", "Look up `eslint.config.js` from the file being linted."],
14
- ["unstable_ts_config", "Enable TypeScript configuration files."]
13
+ ["unstable_config_lookup_from_file", "Look up `eslint.config.js` from the file being linted."]
15
14
  ]);
16
15
 
17
16
  /**
@@ -19,7 +18,8 @@ const activeFlags = new Map([
19
18
  * @type {Map<string, string>}
20
19
  */
21
20
  const inactiveFlags = new Map([
22
- ["test_only_old", "Used only for testing."]
21
+ ["test_only_old", "Used only for testing."],
22
+ ["unstable_ts_config", "This flag is no longer required to enable TypeScript configuration files."]
23
23
  ]);
24
24
 
25
25
  module.exports = {
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @fileoverview Utilities to operate on option objects.
3
+ * @author Josh Goldberg
4
+ */
5
+
6
+ "use strict";
7
+
8
+ /**
9
+ * Determines whether any of input's properties are different
10
+ * from values that already exist in original.
11
+ * @template T
12
+ * @param {Partial<T>} input New value.
13
+ * @param {T} original Original value.
14
+ * @returns {boolean} Whether input includes an explicit difference.
15
+ */
16
+ function containsDifferentProperty(input, original) {
17
+ if (input === original) {
18
+ return false;
19
+ }
20
+
21
+ if (
22
+ typeof input !== typeof original ||
23
+ Array.isArray(input) !== Array.isArray(original)
24
+ ) {
25
+ return true;
26
+ }
27
+
28
+ if (Array.isArray(input)) {
29
+ return (
30
+ input.length !== original.length ||
31
+ input.some((value, i) =>
32
+ containsDifferentProperty(value, original[i]))
33
+ );
34
+ }
35
+
36
+ if (typeof input === "object") {
37
+ if (input === null || original === null) {
38
+ return true;
39
+ }
40
+
41
+ const inputKeys = Object.keys(input);
42
+ const originalKeys = Object.keys(original);
43
+
44
+ return inputKeys.length !== originalKeys.length || inputKeys.some(
45
+ inputKey =>
46
+ !Object.hasOwn(original, inputKey) ||
47
+ containsDifferentProperty(input[inputKey], original[inputKey])
48
+ );
49
+ }
50
+
51
+ return true;
52
+ }
53
+
54
+ module.exports = {
55
+ containsDifferentProperty
56
+ };
@@ -1371,6 +1371,12 @@ export namespace Linter {
1371
1371
  * tracked and reported.
1372
1372
  */
1373
1373
  reportUnusedDisableDirectives?: Severity | StringSeverity | boolean;
1374
+
1375
+ /**
1376
+ * A severity value indicating if and how unused inline configs should be
1377
+ * tracked and reported.
1378
+ */
1379
+ reportUnusedInlineConfigs?: Severity | StringSeverity;
1374
1380
  }
1375
1381
 
1376
1382
  interface Stats {
@@ -1484,7 +1490,7 @@ export namespace ESLint {
1484
1490
  allowInlineConfig?: boolean | undefined;
1485
1491
  baseConfig?: Linter.Config | Linter.Config[] | null | undefined;
1486
1492
  overrideConfig?: Linter.Config | Linter.Config[] | null | undefined;
1487
- overrideConfigFile?: string | boolean | undefined;
1493
+ overrideConfigFile?: string | true | null | undefined;
1488
1494
  plugins?: Record<string, Plugin> | null | undefined;
1489
1495
  ruleFilter?: ((arg: { ruleId: string; severity: Exclude<Linter.Severity, 0> }) => boolean) | undefined;
1490
1496
  stats?: boolean | undefined;