eslint 8.39.0 → 8.41.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 +4 -3
- package/lib/cli-engine/cli-engine.js +3 -1
- package/lib/cli.js +2 -28
- package/lib/config/default-config.js +1 -1
- package/lib/config/flat-config-schema.js +57 -35
- package/lib/eslint/eslint-helpers.js +8 -7
- package/lib/eslint/flat-eslint.js +101 -46
- package/lib/linter/apply-disable-directives.js +11 -1
- package/lib/linter/config-comment-parser.js +9 -2
- package/lib/linter/linter.js +20 -11
- package/lib/linter/report-translator.js +4 -19
- package/lib/rules/accessor-pairs.js +2 -2
- 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 +2 -2
- 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 +2 -2
- 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 +2 -2
- 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 +2 -2
- 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 +40 -56
- 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 +2 -2
- package/lib/rules/max-classes-per-file.js +1 -1
- package/lib/rules/max-depth.js +1 -1
- package/lib/rules/max-len.js +2 -2
- 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 -2
- 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 +1 -1
- 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 +1 -1
- package/lib/rules/no-empty-function.js +2 -2
- package/lib/rules/no-empty-pattern.js +1 -1
- 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 +2 -2
- package/lib/rules/no-extra-semi.js +3 -3
- 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 +1 -1
- package/lib/rules/no-invalid-this.js +2 -2
- package/lib/rules/no-irregular-whitespace.js +2 -2
- 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 +2 -2
- package/lib/rules/no-loss-of-precision.js +1 -1
- package/lib/rules/no-magic-numbers.js +1 -1
- package/lib/rules/no-misleading-character-class.js +2 -2
- 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 +1 -1
- 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 +2 -2
- 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 +1 -1
- 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 +3 -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 +1 -1
- package/lib/rules/no-unused-labels.js +2 -2
- package/lib/rules/no-unused-private-class-members.js +1 -1
- package/lib/rules/no-unused-vars.js +2 -2
- package/lib/rules/no-use-before-define.js +2 -2
- package/lib/rules/no-useless-backreference.js +2 -2
- 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 +2 -2
- package/lib/rules/no-useless-rename.js +2 -2
- package/lib/rules/no-useless-return.js +2 -2
- 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 +4 -4
- 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 +2 -2
- package/lib/rules/prefer-named-capture-group.js +2 -2
- 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 +2 -2
- 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 +2 -2
- 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 +2 -2
- 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/valid-jsdoc.js +2 -2
- package/lib/rules/valid-typeof.js +2 -2
- 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 +2 -2
- package/lib/shared/string-utils.js +39 -1
- package/lib/shared/types.js +6 -2
- package/lib/unsupported-api.js +2 -1
- 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 +6 -7
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
|
|
@@ -281,9 +282,9 @@ The following companies, organizations, and individuals support ESLint's ongoing
|
|
281
282
|
<!--sponsorsstart-->
|
282
283
|
<h3>Platinum Sponsors</h3>
|
283
284
|
<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://
|
285
|
+
<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
286
|
<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://
|
287
|
+
<p><a href="https://www.vedonlyontibonukset.com/pitkavetovihjeet"><img src="https://images.opencollective.com/pitkavetovihjeet/0131f1d/logo.png" alt="Ilmaiset Pitkävetovihjeet" height="32"></a> <a href="https://paydaysay.com/"><img src="https://images.opencollective.com/payday-say-organization/9cd2467/logo.png" alt="PayDay Say" height="32"></a> <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://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
288
|
<!--sponsorsend-->
|
288
289
|
|
289
290
|
## Technology Sponsors
|
@@ -308,9 +308,11 @@ function createIgnoreResult(filePath, baseDir) {
|
|
308
308
|
filePath: path.resolve(filePath),
|
309
309
|
messages: [
|
310
310
|
{
|
311
|
+
ruleId: null,
|
311
312
|
fatal: false,
|
312
313
|
severity: 1,
|
313
|
-
message
|
314
|
+
message,
|
315
|
+
nodeType: null
|
314
316
|
}
|
315
317
|
],
|
316
318
|
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
|
|
@@ -357,39 +390,28 @@ const rulesSchema = {
|
|
357
390
|
validate(value) {
|
358
391
|
assertIsObject(value);
|
359
392
|
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
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
|
-
}
|
393
|
+
/*
|
394
|
+
* We are not checking the rule schema here because there is no
|
395
|
+
* guarantee that the rule definition is present at this point. Instead
|
396
|
+
* we wait and check the rule schema during the finalization step
|
397
|
+
* of calculating a config.
|
398
|
+
*/
|
399
|
+
for (const ruleId of Object.keys(value)) {
|
377
400
|
|
378
|
-
|
401
|
+
// avoid hairy edge case
|
402
|
+
if (ruleId === "__proto__") {
|
403
|
+
continue;
|
404
|
+
}
|
379
405
|
|
380
|
-
|
406
|
+
const ruleOptions = value[ruleId];
|
381
407
|
|
382
|
-
|
408
|
+
assertIsRuleOptions(ruleId, ruleOptions);
|
383
409
|
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
}
|
410
|
+
if (Array.isArray(ruleOptions)) {
|
411
|
+
assertIsRuleSeverity(ruleId, ruleOptions[0]);
|
412
|
+
} else {
|
413
|
+
assertIsRuleSeverity(ruleId, ruleOptions);
|
389
414
|
}
|
390
|
-
} catch (error) {
|
391
|
-
error.message = `Key "${lastRuleId}": ${error.message}`;
|
392
|
-
throw error;
|
393
415
|
}
|
394
416
|
}
|
395
417
|
};
|
@@ -591,14 +591,10 @@ function isErrorMessage(message) {
|
|
591
591
|
*/
|
592
592
|
function createIgnoreResult(filePath, baseDir) {
|
593
593
|
let message;
|
594
|
-
const isHidden = filePath.split(path.sep)
|
595
|
-
.find(segment => /^\./u.test(segment));
|
596
594
|
const isInNodeModules = baseDir && path.relative(baseDir, filePath).startsWith("node_modules");
|
597
595
|
|
598
|
-
if (
|
599
|
-
message = "File ignored by default
|
600
|
-
} else if (isInNodeModules) {
|
601
|
-
message = "File ignored by default. Use \"--ignore-pattern '!node_modules/*'\" to override.";
|
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
|
}
|
@@ -55,6 +55,7 @@ const LintResultCache = require("../cli-engine/lint-result-cache");
|
|
55
55
|
/** @typedef {import("../shared/types").ConfigData} ConfigData */
|
56
56
|
/** @typedef {import("../shared/types").DeprecatedRuleInfo} DeprecatedRuleInfo */
|
57
57
|
/** @typedef {import("../shared/types").LintMessage} LintMessage */
|
58
|
+
/** @typedef {import("../shared/types").LintResult} LintResult */
|
58
59
|
/** @typedef {import("../shared/types").ParserOptions} ParserOptions */
|
59
60
|
/** @typedef {import("../shared/types").Plugin} Plugin */
|
60
61
|
/** @typedef {import("../shared/types").ResultsMeta} ResultsMeta */
|
@@ -76,7 +77,7 @@ const LintResultCache = require("../cli-engine/lint-result-cache");
|
|
76
77
|
* @property {string[]} [fixTypes] Array of rule types to apply fixes for.
|
77
78
|
* @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.
|
78
79
|
* @property {boolean} [ignore] False disables all ignore patterns except for the default ones.
|
79
|
-
* @property {string[]} [ignorePatterns] Ignore file patterns to use in addition to config ignores.
|
80
|
+
* @property {string[]} [ignorePatterns] Ignore file patterns to use in addition to config ignores. These patterns are relative to `cwd`.
|
80
81
|
* @property {ConfigData} [overrideConfig] Override config object, overrides all configs used with this instance
|
81
82
|
* @property {boolean|string} [overrideConfigFile] Searches for default config file when falsy;
|
82
83
|
* doesn't do any config file lookup when `true`; considered to be a config filename
|
@@ -261,7 +262,7 @@ function compareResultsByFilePath(a, b) {
|
|
261
262
|
* Searches from the current working directory up until finding the
|
262
263
|
* given flat config filename.
|
263
264
|
* @param {string} cwd The current working directory to search from.
|
264
|
-
* @returns {Promise<string|
|
265
|
+
* @returns {Promise<string|undefined>} The filename if found or `undefined` if not.
|
265
266
|
*/
|
266
267
|
function findFlatConfigFile(cwd) {
|
267
268
|
return findUp(
|
@@ -320,6 +321,45 @@ async function loadFlatConfigFile(filePath) {
|
|
320
321
|
return config;
|
321
322
|
}
|
322
323
|
|
324
|
+
/**
|
325
|
+
* Determines which config file to use. This is determined by seeing if an
|
326
|
+
* override config file was passed, and if so, using it; otherwise, as long
|
327
|
+
* as override config file is not explicitly set to `false`, it will search
|
328
|
+
* upwards from the cwd for a file named `eslint.config.js`.
|
329
|
+
* @param {import("./eslint").ESLintOptions} options The ESLint instance options.
|
330
|
+
* @returns {{configFilePath:string|undefined,basePath:string,error:Error|null}} Location information for
|
331
|
+
* the config file.
|
332
|
+
*/
|
333
|
+
async function locateConfigFileToUse({ configFile, cwd }) {
|
334
|
+
|
335
|
+
// determine where to load config file from
|
336
|
+
let configFilePath;
|
337
|
+
let basePath = cwd;
|
338
|
+
let error = null;
|
339
|
+
|
340
|
+
if (typeof configFile === "string") {
|
341
|
+
debug(`Override config file path is ${configFile}`);
|
342
|
+
configFilePath = path.resolve(cwd, configFile);
|
343
|
+
} else if (configFile !== false) {
|
344
|
+
debug("Searching for eslint.config.js");
|
345
|
+
configFilePath = await findFlatConfigFile(cwd);
|
346
|
+
|
347
|
+
if (configFilePath) {
|
348
|
+
basePath = path.resolve(path.dirname(configFilePath));
|
349
|
+
} else {
|
350
|
+
error = new Error("Could not find config file.");
|
351
|
+
}
|
352
|
+
|
353
|
+
}
|
354
|
+
|
355
|
+
return {
|
356
|
+
configFilePath,
|
357
|
+
basePath,
|
358
|
+
error
|
359
|
+
};
|
360
|
+
|
361
|
+
}
|
362
|
+
|
323
363
|
/**
|
324
364
|
* Calculates the config array for this run based on inputs.
|
325
365
|
* @param {FlatESLint} eslint The instance to create the config array for.
|
@@ -342,25 +382,13 @@ async function calculateConfigArray(eslint, {
|
|
342
382
|
return slots.configs;
|
343
383
|
}
|
344
384
|
|
345
|
-
|
346
|
-
let configFilePath;
|
347
|
-
let basePath = cwd;
|
348
|
-
|
349
|
-
if (typeof configFile === "string") {
|
350
|
-
debug(`Override config file path is ${configFile}`);
|
351
|
-
configFilePath = path.resolve(cwd, configFile);
|
352
|
-
} else if (configFile !== false) {
|
353
|
-
debug("Searching for eslint.config.js");
|
354
|
-
configFilePath = await findFlatConfigFile(cwd);
|
355
|
-
|
356
|
-
if (!configFilePath) {
|
357
|
-
throw new Error("Could not find config file.");
|
358
|
-
}
|
385
|
+
const { configFilePath, basePath, error } = await locateConfigFileToUse({ configFile, cwd });
|
359
386
|
|
360
|
-
|
387
|
+
// config file is required to calculate config
|
388
|
+
if (error) {
|
389
|
+
throw error;
|
361
390
|
}
|
362
391
|
|
363
|
-
|
364
392
|
const configs = new FlatConfigArray(baseConfig || [], { basePath, shouldIgnore });
|
365
393
|
|
366
394
|
// load config file
|
@@ -377,45 +405,39 @@ async function calculateConfigArray(eslint, {
|
|
377
405
|
// add in any configured defaults
|
378
406
|
configs.push(...slots.defaultConfigs);
|
379
407
|
|
380
|
-
let allIgnorePatterns = [];
|
381
|
-
|
382
408
|
// append command line ignore patterns
|
383
|
-
if (ignorePatterns) {
|
384
|
-
if (typeof ignorePatterns === "string") {
|
385
|
-
allIgnorePatterns.push(ignorePatterns);
|
386
|
-
} else {
|
387
|
-
allIgnorePatterns.push(...ignorePatterns);
|
388
|
-
}
|
389
|
-
}
|
409
|
+
if (ignorePatterns && ignorePatterns.length > 0) {
|
390
410
|
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
411
|
+
let relativeIgnorePatterns;
|
412
|
+
|
413
|
+
/*
|
414
|
+
* If the config file basePath is different than the cwd, then
|
415
|
+
* the ignore patterns won't work correctly. Here, we adjust the
|
416
|
+
* ignore pattern to include the correct relative path. Patterns
|
417
|
+
* passed as `ignorePatterns` are relative to the cwd, whereas
|
418
|
+
* the config file basePath can be an ancestor of the cwd.
|
419
|
+
*/
|
420
|
+
if (basePath === cwd) {
|
421
|
+
relativeIgnorePatterns = ignorePatterns;
|
422
|
+
} else {
|
399
423
|
|
400
|
-
|
424
|
+
const relativeIgnorePath = path.relative(basePath, cwd);
|
401
425
|
|
402
|
-
|
403
|
-
|
404
|
-
|
426
|
+
relativeIgnorePatterns = ignorePatterns.map(pattern => {
|
427
|
+
const negated = pattern.startsWith("!");
|
428
|
+
const basePattern = negated ? pattern.slice(1) : pattern;
|
405
429
|
|
406
|
-
|
430
|
+
return (negated ? "!" : "") +
|
407
431
|
path.posix.join(relativeIgnorePath, basePattern);
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
if (allIgnorePatterns.length) {
|
432
|
+
});
|
433
|
+
}
|
412
434
|
|
413
435
|
/*
|
414
436
|
* Ignore patterns are added to the end of the config array
|
415
437
|
* so they can override default ignores.
|
416
438
|
*/
|
417
439
|
configs.push({
|
418
|
-
ignores:
|
440
|
+
ignores: relativeIgnorePatterns
|
419
441
|
});
|
420
442
|
}
|
421
443
|
|
@@ -1160,6 +1182,19 @@ class FlatESLint {
|
|
1160
1182
|
return configs.getConfig(absolutePath);
|
1161
1183
|
}
|
1162
1184
|
|
1185
|
+
/**
|
1186
|
+
* Finds the config file being used by this instance based on the options
|
1187
|
+
* passed to the constructor.
|
1188
|
+
* @returns {string|undefined} The path to the config file being used or
|
1189
|
+
* `undefined` if no config file is being used.
|
1190
|
+
*/
|
1191
|
+
async findConfigFile() {
|
1192
|
+
const options = privateMembers.get(this).options;
|
1193
|
+
const { configFilePath } = await locateConfigFileToUse(options);
|
1194
|
+
|
1195
|
+
return configFilePath;
|
1196
|
+
}
|
1197
|
+
|
1163
1198
|
/**
|
1164
1199
|
* Checks if a given path is ignored by ESLint.
|
1165
1200
|
* @param {string} filePath The path of the file to check.
|
@@ -1172,11 +1207,31 @@ class FlatESLint {
|
|
1172
1207
|
}
|
1173
1208
|
}
|
1174
1209
|
|
1210
|
+
/**
|
1211
|
+
* Returns whether flat config should be used.
|
1212
|
+
* @returns {Promise<boolean>} Whether flat config should be used.
|
1213
|
+
*/
|
1214
|
+
async function shouldUseFlatConfig() {
|
1215
|
+
switch (process.env.ESLINT_USE_FLAT_CONFIG) {
|
1216
|
+
case "true":
|
1217
|
+
return true;
|
1218
|
+
case "false":
|
1219
|
+
return false;
|
1220
|
+
default:
|
1221
|
+
|
1222
|
+
/*
|
1223
|
+
* If neither explicitly enabled nor disabled, then use the presence
|
1224
|
+
* of a flat config file to determine enablement.
|
1225
|
+
*/
|
1226
|
+
return !!(await findFlatConfigFile(process.cwd()));
|
1227
|
+
}
|
1228
|
+
}
|
1229
|
+
|
1175
1230
|
//------------------------------------------------------------------------------
|
1176
1231
|
// Public Interface
|
1177
1232
|
//------------------------------------------------------------------------------
|
1178
1233
|
|
1179
1234
|
module.exports = {
|
1180
1235
|
FlatESLint,
|
1181
|
-
|
1236
|
+
shouldUseFlatConfig
|
1182
1237
|
};
|
@@ -5,6 +5,16 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
//------------------------------------------------------------------------------
|
9
|
+
// Typedefs
|
10
|
+
//------------------------------------------------------------------------------
|
11
|
+
|
12
|
+
/** @typedef {import("../shared/types").LintMessage} LintMessage */
|
13
|
+
|
14
|
+
//------------------------------------------------------------------------------
|
15
|
+
// Module Definition
|
16
|
+
//------------------------------------------------------------------------------
|
17
|
+
|
8
18
|
const escapeRegExp = require("escape-string-regexp");
|
9
19
|
|
10
20
|
/**
|
@@ -196,7 +206,7 @@ function processUnusedDisableDirectives(allDirectives) {
|
|
196
206
|
* @param {Object} options options for applying directives. This is the same as the options
|
197
207
|
* for the exported function, except that `reportUnusedDisableDirectives` is not supported
|
198
208
|
* (this function always reports unused disable directives).
|
199
|
-
* @returns {{problems:
|
209
|
+
* @returns {{problems: LintMessage[], unusedDisableDirectives: LintMessage[]}} An object with a list
|
200
210
|
* of problems (including suppressed ones) and unused eslint-disable directives
|
201
211
|
*/
|
202
212
|
function applyDirectives(options) {
|
@@ -19,6 +19,12 @@ const levn = require("levn"),
|
|
19
19
|
|
20
20
|
const debug = require("debug")("eslint:config-comment-parser");
|
21
21
|
|
22
|
+
//------------------------------------------------------------------------------
|
23
|
+
// Typedefs
|
24
|
+
//------------------------------------------------------------------------------
|
25
|
+
|
26
|
+
/** @typedef {import("../shared/types").LintMessage} LintMessage */
|
27
|
+
|
22
28
|
//------------------------------------------------------------------------------
|
23
29
|
// Public Interface
|
24
30
|
//------------------------------------------------------------------------------
|
@@ -61,7 +67,7 @@ module.exports = class ConfigCommentParser {
|
|
61
67
|
* Parses a JSON-like config.
|
62
68
|
* @param {string} string The string to parse.
|
63
69
|
* @param {Object} location Start line and column of comments for potential error message.
|
64
|
-
* @returns {({success: true, config: Object}|{success: false, error:
|
70
|
+
* @returns {({success: true, config: Object}|{success: false, error: LintMessage})} Result map object
|
65
71
|
*/
|
66
72
|
parseJsonConfig(string, location) {
|
67
73
|
debug("Parsing JSON config");
|
@@ -109,7 +115,8 @@ module.exports = class ConfigCommentParser {
|
|
109
115
|
severity: 2,
|
110
116
|
message: `Failed to parse JSON from '${normalizedString}': ${ex.message}`,
|
111
117
|
line: location.start.line,
|
112
|
-
column: location.start.column + 1
|
118
|
+
column: location.start.column + 1,
|
119
|
+
nodeType: null
|
113
120
|
}
|
114
121
|
};
|
115
122
|
|