eslint 8.47.0 → 8.57.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 (118) hide show
  1. package/README.md +18 -13
  2. package/bin/eslint.js +38 -5
  3. package/conf/rule-type-list.json +25 -33
  4. package/lib/api.js +29 -1
  5. package/lib/cli-engine/cli-engine.js +2 -2
  6. package/lib/cli-engine/lint-result-cache.js +18 -6
  7. package/lib/cli.js +36 -6
  8. package/lib/config/flat-config-schema.js +124 -61
  9. package/lib/config/rule-validator.js +2 -1
  10. package/lib/eslint/eslint-helpers.js +9 -11
  11. package/lib/eslint/eslint.js +7 -0
  12. package/lib/eslint/flat-eslint.js +33 -18
  13. package/lib/linter/apply-disable-directives.js +127 -13
  14. package/lib/linter/code-path-analysis/code-path-analyzer.js +32 -24
  15. package/lib/linter/code-path-analysis/code-path-segment.js +52 -24
  16. package/lib/linter/code-path-analysis/code-path-state.js +1108 -243
  17. package/lib/linter/code-path-analysis/code-path.js +128 -33
  18. package/lib/linter/code-path-analysis/fork-context.js +173 -72
  19. package/lib/linter/config-comment-parser.js +36 -2
  20. package/lib/linter/linter.js +183 -82
  21. package/lib/options.js +24 -3
  22. package/lib/rule-tester/flat-rule-tester.js +113 -25
  23. package/lib/rule-tester/rule-tester.js +176 -23
  24. package/lib/rules/array-bracket-newline.js +3 -0
  25. package/lib/rules/array-bracket-spacing.js +3 -0
  26. package/lib/rules/array-callback-return.js +175 -25
  27. package/lib/rules/array-element-newline.js +3 -0
  28. package/lib/rules/arrow-parens.js +3 -0
  29. package/lib/rules/arrow-spacing.js +3 -0
  30. package/lib/rules/block-spacing.js +3 -0
  31. package/lib/rules/brace-style.js +3 -0
  32. package/lib/rules/comma-dangle.js +3 -0
  33. package/lib/rules/comma-spacing.js +3 -0
  34. package/lib/rules/comma-style.js +3 -0
  35. package/lib/rules/computed-property-spacing.js +3 -0
  36. package/lib/rules/consistent-return.js +32 -7
  37. package/lib/rules/constructor-super.js +37 -14
  38. package/lib/rules/dot-location.js +3 -0
  39. package/lib/rules/eol-last.js +3 -0
  40. package/lib/rules/for-direction.js +38 -24
  41. package/lib/rules/func-call-spacing.js +3 -0
  42. package/lib/rules/function-call-argument-newline.js +3 -0
  43. package/lib/rules/function-paren-newline.js +3 -0
  44. package/lib/rules/generator-star-spacing.js +3 -0
  45. package/lib/rules/getter-return.js +33 -8
  46. package/lib/rules/implicit-arrow-linebreak.js +3 -0
  47. package/lib/rules/indent.js +3 -0
  48. package/lib/rules/index.js +1 -0
  49. package/lib/rules/jsx-quotes.js +3 -0
  50. package/lib/rules/key-spacing.js +3 -0
  51. package/lib/rules/keyword-spacing.js +3 -0
  52. package/lib/rules/linebreak-style.js +3 -0
  53. package/lib/rules/lines-around-comment.js +3 -0
  54. package/lib/rules/lines-between-class-members.js +95 -7
  55. package/lib/rules/logical-assignment-operators.js +31 -3
  56. package/lib/rules/max-len.js +3 -0
  57. package/lib/rules/max-statements-per-line.js +3 -0
  58. package/lib/rules/multiline-ternary.js +3 -0
  59. package/lib/rules/new-parens.js +3 -0
  60. package/lib/rules/newline-per-chained-call.js +3 -0
  61. package/lib/rules/no-array-constructor.js +85 -6
  62. package/lib/rules/no-confusing-arrow.js +3 -0
  63. package/lib/rules/no-console.js +74 -2
  64. package/lib/rules/no-extra-parens.js +3 -0
  65. package/lib/rules/no-extra-semi.js +3 -0
  66. package/lib/rules/no-fallthrough.js +42 -14
  67. package/lib/rules/no-floating-decimal.js +3 -0
  68. package/lib/rules/no-invalid-this.js +1 -1
  69. package/lib/rules/no-misleading-character-class.js +65 -15
  70. package/lib/rules/no-mixed-operators.js +3 -0
  71. package/lib/rules/no-mixed-spaces-and-tabs.js +3 -0
  72. package/lib/rules/no-multi-spaces.js +3 -0
  73. package/lib/rules/no-multiple-empty-lines.js +3 -0
  74. package/lib/rules/no-new-object.js +7 -0
  75. package/lib/rules/no-object-constructor.js +117 -0
  76. package/lib/rules/no-promise-executor-return.js +157 -16
  77. package/lib/rules/no-prototype-builtins.js +90 -2
  78. package/lib/rules/no-restricted-imports.js +54 -31
  79. package/lib/rules/no-restricted-properties.js +15 -28
  80. package/lib/rules/no-tabs.js +3 -0
  81. package/lib/rules/no-this-before-super.js +38 -11
  82. package/lib/rules/no-trailing-spaces.js +3 -0
  83. package/lib/rules/no-unreachable-loop.js +47 -12
  84. package/lib/rules/no-unreachable.js +39 -10
  85. package/lib/rules/no-useless-return.js +35 -4
  86. package/lib/rules/no-whitespace-before-property.js +3 -0
  87. package/lib/rules/nonblock-statement-body-position.js +3 -0
  88. package/lib/rules/object-curly-newline.js +3 -0
  89. package/lib/rules/object-curly-spacing.js +3 -0
  90. package/lib/rules/object-property-newline.js +3 -0
  91. package/lib/rules/one-var-declaration-per-line.js +3 -0
  92. package/lib/rules/operator-linebreak.js +3 -0
  93. package/lib/rules/padded-blocks.js +3 -0
  94. package/lib/rules/padding-line-between-statements.js +3 -0
  95. package/lib/rules/quote-props.js +3 -0
  96. package/lib/rules/quotes.js +3 -0
  97. package/lib/rules/require-atomic-updates.js +21 -7
  98. package/lib/rules/rest-spread-spacing.js +3 -0
  99. package/lib/rules/semi-spacing.js +3 -0
  100. package/lib/rules/semi-style.js +3 -0
  101. package/lib/rules/semi.js +3 -0
  102. package/lib/rules/space-before-blocks.js +3 -0
  103. package/lib/rules/space-before-function-paren.js +3 -0
  104. package/lib/rules/space-in-parens.js +3 -0
  105. package/lib/rules/space-infix-ops.js +3 -0
  106. package/lib/rules/space-unary-ops.js +3 -0
  107. package/lib/rules/spaced-comment.js +3 -0
  108. package/lib/rules/switch-colon-spacing.js +3 -0
  109. package/lib/rules/template-curly-spacing.js +3 -0
  110. package/lib/rules/template-tag-spacing.js +3 -0
  111. package/lib/rules/utils/ast-utils.js +111 -1
  112. package/lib/rules/wrap-iife.js +3 -0
  113. package/lib/rules/wrap-regex.js +3 -0
  114. package/lib/rules/yield-star-spacing.js +3 -0
  115. package/lib/shared/severity.js +49 -0
  116. package/lib/source-code/source-code.js +329 -3
  117. package/messages/eslintrc-incompat.js +1 -1
  118. package/package.json +24 -17
package/README.md CHANGED
@@ -103,7 +103,7 @@ We are now at or near 100% compatibility with JSCS. If you try ESLint and believ
103
103
 
104
104
  ### Does Prettier replace ESLint?
105
105
 
106
- No, ESLint does both traditional linting (looking for problematic patterns) and style checking (enforcement of conventions). You can use ESLint for everything, or you can combine both using Prettier to format your code and ESLint to catch possible errors.
106
+ No, ESLint and Prettier have diffent jobs: ESLint is a linter (looking for problematic patterns) and Prettier is a code formatter. Using both tools is common, refer to [Prettier's documentation](https://prettier.io/docs/en/install#eslint-and-other-linters) to learn how to configure them to work well with each other.
107
107
 
108
108
  ### Why can't ESLint find my plugins?
109
109
 
@@ -209,12 +209,12 @@ The people who manage releases, review feature requests, and meet regularly to e
209
209
 
210
210
  <table><tbody><tr><td align="center" valign="top" width="11%">
211
211
  <a href="https://github.com/nzakas">
212
- <img src="https://github.com/nzakas.png?s=75" width="75" height="75"><br />
212
+ <img src="https://github.com/nzakas.png?s=75" width="75" height="75" alt="Nicholas C. Zakas's Avatar"><br />
213
213
  Nicholas C. Zakas
214
214
  </a>
215
215
  </td><td align="center" valign="top" width="11%">
216
216
  <a href="https://github.com/mdjermanovic">
217
- <img src="https://github.com/mdjermanovic.png?s=75" width="75" height="75"><br />
217
+ <img src="https://github.com/mdjermanovic.png?s=75" width="75" height="75" alt="Milos Djermanovic's Avatar"><br />
218
218
  Milos Djermanovic
219
219
  </a>
220
220
  </td></tr></tbody></table>
@@ -225,12 +225,12 @@ The people who review and implement new features.
225
225
 
226
226
  <table><tbody><tr><td align="center" valign="top" width="11%">
227
227
  <a href="https://github.com/aladdin-add">
228
- <img src="https://github.com/aladdin-add.png?s=75" width="75" height="75"><br />
228
+ <img src="https://github.com/aladdin-add.png?s=75" width="75" height="75" alt="唯然's Avatar"><br />
229
229
  唯然
230
230
  </a>
231
231
  </td><td align="center" valign="top" width="11%">
232
232
  <a href="https://github.com/snitin315">
233
- <img src="https://github.com/snitin315.png?s=75" width="75" height="75"><br />
233
+ <img src="https://github.com/snitin315.png?s=75" width="75" height="75" alt="Nitin Kumar's Avatar"><br />
234
234
  Nitin Kumar
235
235
  </a>
236
236
  </td></tr></tbody></table>
@@ -241,19 +241,24 @@ The people who review and fix bugs and help triage issues.
241
241
 
242
242
  <table><tbody><tr><td align="center" valign="top" width="11%">
243
243
  <a href="https://github.com/bmish">
244
- <img src="https://github.com/bmish.png?s=75" width="75" height="75"><br />
244
+ <img src="https://github.com/bmish.png?s=75" width="75" height="75" alt="Bryan Mishkin's Avatar"><br />
245
245
  Bryan Mishkin
246
246
  </a>
247
247
  </td><td align="center" valign="top" width="11%">
248
248
  <a href="https://github.com/fasttime">
249
- <img src="https://github.com/fasttime.png?s=75" width="75" height="75"><br />
249
+ <img src="https://github.com/fasttime.png?s=75" width="75" height="75" alt="Francesco Trotta's Avatar"><br />
250
250
  Francesco Trotta
251
251
  </a>
252
252
  </td><td align="center" valign="top" width="11%">
253
253
  <a href="https://github.com/ota-meshi">
254
- <img src="https://github.com/ota-meshi.png?s=75" width="75" height="75"><br />
254
+ <img src="https://github.com/ota-meshi.png?s=75" width="75" height="75" alt="Yosuke Ota's Avatar"><br />
255
255
  Yosuke Ota
256
256
  </a>
257
+ </td><td align="center" valign="top" width="11%">
258
+ <a href="https://github.com/Tanujkanti4441">
259
+ <img src="https://github.com/Tanujkanti4441.png?s=75" width="75" height="75" alt="Tanuj Kanti's Avatar"><br />
260
+ Tanuj Kanti
261
+ </a>
257
262
  </td></tr></tbody></table>
258
263
 
259
264
  ### Website Team
@@ -262,17 +267,17 @@ Team members who focus specifically on eslint.org
262
267
 
263
268
  <table><tbody><tr><td align="center" valign="top" width="11%">
264
269
  <a href="https://github.com/amareshsm">
265
- <img src="https://github.com/amareshsm.png?s=75" width="75" height="75"><br />
270
+ <img src="https://github.com/amareshsm.png?s=75" width="75" height="75" alt="Amaresh S M's Avatar"><br />
266
271
  Amaresh S M
267
272
  </a>
268
273
  </td><td align="center" valign="top" width="11%">
269
274
  <a href="https://github.com/harish-sethuraman">
270
- <img src="https://github.com/harish-sethuraman.png?s=75" width="75" height="75"><br />
275
+ <img src="https://github.com/harish-sethuraman.png?s=75" width="75" height="75" alt="Strek's Avatar"><br />
271
276
  Strek
272
277
  </a>
273
278
  </td><td align="center" valign="top" width="11%">
274
279
  <a href="https://github.com/kecrily">
275
- <img src="https://github.com/kecrily.png?s=75" width="75" height="75"><br />
280
+ <img src="https://github.com/kecrily.png?s=75" width="75" height="75" alt="Percy Ma's Avatar"><br />
276
281
  Percy Ma
277
282
  </a>
278
283
  </td></tr></tbody></table>
@@ -288,8 +293,8 @@ The following companies, organizations, and individuals support ESLint's ongoing
288
293
  <h3>Platinum Sponsors</h3>
289
294
  <p><a href="#"><img src="https://images.opencollective.com/2021-frameworks-fund/logo.png" alt="Chrome Frameworks Fund" height="undefined"></a> <a href="https://automattic.com"><img src="https://images.opencollective.com/automattic/d0ef3e1/logo.png" alt="Automattic" height="undefined"></a></p><h3>Gold Sponsors</h3>
290
295
  <p><a href="https://engineering.salesforce.com"><img src="https://images.opencollective.com/salesforce/ca8f997/logo.png" alt="Salesforce" height="96"></a> <a href="https://www.airbnb.com/"><img src="https://images.opencollective.com/airbnb/d327d66/logo.png" alt="Airbnb" height="96"></a></p><h3>Silver Sponsors</h3>
291
- <p><a href="https://sentry.io"><img src="https://avatars.githubusercontent.com/u/1396951?v=4" alt="Sentry" 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?v=4" alt="American Express" height="64"></a></p><h3>Bronze Sponsors</h3>
292
- <p><a href="https://themeisle.com"><img src="https://images.opencollective.com/themeisle/d5592fe/logo.png" alt="ThemeIsle" height="32"></a> <a href="https://nx.dev"><img src="https://images.opencollective.com/nx/0efbe42/logo.png" alt="Nx (by Nrwl)" height="32"></a> <a href="https://www.crosswordsolver.org/anagram-solver/"><img src="https://images.opencollective.com/anagram-solver/2666271/logo.png" alt="Anagram Solver" height="32"></a> <a href="https://icons8.com"><img src="https://images.opencollective.com/icons8/7fa1641/logo.png" alt="Icons8: free icons, photos, illustrations, and music" height="32"></a> <a href="https://discord.com"><img src="https://images.opencollective.com/discordapp/f9645d9/logo.png" alt="Discord" height="32"></a> <a href="https://github.com/about"><img src="https://avatars.githubusercontent.com/u/9919?v=4" alt="GitHub" height="32"></a> <a href="https://transloadit.com/"><img src="https://avatars.githubusercontent.com/u/125754?v=4" alt="Transloadit" height="32"></a> <a href="https://www.ignitionapp.com"><img src="https://avatars.githubusercontent.com/u/5753491?v=4" alt="Ignition" height="32"></a> <a href="https://herocoders.com"><img src="https://avatars.githubusercontent.com/u/37549774?v=4" alt="HeroCoders" height="32"></a> <a href="https://quickbookstoolhub.com"><img src="https://avatars.githubusercontent.com/u/95090305?u=e5bc398ef775c9ed19f955c675cdc1fb6abf01df&v=4" alt="QuickBooks Tool hub" height="32"></a></p>
296
+ <p><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?v=4" alt="American Express" height="64"></a> <a href="https://www.workleap.com"><img src="https://avatars.githubusercontent.com/u/53535748?u=d1e55d7661d724bf2281c1bfd33cb8f99fe2465f&v=4" alt="Workleap" height="64"></a></p><h3>Bronze Sponsors</h3>
297
+ <p><a href="https://themeisle.com"><img src="https://images.opencollective.com/themeisle/d5592fe/logo.png" alt="ThemeIsle" height="32"></a> <a href="https://www.crosswordsolver.org/anagram-solver/"><img src="https://images.opencollective.com/anagram-solver/2666271/logo.png" alt="Anagram Solver" height="32"></a> <a href="https://icons8.com/"><img src="https://images.opencollective.com/icons8/7fa1641/logo.png" alt="Icons8" height="32"></a> <a href="https://discord.com"><img src="https://images.opencollective.com/discordapp/f9645d9/logo.png" alt="Discord" height="32"></a> <a href="https://transloadit.com/"><img src="https://avatars.githubusercontent.com/u/125754?v=4" alt="Transloadit" height="32"></a> <a href="https://www.ignitionapp.com"><img src="https://avatars.githubusercontent.com/u/5753491?v=4" alt="Ignition" height="32"></a> <a href="https://nx.dev"><img src="https://avatars.githubusercontent.com/u/23692104?v=4" alt="Nx" height="32"></a> <a href="https://herocoders.com"><img src="https://avatars.githubusercontent.com/u/37549774?v=4" alt="HeroCoders" height="32"></a></p>
293
298
  <!--sponsorsend-->
294
299
 
295
300
  ## Technology Sponsors
package/bin/eslint.js CHANGED
@@ -92,6 +92,19 @@ function getErrorMessage(error) {
92
92
  return util.format("%o", error);
93
93
  }
94
94
 
95
+ /**
96
+ * Tracks error messages that are shown to the user so we only ever show the
97
+ * same message once.
98
+ * @type {Set<string>}
99
+ */
100
+ const displayedErrors = new Set();
101
+
102
+ /**
103
+ * Tracks whether an unexpected error was caught
104
+ * @type {boolean}
105
+ */
106
+ let hadFatalError = false;
107
+
95
108
  /**
96
109
  * Catch and report unexpected error.
97
110
  * @param {any} error The thrown error object.
@@ -99,16 +112,20 @@ function getErrorMessage(error) {
99
112
  */
100
113
  function onFatalError(error) {
101
114
  process.exitCode = 2;
115
+ hadFatalError = true;
102
116
 
103
117
  const { version } = require("../package.json");
104
- const message = getErrorMessage(error);
105
-
106
- console.error(`
118
+ const message = `
107
119
  Oops! Something went wrong! :(
108
120
 
109
121
  ESLint: ${version}
110
122
 
111
- ${message}`);
123
+ ${getErrorMessage(error)}`;
124
+
125
+ if (!displayedErrors.has(message)) {
126
+ console.error(message);
127
+ displayedErrors.add(message);
128
+ }
112
129
  }
113
130
 
114
131
  //------------------------------------------------------------------------------
@@ -132,9 +149,25 @@ ${message}`);
132
149
  }
133
150
 
134
151
  // Otherwise, call the CLI.
135
- process.exitCode = await require("../lib/cli").execute(
152
+ const exitCode = await require("../lib/cli").execute(
136
153
  process.argv,
137
154
  process.argv.includes("--stdin") ? await readStdin() : null,
138
155
  true
139
156
  );
157
+
158
+ /*
159
+ * If an uncaught exception or unhandled rejection was detected in the meantime,
160
+ * keep the fatal exit code 2 that is already assigned to `process.exitCode`.
161
+ * Without this condition, exit code 2 (unsuccessful execution) could be overwritten with
162
+ * 1 (successful execution, lint problems found) or even 0 (successful execution, no lint problems found).
163
+ * This ensures that unexpected errors that seemingly don't affect the success
164
+ * of the execution will still cause a non-zero exit code, as it's a common
165
+ * practice and the default behavior of Node.js to exit with non-zero
166
+ * in case of an uncaught exception or unhandled rejection.
167
+ *
168
+ * Otherwise, assign the exit code returned from CLI.
169
+ */
170
+ if (!hadFatalError) {
171
+ process.exitCode = exitCode;
172
+ }
140
173
  }()).catch(onFatalError);
@@ -1,36 +1,28 @@
1
1
  {
2
- "types": [
3
- { "name": "problem", "displayName": "Possible Problems", "description": "These rules relate to possible logic errors in code:" },
4
- { "name": "suggestion", "displayName": "Suggestions", "description": "These rules suggest alternate ways of doing things:" },
5
- { "name": "layout", "displayName": "Layout & Formatting", "description": "These rules care about how the code looks rather than how it executes:" }
6
- ],
7
- "deprecated": {
8
- "name": "Deprecated",
9
- "description": "These rules have been deprecated in accordance with the <a href=\"{{ '/use/rule-deprecation' | url }}\">deprecation policy</a>, and replaced by newer rules:",
10
- "rules": []
2
+ "types": {
3
+ "problem": [],
4
+ "suggestion": [],
5
+ "layout": []
11
6
  },
12
- "removed": {
13
- "name": "Removed",
14
- "description": "These rules from older versions of ESLint (before the <a href=\"{{ '/use/rule-deprecation' | url }}\">deprecation policy</a> existed) have been replaced by newer rules:",
15
- "rules": [
16
- { "removed": "generator-star", "replacedBy": ["generator-star-spacing"] },
17
- { "removed": "global-strict", "replacedBy": ["strict"] },
18
- { "removed": "no-arrow-condition", "replacedBy": ["no-confusing-arrow", "no-constant-condition"] },
19
- { "removed": "no-comma-dangle", "replacedBy": ["comma-dangle"] },
20
- { "removed": "no-empty-class", "replacedBy": ["no-empty-character-class"] },
21
- { "removed": "no-empty-label", "replacedBy": ["no-labels"] },
22
- { "removed": "no-extra-strict", "replacedBy": ["strict"] },
23
- { "removed": "no-reserved-keys", "replacedBy": ["quote-props"] },
24
- { "removed": "no-space-before-semi", "replacedBy": ["semi-spacing"] },
25
- { "removed": "no-wrap-func", "replacedBy": ["no-extra-parens"] },
26
- { "removed": "space-after-function-name", "replacedBy": ["space-before-function-paren"] },
27
- { "removed": "space-after-keywords", "replacedBy": ["keyword-spacing"] },
28
- { "removed": "space-before-function-parentheses", "replacedBy": ["space-before-function-paren"] },
29
- { "removed": "space-before-keywords", "replacedBy": ["keyword-spacing"] },
30
- { "removed": "space-in-brackets", "replacedBy": ["object-curly-spacing", "array-bracket-spacing"] },
31
- { "removed": "space-return-throw-case", "replacedBy": ["keyword-spacing"] },
32
- { "removed": "space-unary-word-ops", "replacedBy": ["space-unary-ops"] },
33
- { "removed": "spaced-line-comment", "replacedBy": ["spaced-comment"] }
34
- ]
35
- }
7
+ "deprecated": [],
8
+ "removed": [
9
+ { "removed": "generator-star", "replacedBy": ["generator-star-spacing"] },
10
+ { "removed": "global-strict", "replacedBy": ["strict"] },
11
+ { "removed": "no-arrow-condition", "replacedBy": ["no-confusing-arrow", "no-constant-condition"] },
12
+ { "removed": "no-comma-dangle", "replacedBy": ["comma-dangle"] },
13
+ { "removed": "no-empty-class", "replacedBy": ["no-empty-character-class"] },
14
+ { "removed": "no-empty-label", "replacedBy": ["no-labels"] },
15
+ { "removed": "no-extra-strict", "replacedBy": ["strict"] },
16
+ { "removed": "no-reserved-keys", "replacedBy": ["quote-props"] },
17
+ { "removed": "no-space-before-semi", "replacedBy": ["semi-spacing"] },
18
+ { "removed": "no-wrap-func", "replacedBy": ["no-extra-parens"] },
19
+ { "removed": "space-after-function-name", "replacedBy": ["space-before-function-paren"] },
20
+ { "removed": "space-after-keywords", "replacedBy": ["keyword-spacing"] },
21
+ { "removed": "space-before-function-parentheses", "replacedBy": ["space-before-function-paren"] },
22
+ { "removed": "space-before-keywords", "replacedBy": ["keyword-spacing"] },
23
+ { "removed": "space-in-brackets", "replacedBy": ["object-curly-spacing", "array-bracket-spacing"] },
24
+ { "removed": "space-return-throw-case", "replacedBy": ["keyword-spacing"] },
25
+ { "removed": "space-unary-word-ops", "replacedBy": ["space-unary-ops"] },
26
+ { "removed": "spaced-line-comment", "replacedBy": ["spaced-comment"] }
27
+ ]
36
28
  }
package/lib/api.js CHANGED
@@ -9,17 +9,45 @@
9
9
  // Requirements
10
10
  //-----------------------------------------------------------------------------
11
11
 
12
- const { ESLint } = require("./eslint");
12
+ const { ESLint, FlatESLint } = require("./eslint");
13
+ const { shouldUseFlatConfig } = require("./eslint/flat-eslint");
13
14
  const { Linter } = require("./linter");
14
15
  const { RuleTester } = require("./rule-tester");
15
16
  const { SourceCode } = require("./source-code");
16
17
 
18
+ //-----------------------------------------------------------------------------
19
+ // Functions
20
+ //-----------------------------------------------------------------------------
21
+
22
+ /**
23
+ * Loads the correct ESLint constructor given the options.
24
+ * @param {Object} [options] The options object
25
+ * @param {boolean} [options.useFlatConfig] Whether or not to use a flat config
26
+ * @param {string} [options.cwd] The current working directory
27
+ * @returns {Promise<ESLint|LegacyESLint>} The ESLint constructor
28
+ */
29
+ async function loadESLint({ useFlatConfig, cwd = process.cwd() } = {}) {
30
+
31
+ /*
32
+ * Note: The v9.x version of this function doesn't have a cwd option
33
+ * because it's not used. It's only used in the v8.x version of this
34
+ * function.
35
+ */
36
+
37
+ const shouldESLintUseFlatConfig = typeof useFlatConfig === "boolean"
38
+ ? useFlatConfig
39
+ : await shouldUseFlatConfig({ cwd });
40
+
41
+ return shouldESLintUseFlatConfig ? FlatESLint : ESLint;
42
+ }
43
+
17
44
  //-----------------------------------------------------------------------------
18
45
  // Exports
19
46
  //-----------------------------------------------------------------------------
20
47
 
21
48
  module.exports = {
22
49
  Linter,
50
+ loadESLint,
23
51
  ESLint,
24
52
  RuleTester,
25
53
  SourceCode
@@ -83,7 +83,7 @@ const validFixTypes = new Set(["directive", "problem", "suggestion", "layout"]);
83
83
  * @property {string[]} [plugins] An array of plugins to load.
84
84
  * @property {Record<string,RuleConf>} [rules] An object of rules to use.
85
85
  * @property {string[]} [rulePaths] An array of directories to load custom rules from.
86
- * @property {boolean} [reportUnusedDisableDirectives] `true` adds reports for unused eslint-disable directives
86
+ * @property {boolean|string} [reportUnusedDisableDirectives] `true`, `"error"` or '"warn"' adds reports for unused eslint-disable directives
87
87
  * @property {boolean} [globInputPaths] Set to false to skip glob resolution of input file paths to lint (default: true). If false, each input file paths is assumed to be a non-glob path to an existing file.
88
88
  * @property {string} [resolvePluginsRelativeTo] The folder where plugins should be resolved from, defaulting to the CWD
89
89
  */
@@ -224,7 +224,7 @@ function calculateStatsPerRun(results) {
224
224
  * @param {ConfigArray} config.config The config.
225
225
  * @param {boolean} config.fix If `true` then it does fix.
226
226
  * @param {boolean} config.allowInlineConfig If `true` then it uses directive comments.
227
- * @param {boolean} config.reportUnusedDisableDirectives If `true` then it reports unused `eslint-disable` comments.
227
+ * @param {boolean|string} config.reportUnusedDisableDirectives If `true`, `"error"` or '"warn"', then it reports unused `eslint-disable` comments.
228
228
  * @param {FileEnumerator} config.fileEnumerator The file enumerator to check if a path is a target or not.
229
229
  * @param {Linter} config.linter The linter instance to verify.
230
230
  * @returns {LintResult} The result of linting.
@@ -128,16 +128,28 @@ class LintResultCache {
128
128
  return null;
129
129
  }
130
130
 
131
+ const cachedResults = fileDescriptor.meta.results;
132
+
133
+ // Just in case, not sure if this can ever happen.
134
+ if (!cachedResults) {
135
+ return cachedResults;
136
+ }
137
+
138
+ /*
139
+ * Shallow clone the object to ensure that any properties added or modified afterwards
140
+ * will not be accidentally stored in the cache file when `reconcile()` is called.
141
+ * https://github.com/eslint/eslint/issues/13507
142
+ * All intentional changes to the cache file must be done through `setCachedLintResults()`.
143
+ */
144
+ const results = { ...cachedResults };
145
+
131
146
  // If source is present but null, need to reread the file from the filesystem.
132
- if (
133
- fileDescriptor.meta.results &&
134
- fileDescriptor.meta.results.source === null
135
- ) {
147
+ if (results.source === null) {
136
148
  debug(`Rereading cached result source from filesystem: ${filePath}`);
137
- fileDescriptor.meta.results.source = fs.readFileSync(filePath, "utf-8");
149
+ results.source = fs.readFileSync(filePath, "utf-8");
138
150
  }
139
151
 
140
- return fileDescriptor.meta.results;
152
+ return results;
141
153
  }
142
154
 
143
155
  /**
package/lib/cli.js CHANGED
@@ -22,7 +22,8 @@ const fs = require("fs"),
22
22
  { FlatESLint, shouldUseFlatConfig } = require("./eslint/flat-eslint"),
23
23
  createCLIOptions = require("./options"),
24
24
  log = require("./shared/logging"),
25
- RuntimeInfo = require("./shared/runtime-info");
25
+ RuntimeInfo = require("./shared/runtime-info"),
26
+ { normalizeSeverityToString } = require("./shared/severity");
26
27
  const { Legacy: { naming } } = require("@eslint/eslintrc");
27
28
  const { ModuleImporter } = require("@humanwhocodes/module-importer");
28
29
 
@@ -89,9 +90,11 @@ async function translateOptions({
89
90
  plugin,
90
91
  quiet,
91
92
  reportUnusedDisableDirectives,
93
+ reportUnusedDisableDirectivesSeverity,
92
94
  resolvePluginsRelativeTo,
93
95
  rule,
94
- rulesdir
96
+ rulesdir,
97
+ warnIgnored
95
98
  }, configType) {
96
99
 
97
100
  let overrideConfig, overrideConfigFile;
@@ -124,6 +127,14 @@ async function translateOptions({
124
127
  rules: rule ? rule : {}
125
128
  }];
126
129
 
130
+ if (reportUnusedDisableDirectives || reportUnusedDisableDirectivesSeverity !== void 0) {
131
+ overrideConfig[0].linterOptions = {
132
+ reportUnusedDisableDirectives: reportUnusedDisableDirectives
133
+ ? "error"
134
+ : normalizeSeverityToString(reportUnusedDisableDirectivesSeverity)
135
+ };
136
+ }
137
+
127
138
  if (parser) {
128
139
  overrideConfig[0].languageOptions.parser = await importer.import(parser);
129
140
  }
@@ -176,18 +187,23 @@ async function translateOptions({
176
187
  fixTypes: fixType,
177
188
  ignore,
178
189
  overrideConfig,
179
- overrideConfigFile,
180
- reportUnusedDisableDirectives: reportUnusedDisableDirectives ? "error" : void 0
190
+ overrideConfigFile
181
191
  };
182
192
 
183
193
  if (configType === "flat") {
184
194
  options.ignorePatterns = ignorePattern;
195
+ options.warnIgnored = warnIgnored;
185
196
  } else {
186
197
  options.resolvePluginsRelativeTo = resolvePluginsRelativeTo;
187
198
  options.rulePaths = rulesdir;
188
199
  options.useEslintrc = eslintrc;
189
200
  options.extensions = ext;
190
201
  options.ignorePath = ignorePath;
202
+ if (reportUnusedDisableDirectives || reportUnusedDisableDirectivesSeverity !== void 0) {
203
+ options.reportUnusedDisableDirectives = reportUnusedDisableDirectives
204
+ ? "error"
205
+ : normalizeSeverityToString(reportUnusedDisableDirectivesSeverity);
206
+ }
191
207
  }
192
208
 
193
209
  return options;
@@ -316,7 +332,14 @@ const cli = {
316
332
  options = CLIOptions.parse(args);
317
333
  } catch (error) {
318
334
  debug("Error parsing CLI options:", error.message);
319
- log.error(error.message);
335
+
336
+ let errorMessage = error.message;
337
+
338
+ if (usingFlatConfig) {
339
+ errorMessage += "\nYou're using eslint.config.js, some command line flags are no longer available. Please see https://eslint.org/docs/latest/use/command-line-interface for details.";
340
+ }
341
+
342
+ log.error(errorMessage);
320
343
  return 2;
321
344
  }
322
345
 
@@ -377,6 +400,11 @@ const cli = {
377
400
  return 2;
378
401
  }
379
402
 
403
+ if (options.reportUnusedDisableDirectives && options.reportUnusedDisableDirectivesSeverity !== void 0) {
404
+ log.error("The --report-unused-disable-directives option and the --report-unused-disable-directives-severity option cannot be used together.");
405
+ return 2;
406
+ }
407
+
380
408
  const ActiveESLint = usingFlatConfig ? FlatESLint : ESLint;
381
409
 
382
410
  const engine = new ActiveESLint(await translateOptions(options, usingFlatConfig ? "flat" : "eslintrc"));
@@ -385,7 +413,9 @@ const cli = {
385
413
  if (useStdin) {
386
414
  results = await engine.lintText(text, {
387
415
  filePath: options.stdinFilename,
388
- warnIgnored: true
416
+
417
+ // flatConfig respects CLI flag and constructor warnIgnored, eslintrc forces true for backwards compatibility
418
+ warnIgnored: usingFlatConfig ? void 0 : true
389
419
  });
390
420
  } else {
391
421
  results = await engine.lintFiles(files);