eslint 8.39.0 → 8.47.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.
- package/README.md +10 -4
- package/conf/globals.js +6 -1
- package/lib/cli-engine/cli-engine.js +30 -19
- package/lib/cli.js +2 -28
- package/lib/config/default-config.js +1 -1
- package/lib/config/flat-config-schema.js +127 -35
- package/lib/eslint/eslint-helpers.js +11 -10
- package/lib/eslint/eslint.js +1 -1
- package/lib/eslint/flat-eslint.js +119 -161
- package/lib/linter/apply-disable-directives.js +11 -1
- package/lib/linter/code-path-analysis/debug-helpers.js +1 -1
- package/lib/linter/config-comment-parser.js +9 -2
- package/lib/linter/linter.js +20 -11
- package/lib/linter/report-translator.js +22 -21
- package/lib/rule-tester/flat-rule-tester.js +1 -2
- package/lib/rule-tester/rule-tester.js +1 -2
- package/lib/rules/accessor-pairs.js +35 -43
- package/lib/rules/array-bracket-newline.js +2 -2
- package/lib/rules/array-bracket-spacing.js +2 -2
- package/lib/rules/array-callback-return.js +2 -2
- package/lib/rules/array-element-newline.js +12 -6
- package/lib/rules/arrow-body-style.js +2 -2
- package/lib/rules/arrow-parens.js +2 -2
- package/lib/rules/arrow-spacing.js +2 -2
- package/lib/rules/block-scoped-var.js +17 -7
- package/lib/rules/block-spacing.js +2 -2
- package/lib/rules/brace-style.js +2 -2
- package/lib/rules/callback-return.js +2 -2
- package/lib/rules/camelcase.js +2 -2
- package/lib/rules/capitalized-comments.js +2 -2
- package/lib/rules/class-methods-use-this.js +2 -2
- package/lib/rules/comma-dangle.js +2 -2
- package/lib/rules/comma-spacing.js +2 -2
- package/lib/rules/comma-style.js +2 -2
- package/lib/rules/complexity.js +1 -1
- package/lib/rules/computed-property-spacing.js +2 -2
- package/lib/rules/consistent-return.js +3 -3
- package/lib/rules/consistent-this.js +2 -2
- package/lib/rules/constructor-super.js +1 -1
- package/lib/rules/curly.js +2 -2
- package/lib/rules/default-case-last.js +1 -1
- package/lib/rules/default-case.js +2 -2
- package/lib/rules/default-param-last.js +1 -1
- package/lib/rules/dot-location.js +2 -2
- package/lib/rules/dot-notation.js +3 -4
- package/lib/rules/eol-last.js +2 -2
- package/lib/rules/eqeqeq.js +2 -2
- package/lib/rules/for-direction.js +1 -1
- package/lib/rules/func-call-spacing.js +2 -2
- package/lib/rules/func-name-matching.js +1 -1
- package/lib/rules/func-names.js +2 -2
- package/lib/rules/func-style.js +1 -1
- package/lib/rules/function-call-argument-newline.js +2 -2
- package/lib/rules/function-paren-newline.js +2 -2
- package/lib/rules/generator-star-spacing.js +2 -2
- package/lib/rules/getter-return.js +2 -2
- package/lib/rules/global-require.js +2 -2
- package/lib/rules/grouped-accessor-pairs.js +35 -44
- package/lib/rules/guard-for-in.js +1 -1
- package/lib/rules/handle-callback-err.js +2 -2
- package/lib/rules/id-blacklist.js +2 -2
- package/lib/rules/id-denylist.js +2 -2
- package/lib/rules/id-length.js +3 -36
- package/lib/rules/id-match.js +2 -2
- package/lib/rules/implicit-arrow-linebreak.js +2 -2
- package/lib/rules/indent-legacy.js +2 -2
- package/lib/rules/indent.js +84 -88
- package/lib/rules/init-declarations.js +1 -1
- package/lib/rules/jsx-quotes.js +1 -1
- package/lib/rules/key-spacing.js +4 -10
- package/lib/rules/keyword-spacing.js +2 -2
- package/lib/rules/line-comment-position.js +2 -2
- package/lib/rules/linebreak-style.js +2 -2
- package/lib/rules/lines-around-comment.js +2 -2
- package/lib/rules/lines-around-directive.js +2 -2
- package/lib/rules/lines-between-class-members.js +2 -2
- package/lib/rules/logical-assignment-operators.js +7 -5
- package/lib/rules/max-classes-per-file.js +1 -1
- package/lib/rules/max-depth.js +1 -1
- package/lib/rules/max-len.js +19 -15
- package/lib/rules/max-lines-per-function.js +2 -2
- package/lib/rules/max-lines.js +2 -2
- package/lib/rules/max-nested-callbacks.js +1 -1
- package/lib/rules/max-params.js +2 -2
- package/lib/rules/max-statements-per-line.js +2 -2
- package/lib/rules/max-statements.js +1 -1
- package/lib/rules/multiline-comment-style.js +2 -2
- package/lib/rules/multiline-ternary.js +2 -2
- package/lib/rules/new-cap.js +2 -2
- package/lib/rules/new-parens.js +2 -2
- package/lib/rules/newline-after-var.js +2 -4
- package/lib/rules/newline-before-return.js +2 -2
- package/lib/rules/newline-per-chained-call.js +2 -2
- package/lib/rules/no-alert.js +2 -2
- package/lib/rules/no-array-constructor.js +1 -1
- package/lib/rules/no-async-promise-executor.js +2 -2
- package/lib/rules/no-await-in-loop.js +1 -1
- package/lib/rules/no-bitwise.js +1 -1
- package/lib/rules/no-buffer-constructor.js +1 -1
- package/lib/rules/no-caller.js +1 -1
- package/lib/rules/no-case-declarations.js +1 -1
- package/lib/rules/no-catch-shadow.js +2 -2
- package/lib/rules/no-class-assign.js +2 -2
- package/lib/rules/no-compare-neg-zero.js +1 -1
- package/lib/rules/no-cond-assign.js +2 -2
- package/lib/rules/no-confusing-arrow.js +2 -2
- package/lib/rules/no-console.js +2 -2
- package/lib/rules/no-const-assign.js +2 -2
- package/lib/rules/no-constant-binary-expression.js +2 -2
- package/lib/rules/no-constant-condition.js +2 -2
- package/lib/rules/no-constructor-return.js +1 -1
- package/lib/rules/no-continue.js +1 -1
- package/lib/rules/no-control-regex.js +16 -3
- package/lib/rules/no-debugger.js +1 -1
- package/lib/rules/no-delete-var.js +1 -1
- package/lib/rules/no-div-regex.js +2 -2
- package/lib/rules/no-dupe-args.js +2 -2
- package/lib/rules/no-dupe-class-members.js +1 -1
- package/lib/rules/no-dupe-else-if.js +2 -2
- package/lib/rules/no-dupe-keys.js +1 -1
- package/lib/rules/no-duplicate-case.js +2 -2
- package/lib/rules/no-duplicate-imports.js +1 -1
- package/lib/rules/no-else-return.js +2 -2
- package/lib/rules/no-empty-character-class.js +34 -13
- package/lib/rules/no-empty-function.js +2 -2
- package/lib/rules/no-empty-pattern.js +39 -4
- package/lib/rules/no-empty-static-block.js +2 -2
- package/lib/rules/no-empty.js +2 -2
- package/lib/rules/no-eq-null.js +1 -1
- package/lib/rules/no-eval.js +2 -2
- package/lib/rules/no-ex-assign.js +2 -2
- package/lib/rules/no-extend-native.js +2 -2
- package/lib/rules/no-extra-bind.js +2 -2
- package/lib/rules/no-extra-boolean-cast.js +2 -2
- package/lib/rules/no-extra-label.js +2 -2
- package/lib/rules/no-extra-parens.js +48 -12
- package/lib/rules/no-extra-semi.js +31 -13
- package/lib/rules/no-fallthrough.js +3 -3
- package/lib/rules/no-floating-decimal.js +2 -2
- package/lib/rules/no-func-assign.js +2 -2
- package/lib/rules/no-global-assign.js +2 -2
- package/lib/rules/no-implicit-coercion.js +2 -2
- package/lib/rules/no-implicit-globals.js +2 -2
- package/lib/rules/no-implied-eval.js +2 -2
- package/lib/rules/no-import-assign.js +2 -2
- package/lib/rules/no-inline-comments.js +2 -2
- package/lib/rules/no-inner-declarations.js +1 -1
- package/lib/rules/no-invalid-regexp.js +23 -8
- package/lib/rules/no-invalid-this.js +2 -2
- package/lib/rules/no-irregular-whitespace.js +23 -6
- package/lib/rules/no-iterator.js +1 -1
- package/lib/rules/no-label-var.js +2 -2
- package/lib/rules/no-labels.js +1 -1
- package/lib/rules/no-lone-blocks.js +2 -2
- package/lib/rules/no-lonely-if.js +2 -2
- package/lib/rules/no-loop-func.js +3 -3
- package/lib/rules/no-loss-of-precision.js +15 -7
- package/lib/rules/no-magic-numbers.js +1 -1
- package/lib/rules/no-misleading-character-class.js +10 -4
- package/lib/rules/no-mixed-operators.js +2 -2
- package/lib/rules/no-mixed-requires.js +1 -1
- package/lib/rules/no-mixed-spaces-and-tabs.js +2 -2
- package/lib/rules/no-multi-assign.js +1 -1
- package/lib/rules/no-multi-spaces.js +2 -2
- package/lib/rules/no-multi-str.js +1 -1
- package/lib/rules/no-multiple-empty-lines.js +2 -2
- package/lib/rules/no-native-reassign.js +2 -2
- package/lib/rules/no-negated-condition.js +1 -1
- package/lib/rules/no-negated-in-lhs.js +1 -1
- package/lib/rules/no-nested-ternary.js +1 -1
- package/lib/rules/no-new-func.js +2 -2
- package/lib/rules/no-new-native-nonconstructor.js +2 -2
- package/lib/rules/no-new-object.js +2 -2
- package/lib/rules/no-new-require.js +1 -1
- package/lib/rules/no-new-symbol.js +2 -2
- package/lib/rules/no-new-wrappers.js +20 -8
- package/lib/rules/no-new.js +1 -1
- package/lib/rules/no-nonoctal-decimal-escape.js +2 -2
- package/lib/rules/no-obj-calls.js +2 -2
- package/lib/rules/no-octal-escape.js +1 -1
- package/lib/rules/no-octal.js +1 -1
- package/lib/rules/no-param-reassign.js +2 -2
- package/lib/rules/no-path-concat.js +1 -1
- package/lib/rules/no-plusplus.js +1 -1
- package/lib/rules/no-process-env.js +1 -1
- package/lib/rules/no-process-exit.js +1 -1
- package/lib/rules/no-promise-executor-return.js +2 -2
- package/lib/rules/no-proto.js +1 -1
- package/lib/rules/no-prototype-builtins.js +1 -1
- package/lib/rules/no-redeclare.js +2 -2
- package/lib/rules/no-regex-spaces.js +20 -5
- package/lib/rules/no-restricted-exports.js +2 -2
- package/lib/rules/no-restricted-globals.js +2 -2
- package/lib/rules/no-restricted-imports.js +2 -2
- package/lib/rules/no-restricted-modules.js +8 -11
- package/lib/rules/no-restricted-properties.js +1 -1
- package/lib/rules/no-restricted-syntax.js +1 -1
- package/lib/rules/no-return-assign.js +2 -2
- package/lib/rules/no-return-await.js +8 -3
- package/lib/rules/no-script-url.js +1 -1
- package/lib/rules/no-self-assign.js +2 -2
- package/lib/rules/no-self-compare.js +2 -2
- package/lib/rules/no-sequences.js +2 -2
- package/lib/rules/no-setter-return.js +2 -2
- package/lib/rules/no-shadow-restricted-names.js +2 -2
- package/lib/rules/no-shadow.js +2 -2
- package/lib/rules/no-spaced-func.js +2 -2
- package/lib/rules/no-sparse-arrays.js +1 -1
- package/lib/rules/no-sync.js +1 -1
- package/lib/rules/no-tabs.js +2 -2
- package/lib/rules/no-template-curly-in-string.js +1 -1
- package/lib/rules/no-ternary.js +1 -1
- package/lib/rules/no-this-before-super.js +1 -1
- package/lib/rules/no-throw-literal.js +1 -1
- package/lib/rules/no-trailing-spaces.js +2 -2
- package/lib/rules/no-undef-init.js +2 -2
- package/lib/rules/no-undef.js +2 -2
- package/lib/rules/no-undefined.js +2 -2
- package/lib/rules/no-underscore-dangle.js +2 -2
- package/lib/rules/no-unexpected-multiline.js +2 -2
- package/lib/rules/no-unmodified-loop-condition.js +2 -2
- package/lib/rules/no-unneeded-ternary.js +2 -2
- package/lib/rules/no-unreachable-loop.js +1 -1
- package/lib/rules/no-unreachable.js +2 -2
- package/lib/rules/no-unsafe-finally.js +1 -1
- package/lib/rules/no-unsafe-negation.js +2 -2
- package/lib/rules/no-unsafe-optional-chaining.js +1 -1
- package/lib/rules/no-unused-expressions.js +4 -6
- package/lib/rules/no-unused-labels.js +48 -15
- package/lib/rules/no-unused-private-class-members.js +1 -1
- package/lib/rules/no-unused-vars.js +4 -3
- package/lib/rules/no-use-before-define.js +2 -2
- package/lib/rules/no-useless-backreference.js +3 -3
- package/lib/rules/no-useless-call.js +2 -2
- package/lib/rules/no-useless-catch.js +1 -1
- package/lib/rules/no-useless-computed-key.js +2 -2
- package/lib/rules/no-useless-concat.js +2 -2
- package/lib/rules/no-useless-constructor.js +1 -1
- package/lib/rules/no-useless-escape.js +162 -83
- package/lib/rules/no-useless-rename.js +2 -2
- package/lib/rules/no-useless-return.js +37 -9
- package/lib/rules/no-var.js +2 -2
- package/lib/rules/no-void.js +1 -1
- package/lib/rules/no-warning-comments.js +2 -2
- package/lib/rules/no-whitespace-before-property.js +2 -2
- package/lib/rules/no-with.js +1 -1
- package/lib/rules/nonblock-statement-body-position.js +2 -2
- package/lib/rules/object-curly-newline.js +2 -2
- package/lib/rules/object-curly-spacing.js +4 -4
- package/lib/rules/object-property-newline.js +2 -2
- package/lib/rules/object-shorthand.js +2 -2
- package/lib/rules/one-var-declaration-per-line.js +1 -1
- package/lib/rules/one-var.js +2 -2
- package/lib/rules/operator-assignment.js +2 -2
- package/lib/rules/operator-linebreak.js +2 -2
- package/lib/rules/padded-blocks.js +2 -2
- package/lib/rules/padding-line-between-statements.js +8 -53
- package/lib/rules/prefer-arrow-callback.js +2 -2
- package/lib/rules/prefer-const.js +2 -2
- package/lib/rules/prefer-destructuring.js +2 -2
- package/lib/rules/prefer-exponentiation-operator.js +4 -3
- package/lib/rules/prefer-named-capture-group.js +10 -7
- package/lib/rules/prefer-numeric-literals.js +2 -2
- package/lib/rules/prefer-object-has-own.js +2 -2
- package/lib/rules/prefer-object-spread.js +2 -2
- package/lib/rules/prefer-promise-reject-errors.js +2 -2
- package/lib/rules/prefer-reflect.js +1 -1
- package/lib/rules/prefer-regex-literals.js +14 -17
- package/lib/rules/prefer-rest-params.js +2 -2
- package/lib/rules/prefer-spread.js +2 -2
- package/lib/rules/prefer-template.js +2 -2
- package/lib/rules/quote-props.js +2 -2
- package/lib/rules/quotes.js +16 -16
- package/lib/rules/radix.js +2 -2
- package/lib/rules/require-atomic-updates.js +2 -2
- package/lib/rules/require-await.js +2 -2
- package/lib/rules/require-jsdoc.js +2 -2
- package/lib/rules/require-unicode-regexp.js +5 -5
- package/lib/rules/require-yield.js +1 -1
- package/lib/rules/rest-spread-spacing.js +2 -2
- package/lib/rules/semi-spacing.js +2 -2
- package/lib/rules/semi-style.js +2 -2
- package/lib/rules/semi.js +30 -5
- package/lib/rules/sort-imports.js +2 -2
- package/lib/rules/sort-keys.js +2 -2
- package/lib/rules/sort-vars.js +2 -2
- package/lib/rules/space-before-blocks.js +2 -2
- package/lib/rules/space-before-function-paren.js +2 -2
- package/lib/rules/space-in-parens.js +2 -2
- package/lib/rules/space-infix-ops.js +2 -2
- package/lib/rules/space-unary-ops.js +2 -2
- package/lib/rules/spaced-comment.js +2 -2
- package/lib/rules/strict.js +1 -1
- package/lib/rules/switch-colon-spacing.js +2 -2
- package/lib/rules/symbol-description.js +2 -2
- package/lib/rules/template-curly-spacing.js +2 -2
- package/lib/rules/template-tag-spacing.js +2 -2
- package/lib/rules/unicode-bom.js +2 -2
- package/lib/rules/use-isnan.js +1 -1
- package/lib/rules/utils/ast-utils.js +55 -7
- package/lib/rules/utils/regular-expressions.js +2 -2
- package/lib/rules/valid-jsdoc.js +2 -2
- package/lib/rules/valid-typeof.js +9 -3
- package/lib/rules/vars-on-top.js +1 -1
- package/lib/rules/wrap-iife.js +2 -2
- package/lib/rules/wrap-regex.js +2 -2
- package/lib/rules/yield-star-spacing.js +2 -2
- package/lib/rules/yoda.js +4 -13
- package/lib/shared/string-utils.js +39 -1
- package/lib/shared/types.js +7 -3
- package/lib/unsupported-api.js +5 -2
- package/messages/eslintrc-incompat.js +98 -0
- package/messages/eslintrc-plugins.js +24 -0
- package/messages/invalid-rule-options.js +17 -0
- package/messages/invalid-rule-severity.js +13 -0
- package/messages/shared.js +18 -0
- package/package.json +15 -19
package/README.md
CHANGED
@@ -16,7 +16,8 @@
|
|
16
16
|
[Report Bugs](https://eslint.org/docs/latest/contribute/report-bugs) |
|
17
17
|
[Code of Conduct](https://eslint.org/conduct) |
|
18
18
|
[Twitter](https://twitter.com/geteslint) |
|
19
|
-
[Discord](https://eslint.org/chat)
|
19
|
+
[Discord](https://eslint.org/chat) |
|
20
|
+
[Mastodon](https://fosstodon.org/@eslint)
|
20
21
|
|
21
22
|
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
23
|
|
@@ -116,7 +117,7 @@ Yes, ESLint natively supports parsing JSX syntax (this must be enabled in [confi
|
|
116
117
|
|
117
118
|
### What ECMAScript versions does ESLint support?
|
118
119
|
|
119
|
-
ESLint has full support for ECMAScript 3, 5 (default), 2015, 2016, 2017, 2018, 2019, 2020, 2021 and
|
120
|
+
ESLint has full support for ECMAScript 3, 5 (default), 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, and 2023. You can set your desired ECMAScript syntax (and other settings, like global variables or your target environments) through [configuration](https://eslint.org/docs/latest/use/configure).
|
120
121
|
|
121
122
|
### What about experimental features?
|
122
123
|
|
@@ -248,6 +249,11 @@ Bryan Mishkin
|
|
248
249
|
<img src="https://github.com/fasttime.png?s=75" width="75" height="75"><br />
|
249
250
|
Francesco Trotta
|
250
251
|
</a>
|
252
|
+
</td><td align="center" valign="top" width="11%">
|
253
|
+
<a href="https://github.com/ota-meshi">
|
254
|
+
<img src="https://github.com/ota-meshi.png?s=75" width="75" height="75"><br />
|
255
|
+
Yosuke Ota
|
256
|
+
</a>
|
251
257
|
</td></tr></tbody></table>
|
252
258
|
|
253
259
|
### Website Team
|
@@ -281,9 +287,9 @@ The following companies, organizations, and individuals support ESLint's ongoing
|
|
281
287
|
<!--sponsorsstart-->
|
282
288
|
<h3>Platinum Sponsors</h3>
|
283
289
|
<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>
|
284
|
-
<p><a href="https://
|
290
|
+
<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>
|
285
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>
|
286
|
-
<p><a href="https://
|
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>
|
287
293
|
<!--sponsorsend-->
|
288
294
|
|
289
295
|
## Technology Sponsors
|
package/conf/globals.js
CHANGED
@@ -128,6 +128,10 @@ const es2023 = {
|
|
128
128
|
...es2022
|
129
129
|
};
|
130
130
|
|
131
|
+
const es2024 = {
|
132
|
+
...es2023
|
133
|
+
};
|
134
|
+
|
131
135
|
|
132
136
|
//-----------------------------------------------------------------------------
|
133
137
|
// Exports
|
@@ -145,5 +149,6 @@ module.exports = {
|
|
145
149
|
es2020,
|
146
150
|
es2021,
|
147
151
|
es2022,
|
148
|
-
es2023
|
152
|
+
es2023,
|
153
|
+
es2024
|
149
154
|
};
|
@@ -158,7 +158,17 @@ function validateFixTypes(fixTypes) {
|
|
158
158
|
* @private
|
159
159
|
*/
|
160
160
|
function calculateStatsPerFile(messages) {
|
161
|
-
|
161
|
+
const stat = {
|
162
|
+
errorCount: 0,
|
163
|
+
fatalErrorCount: 0,
|
164
|
+
warningCount: 0,
|
165
|
+
fixableErrorCount: 0,
|
166
|
+
fixableWarningCount: 0
|
167
|
+
};
|
168
|
+
|
169
|
+
for (let i = 0; i < messages.length; i++) {
|
170
|
+
const message = messages[i];
|
171
|
+
|
162
172
|
if (message.fatal || message.severity === 2) {
|
163
173
|
stat.errorCount++;
|
164
174
|
if (message.fatal) {
|
@@ -173,14 +183,8 @@ function calculateStatsPerFile(messages) {
|
|
173
183
|
stat.fixableWarningCount++;
|
174
184
|
}
|
175
185
|
}
|
176
|
-
|
177
|
-
|
178
|
-
errorCount: 0,
|
179
|
-
fatalErrorCount: 0,
|
180
|
-
warningCount: 0,
|
181
|
-
fixableErrorCount: 0,
|
182
|
-
fixableWarningCount: 0
|
183
|
-
});
|
186
|
+
}
|
187
|
+
return stat;
|
184
188
|
}
|
185
189
|
|
186
190
|
/**
|
@@ -190,20 +194,25 @@ function calculateStatsPerFile(messages) {
|
|
190
194
|
* @private
|
191
195
|
*/
|
192
196
|
function calculateStatsPerRun(results) {
|
193
|
-
|
194
|
-
stat.errorCount += result.errorCount;
|
195
|
-
stat.fatalErrorCount += result.fatalErrorCount;
|
196
|
-
stat.warningCount += result.warningCount;
|
197
|
-
stat.fixableErrorCount += result.fixableErrorCount;
|
198
|
-
stat.fixableWarningCount += result.fixableWarningCount;
|
199
|
-
return stat;
|
200
|
-
}, {
|
197
|
+
const stat = {
|
201
198
|
errorCount: 0,
|
202
199
|
fatalErrorCount: 0,
|
203
200
|
warningCount: 0,
|
204
201
|
fixableErrorCount: 0,
|
205
202
|
fixableWarningCount: 0
|
206
|
-
}
|
203
|
+
};
|
204
|
+
|
205
|
+
for (let i = 0; i < results.length; i++) {
|
206
|
+
const result = results[i];
|
207
|
+
|
208
|
+
stat.errorCount += result.errorCount;
|
209
|
+
stat.fatalErrorCount += result.fatalErrorCount;
|
210
|
+
stat.warningCount += result.warningCount;
|
211
|
+
stat.fixableErrorCount += result.fixableErrorCount;
|
212
|
+
stat.fixableWarningCount += result.fixableWarningCount;
|
213
|
+
}
|
214
|
+
|
215
|
+
return stat;
|
207
216
|
}
|
208
217
|
|
209
218
|
/**
|
@@ -308,9 +317,11 @@ function createIgnoreResult(filePath, baseDir) {
|
|
308
317
|
filePath: path.resolve(filePath),
|
309
318
|
messages: [
|
310
319
|
{
|
320
|
+
ruleId: null,
|
311
321
|
fatal: false,
|
312
322
|
severity: 1,
|
313
|
-
message
|
323
|
+
message,
|
324
|
+
nodeType: null
|
314
325
|
}
|
315
326
|
],
|
316
327
|
suppressedMessages: [],
|
package/lib/cli.js
CHANGED
@@ -19,12 +19,11 @@ const fs = require("fs"),
|
|
19
19
|
path = require("path"),
|
20
20
|
{ promisify } = require("util"),
|
21
21
|
{ ESLint } = require("./eslint"),
|
22
|
-
{ FlatESLint } = require("./eslint/flat-eslint"),
|
22
|
+
{ FlatESLint, shouldUseFlatConfig } = require("./eslint/flat-eslint"),
|
23
23
|
createCLIOptions = require("./options"),
|
24
24
|
log = require("./shared/logging"),
|
25
25
|
RuntimeInfo = require("./shared/runtime-info");
|
26
26
|
const { Legacy: { naming } } = require("@eslint/eslintrc");
|
27
|
-
const { findFlatConfigFile } = require("./eslint/flat-eslint");
|
28
27
|
const { ModuleImporter } = require("@humanwhocodes/module-importer");
|
29
28
|
|
30
29
|
const debug = require("debug")("eslint:cli");
|
@@ -275,31 +274,6 @@ async function printResults(engine, results, format, outputFile, resultsMeta) {
|
|
275
274
|
return true;
|
276
275
|
}
|
277
276
|
|
278
|
-
/**
|
279
|
-
* Returns whether flat config should be used.
|
280
|
-
* @param {boolean} [allowFlatConfig] Whether or not to allow flat config.
|
281
|
-
* @returns {Promise<boolean>} Where flat config should be used.
|
282
|
-
*/
|
283
|
-
async function shouldUseFlatConfig(allowFlatConfig) {
|
284
|
-
if (!allowFlatConfig) {
|
285
|
-
return false;
|
286
|
-
}
|
287
|
-
|
288
|
-
switch (process.env.ESLINT_USE_FLAT_CONFIG) {
|
289
|
-
case "true":
|
290
|
-
return true;
|
291
|
-
case "false":
|
292
|
-
return false;
|
293
|
-
default:
|
294
|
-
|
295
|
-
/*
|
296
|
-
* If neither explicitly enabled nor disabled, then use the presence
|
297
|
-
* of a flat config file to determine enablement.
|
298
|
-
*/
|
299
|
-
return !!(await findFlatConfigFile(process.cwd()));
|
300
|
-
}
|
301
|
-
}
|
302
|
-
|
303
277
|
//------------------------------------------------------------------------------
|
304
278
|
// Public Interface
|
305
279
|
//------------------------------------------------------------------------------
|
@@ -329,7 +303,7 @@ const cli = {
|
|
329
303
|
* switch to flat config we can remove this logic.
|
330
304
|
*/
|
331
305
|
|
332
|
-
const usingFlatConfig = await shouldUseFlatConfig(
|
306
|
+
const usingFlatConfig = allowFlatConfig && await shouldUseFlatConfig();
|
333
307
|
|
334
308
|
debug("Using flat config?", usingFlatConfig);
|
335
309
|
|
@@ -126,32 +126,65 @@ function normalizeRuleOptions(ruleOptions) {
|
|
126
126
|
// Assertions
|
127
127
|
//-----------------------------------------------------------------------------
|
128
128
|
|
129
|
+
/**
|
130
|
+
* The error type when a rule's options are configured with an invalid type.
|
131
|
+
*/
|
132
|
+
class InvalidRuleOptionsError extends Error {
|
133
|
+
|
134
|
+
/**
|
135
|
+
* @param {string} ruleId Rule name being configured.
|
136
|
+
* @param {any} value The invalid value.
|
137
|
+
*/
|
138
|
+
constructor(ruleId, value) {
|
139
|
+
super(`Key "${ruleId}": Expected severity of "off", 0, "warn", 1, "error", or 2.`);
|
140
|
+
this.messageTemplate = "invalid-rule-options";
|
141
|
+
this.messageData = { ruleId, value };
|
142
|
+
}
|
143
|
+
}
|
144
|
+
|
129
145
|
/**
|
130
146
|
* Validates that a value is a valid rule options entry.
|
147
|
+
* @param {string} ruleId Rule name being configured.
|
131
148
|
* @param {any} value The value to check.
|
132
149
|
* @returns {void}
|
133
|
-
* @throws {
|
150
|
+
* @throws {InvalidRuleOptionsError} If the value isn't a valid rule options.
|
134
151
|
*/
|
135
|
-
function assertIsRuleOptions(value) {
|
136
|
-
|
152
|
+
function assertIsRuleOptions(ruleId, value) {
|
137
153
|
if (typeof value !== "string" && typeof value !== "number" && !Array.isArray(value)) {
|
138
|
-
throw new
|
154
|
+
throw new InvalidRuleOptionsError(ruleId, value);
|
155
|
+
}
|
156
|
+
}
|
157
|
+
|
158
|
+
/**
|
159
|
+
* The error type when a rule's severity is invalid.
|
160
|
+
*/
|
161
|
+
class InvalidRuleSeverityError extends Error {
|
162
|
+
|
163
|
+
/**
|
164
|
+
* @param {string} ruleId Rule name being configured.
|
165
|
+
* @param {any} value The invalid value.
|
166
|
+
*/
|
167
|
+
constructor(ruleId, value) {
|
168
|
+
super(`Key "${ruleId}": Expected severity of "off", 0, "warn", 1, "error", or 2.`);
|
169
|
+
this.messageTemplate = "invalid-rule-severity";
|
170
|
+
this.messageData = { ruleId, value };
|
139
171
|
}
|
140
172
|
}
|
141
173
|
|
142
174
|
/**
|
143
175
|
* Validates that a value is valid rule severity.
|
176
|
+
* @param {string} ruleId Rule name being configured.
|
144
177
|
* @param {any} value The value to check.
|
145
178
|
* @returns {void}
|
146
|
-
* @throws {
|
179
|
+
* @throws {InvalidRuleSeverityError} If the value isn't a valid rule severity.
|
147
180
|
*/
|
148
|
-
function assertIsRuleSeverity(value) {
|
181
|
+
function assertIsRuleSeverity(ruleId, value) {
|
149
182
|
const severity = typeof value === "string"
|
150
183
|
? ruleSeverities.get(value.toLowerCase())
|
151
184
|
: ruleSeverities.get(value);
|
152
185
|
|
153
186
|
if (typeof severity === "undefined") {
|
154
|
-
throw new
|
187
|
+
throw new InvalidRuleSeverityError(ruleId, value);
|
155
188
|
}
|
156
189
|
}
|
157
190
|
|
@@ -179,6 +212,38 @@ function assertIsObject(value) {
|
|
179
212
|
}
|
180
213
|
}
|
181
214
|
|
215
|
+
/**
|
216
|
+
* The error type when there's an eslintrc-style options in a flat config.
|
217
|
+
*/
|
218
|
+
class IncompatibleKeyError extends Error {
|
219
|
+
|
220
|
+
/**
|
221
|
+
* @param {string} key The invalid key.
|
222
|
+
*/
|
223
|
+
constructor(key) {
|
224
|
+
super("This appears to be in eslintrc format rather than flat config format.");
|
225
|
+
this.messageTemplate = "eslintrc-incompat";
|
226
|
+
this.messageData = { key };
|
227
|
+
}
|
228
|
+
}
|
229
|
+
|
230
|
+
/**
|
231
|
+
* The error type when there's an eslintrc-style plugins array found.
|
232
|
+
*/
|
233
|
+
class IncompatiblePluginsError extends Error {
|
234
|
+
|
235
|
+
/**
|
236
|
+
* Creates a new instance.
|
237
|
+
* @param {Array<string>} plugins The plugins array.
|
238
|
+
*/
|
239
|
+
constructor(plugins) {
|
240
|
+
super("This appears to be in eslintrc format (array of strings) rather than flat config format (object).");
|
241
|
+
this.messageTemplate = "eslintrc-plugins";
|
242
|
+
this.messageData = { plugins };
|
243
|
+
}
|
244
|
+
}
|
245
|
+
|
246
|
+
|
182
247
|
//-----------------------------------------------------------------------------
|
183
248
|
// Low-Level Schemas
|
184
249
|
//-----------------------------------------------------------------------------
|
@@ -270,6 +335,11 @@ const pluginsSchema = {
|
|
270
335
|
throw new TypeError("Expected an object.");
|
271
336
|
}
|
272
337
|
|
338
|
+
// make sure it's not an array, which would mean eslintrc-style is used
|
339
|
+
if (Array.isArray(value)) {
|
340
|
+
throw new IncompatiblePluginsError(value);
|
341
|
+
}
|
342
|
+
|
273
343
|
// second check the keys to make sure they are objects
|
274
344
|
for (const key of Object.keys(value)) {
|
275
345
|
|
@@ -357,39 +427,28 @@ const rulesSchema = {
|
|
357
427
|
validate(value) {
|
358
428
|
assertIsObject(value);
|
359
429
|
|
360
|
-
|
430
|
+
/*
|
431
|
+
* We are not checking the rule schema here because there is no
|
432
|
+
* guarantee that the rule definition is present at this point. Instead
|
433
|
+
* we wait and check the rule schema during the finalization step
|
434
|
+
* of calculating a config.
|
435
|
+
*/
|
436
|
+
for (const ruleId of Object.keys(value)) {
|
361
437
|
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
* We are not checking the rule schema here because there is no
|
367
|
-
* guarantee that the rule definition is present at this point. Instead
|
368
|
-
* we wait and check the rule schema during the finalization step
|
369
|
-
* of calculating a config.
|
370
|
-
*/
|
371
|
-
for (const ruleId of Object.keys(value)) {
|
372
|
-
|
373
|
-
// avoid hairy edge case
|
374
|
-
if (ruleId === "__proto__") {
|
375
|
-
continue;
|
376
|
-
}
|
377
|
-
|
378
|
-
lastRuleId = ruleId;
|
438
|
+
// avoid hairy edge case
|
439
|
+
if (ruleId === "__proto__") {
|
440
|
+
continue;
|
441
|
+
}
|
379
442
|
|
380
|
-
|
443
|
+
const ruleOptions = value[ruleId];
|
381
444
|
|
382
|
-
|
445
|
+
assertIsRuleOptions(ruleId, ruleOptions);
|
383
446
|
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
}
|
447
|
+
if (Array.isArray(ruleOptions)) {
|
448
|
+
assertIsRuleSeverity(ruleId, ruleOptions[0]);
|
449
|
+
} else {
|
450
|
+
assertIsRuleSeverity(ruleId, ruleOptions);
|
389
451
|
}
|
390
|
-
} catch (error) {
|
391
|
-
error.message = `Key "${lastRuleId}": ${error.message}`;
|
392
|
-
throw error;
|
393
452
|
}
|
394
453
|
}
|
395
454
|
};
|
@@ -416,11 +475,44 @@ const sourceTypeSchema = {
|
|
416
475
|
}
|
417
476
|
};
|
418
477
|
|
478
|
+
/**
|
479
|
+
* Creates a schema that always throws an error. Useful for warning
|
480
|
+
* about eslintrc-style keys.
|
481
|
+
* @param {string} key The eslintrc key to create a schema for.
|
482
|
+
* @returns {ObjectPropertySchema} The schema.
|
483
|
+
*/
|
484
|
+
function createEslintrcErrorSchema(key) {
|
485
|
+
return {
|
486
|
+
merge: "replace",
|
487
|
+
validate() {
|
488
|
+
throw new IncompatibleKeyError(key);
|
489
|
+
}
|
490
|
+
};
|
491
|
+
}
|
492
|
+
|
493
|
+
const eslintrcKeys = [
|
494
|
+
"env",
|
495
|
+
"extends",
|
496
|
+
"globals",
|
497
|
+
"ignorePatterns",
|
498
|
+
"noInlineConfig",
|
499
|
+
"overrides",
|
500
|
+
"parser",
|
501
|
+
"parserOptions",
|
502
|
+
"reportUnusedDisableDirectives",
|
503
|
+
"root"
|
504
|
+
];
|
505
|
+
|
419
506
|
//-----------------------------------------------------------------------------
|
420
507
|
// Full schema
|
421
508
|
//-----------------------------------------------------------------------------
|
422
509
|
|
423
510
|
exports.flatConfigSchema = {
|
511
|
+
|
512
|
+
// eslintrc-style keys that should always error
|
513
|
+
...Object.fromEntries(eslintrcKeys.map(key => [key, createEslintrcErrorSchema(key)])),
|
514
|
+
|
515
|
+
// flat config keys
|
424
516
|
settings: deepObjectAssignSchema,
|
425
517
|
linterOptions: {
|
426
518
|
schema: {
|
@@ -591,14 +591,10 @@ function isErrorMessage(message) {
|
|
591
591
|
*/
|
592
592
|
function createIgnoreResult(filePath, baseDir) {
|
593
593
|
let message;
|
594
|
-
const
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
if (isHidden) {
|
599
|
-
message = "File ignored by default. Use a negated ignore pattern (like \"--ignore-pattern '!<relative/path/to/filename>'\") to override.";
|
600
|
-
} else if (isInNodeModules) {
|
601
|
-
message = "File ignored by default. Use \"--ignore-pattern '!node_modules/*'\" to override.";
|
594
|
+
const isInNodeModules = baseDir && path.dirname(path.relative(baseDir, filePath)).split(path.sep).includes("node_modules");
|
595
|
+
|
596
|
+
if (isInNodeModules) {
|
597
|
+
message = "File ignored by default because it is located under the node_modules directory. Use ignore pattern \"!**/node_modules/\" to override.";
|
602
598
|
} else {
|
603
599
|
message = "File ignored because of a matching ignore pattern. Use \"--no-ignore\" to override.";
|
604
600
|
}
|
@@ -607,9 +603,11 @@ function createIgnoreResult(filePath, baseDir) {
|
|
607
603
|
filePath: path.resolve(filePath),
|
608
604
|
messages: [
|
609
605
|
{
|
606
|
+
ruleId: null,
|
610
607
|
fatal: false,
|
611
608
|
severity: 1,
|
612
|
-
message
|
609
|
+
message,
|
610
|
+
nodeType: null
|
613
611
|
}
|
614
612
|
],
|
615
613
|
suppressedMessages: [],
|
@@ -758,6 +756,9 @@ function processOptions({
|
|
758
756
|
if (typeof ignore !== "boolean") {
|
759
757
|
errors.push("'ignore' must be a boolean.");
|
760
758
|
}
|
759
|
+
if (!isArrayOfNonEmptyString(ignorePatterns) && ignorePatterns !== null) {
|
760
|
+
errors.push("'ignorePatterns' must be an array of non-empty strings or null.");
|
761
|
+
}
|
761
762
|
if (typeof overrideConfig !== "object") {
|
762
763
|
errors.push("'overrideConfig' must be an object or null.");
|
763
764
|
}
|
@@ -794,7 +795,7 @@ function processOptions({
|
|
794
795
|
// when overrideConfigFile is true that means don't do config file lookup
|
795
796
|
configFile: overrideConfigFile === true ? false : overrideConfigFile,
|
796
797
|
overrideConfig,
|
797
|
-
cwd,
|
798
|
+
cwd: path.normalize(cwd),
|
798
799
|
errorOnUnmatchedPattern,
|
799
800
|
fix,
|
800
801
|
fixTypes,
|