eslint 8.0.0-beta.0 → 8.0.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 -4
- package/bin/eslint.js +1 -1
- package/conf/eslint-recommended.js +1 -1
- package/conf/{category-list.json → rule-type-list.json} +4 -7
- package/lib/cli-engine/cli-engine.js +11 -3
- package/lib/cli-engine/file-enumerator.js +4 -3
- package/lib/cli-engine/formatters/html.js +1 -1
- package/lib/cli-engine/hash.js +2 -2
- package/lib/cli-engine/xml-escape.js +1 -1
- package/lib/config/flat-config-array.js +2 -2
- package/lib/config/flat-config-schema.js +1 -1
- package/lib/config/rule-validator.js +25 -8
- package/lib/eslint/eslint.js +4 -0
- package/lib/init/autoconfig.js +17 -18
- package/lib/init/config-file.js +3 -3
- package/lib/init/config-initializer.js +11 -10
- package/lib/init/config-rule.js +15 -16
- package/lib/init/npm-utils.js +16 -15
- package/lib/init/source-code-utils.js +6 -5
- package/lib/linter/apply-disable-directives.js +80 -11
- package/lib/linter/code-path-analysis/code-path-analyzer.js +115 -36
- package/lib/linter/code-path-analysis/code-path-segment.js +0 -1
- package/lib/linter/code-path-analysis/code-path-state.js +4 -1
- package/lib/linter/code-path-analysis/code-path.js +14 -5
- package/lib/linter/code-path-analysis/debug-helpers.js +2 -2
- package/lib/linter/code-path-analysis/fork-context.js +0 -1
- package/lib/linter/code-path-analysis/id-generator.js +0 -1
- package/lib/linter/config-comment-parser.js +1 -1
- package/lib/linter/linter.js +51 -22
- package/lib/linter/node-event-generator.js +0 -1
- package/lib/linter/report-translator.js +12 -12
- package/lib/linter/rules.js +3 -0
- package/lib/linter/safe-emitter.js +2 -2
- package/lib/linter/source-code-fixer.js +2 -2
- package/lib/linter/timing.js +2 -2
- package/lib/rule-tester/rule-tester.js +12 -2
- package/lib/rules/accessor-pairs.js +0 -1
- package/lib/rules/array-bracket-newline.js +0 -1
- package/lib/rules/array-bracket-spacing.js +0 -1
- package/lib/rules/array-callback-return.js +0 -1
- package/lib/rules/array-element-newline.js +0 -1
- package/lib/rules/arrow-body-style.js +0 -1
- package/lib/rules/arrow-parens.js +0 -1
- package/lib/rules/arrow-spacing.js +0 -1
- package/lib/rules/block-scoped-var.js +0 -1
- package/lib/rules/block-spacing.js +0 -1
- package/lib/rules/brace-style.js +0 -1
- package/lib/rules/callback-return.js +1 -1
- package/lib/rules/camelcase.js +17 -19
- package/lib/rules/capitalized-comments.js +0 -1
- package/lib/rules/class-methods-use-this.js +51 -9
- package/lib/rules/comma-dangle.js +0 -1
- package/lib/rules/comma-spacing.js +0 -1
- package/lib/rules/comma-style.js +0 -1
- package/lib/rules/complexity.js +47 -56
- package/lib/rules/computed-property-spacing.js +0 -1
- package/lib/rules/consistent-return.js +0 -1
- package/lib/rules/consistent-this.js +1 -2
- package/lib/rules/constructor-super.js +0 -1
- package/lib/rules/curly.js +0 -1
- package/lib/rules/default-case-last.js +0 -1
- package/lib/rules/default-case.js +2 -3
- package/lib/rules/default-param-last.js +1 -2
- package/lib/rules/dot-location.js +0 -1
- package/lib/rules/dot-notation.js +0 -1
- package/lib/rules/eol-last.js +6 -2
- package/lib/rules/eqeqeq.js +1 -2
- package/lib/rules/for-direction.js +0 -1
- package/lib/rules/func-call-spacing.js +0 -1
- package/lib/rules/func-name-matching.js +9 -6
- package/lib/rules/func-names.js +0 -1
- package/lib/rules/func-style.js +0 -1
- package/lib/rules/function-call-argument-newline.js +0 -1
- package/lib/rules/function-paren-newline.js +1 -1
- package/lib/rules/generator-star-spacing.js +0 -1
- package/lib/rules/getter-return.js +0 -1
- package/lib/rules/global-require.js +1 -1
- package/lib/rules/grouped-accessor-pairs.js +0 -1
- package/lib/rules/guard-for-in.js +0 -1
- package/lib/rules/handle-callback-err.js +1 -1
- package/lib/rules/id-blacklist.js +1 -1
- package/lib/rules/id-denylist.js +0 -1
- package/lib/rules/id-length.js +0 -1
- package/lib/rules/id-match.js +0 -1
- package/lib/rules/implicit-arrow-linebreak.js +0 -1
- package/lib/rules/indent-legacy.js +1 -1
- package/lib/rules/indent.js +7 -10
- package/lib/rules/index.js +1 -1
- package/lib/rules/init-declarations.js +0 -1
- package/lib/rules/jsx-quotes.js +0 -1
- package/lib/rules/key-spacing.js +4 -5
- package/lib/rules/keyword-spacing.js +19 -3
- package/lib/rules/line-comment-position.js +0 -1
- package/lib/rules/linebreak-style.js +0 -1
- package/lib/rules/lines-around-comment.js +0 -1
- package/lib/rules/lines-around-directive.js +1 -2
- package/lib/rules/lines-between-class-members.js +50 -3
- package/lib/rules/max-classes-per-file.js +31 -8
- package/lib/rules/max-depth.js +0 -1
- package/lib/rules/max-len.js +1 -2
- package/lib/rules/max-lines-per-function.js +1 -2
- package/lib/rules/max-lines.js +0 -1
- package/lib/rules/max-nested-callbacks.js +0 -1
- package/lib/rules/max-params.js +0 -1
- package/lib/rules/max-statements-per-line.js +0 -1
- package/lib/rules/max-statements.js +0 -1
- package/lib/rules/multiline-comment-style.js +0 -1
- package/lib/rules/multiline-ternary.js +0 -1
- package/lib/rules/new-cap.js +2 -2
- package/lib/rules/new-parens.js +0 -1
- package/lib/rules/newline-after-var.js +4 -5
- package/lib/rules/newline-before-return.js +2 -3
- package/lib/rules/newline-per-chained-call.js +1 -2
- package/lib/rules/no-alert.js +0 -1
- package/lib/rules/no-array-constructor.js +0 -1
- package/lib/rules/no-async-promise-executor.js +0 -1
- package/lib/rules/no-await-in-loop.js +0 -1
- package/lib/rules/no-bitwise.js +5 -6
- package/lib/rules/no-buffer-constructor.js +1 -1
- package/lib/rules/no-caller.js +0 -1
- package/lib/rules/no-case-declarations.js +0 -1
- package/lib/rules/no-catch-shadow.js +0 -1
- package/lib/rules/no-class-assign.js +0 -1
- package/lib/rules/no-compare-neg-zero.js +0 -1
- package/lib/rules/no-cond-assign.js +0 -1
- package/lib/rules/no-confusing-arrow.js +0 -1
- package/lib/rules/no-console.js +0 -1
- package/lib/rules/no-const-assign.js +0 -1
- package/lib/rules/no-constant-condition.js +0 -1
- package/lib/rules/no-constructor-return.js +0 -1
- package/lib/rules/no-continue.js +0 -1
- package/lib/rules/no-control-regex.js +0 -1
- package/lib/rules/no-debugger.js +0 -1
- package/lib/rules/no-delete-var.js +0 -1
- package/lib/rules/no-div-regex.js +0 -1
- package/lib/rules/no-dupe-args.js +0 -1
- package/lib/rules/no-dupe-class-members.js +0 -1
- package/lib/rules/no-dupe-else-if.js +0 -1
- package/lib/rules/no-dupe-keys.js +0 -2
- package/lib/rules/no-duplicate-case.js +0 -1
- package/lib/rules/no-duplicate-imports.js +0 -1
- package/lib/rules/no-else-return.js +0 -1
- package/lib/rules/no-empty-character-class.js +0 -1
- package/lib/rules/no-empty-function.js +0 -1
- package/lib/rules/no-empty-pattern.js +0 -1
- package/lib/rules/no-empty.js +0 -1
- package/lib/rules/no-eq-null.js +0 -1
- package/lib/rules/no-eval.js +0 -1
- package/lib/rules/no-ex-assign.js +0 -1
- package/lib/rules/no-extend-native.js +0 -1
- package/lib/rules/no-extra-bind.js +0 -1
- package/lib/rules/no-extra-boolean-cast.js +1 -1
- package/lib/rules/no-extra-label.js +0 -1
- package/lib/rules/no-extra-parens.js +0 -1
- package/lib/rules/no-extra-semi.js +0 -1
- package/lib/rules/no-fallthrough.js +0 -1
- package/lib/rules/no-floating-decimal.js +0 -1
- package/lib/rules/no-func-assign.js +0 -1
- package/lib/rules/no-global-assign.js +0 -1
- package/lib/rules/no-implicit-coercion.js +0 -1
- package/lib/rules/no-implicit-globals.js +0 -1
- package/lib/rules/no-implied-eval.js +0 -1
- package/lib/rules/no-import-assign.js +0 -1
- package/lib/rules/no-inline-comments.js +0 -1
- package/lib/rules/no-inner-declarations.js +0 -1
- package/lib/rules/no-invalid-regexp.js +0 -1
- package/lib/rules/no-invalid-this.js +0 -1
- package/lib/rules/no-irregular-whitespace.js +0 -1
- package/lib/rules/no-iterator.js +0 -1
- package/lib/rules/no-label-var.js +0 -1
- package/lib/rules/no-labels.js +0 -1
- package/lib/rules/no-lone-blocks.js +0 -1
- package/lib/rules/no-lonely-if.js +0 -1
- package/lib/rules/no-loop-func.js +1 -2
- package/lib/rules/no-loss-of-precision.js +0 -1
- package/lib/rules/no-magic-numbers.js +0 -1
- package/lib/rules/no-misleading-character-class.js +0 -1
- package/lib/rules/no-mixed-operators.js +1 -2
- package/lib/rules/no-mixed-requires.js +1 -1
- package/lib/rules/no-mixed-spaces-and-tabs.js +0 -1
- package/lib/rules/no-multi-assign.js +0 -1
- package/lib/rules/no-multi-spaces.js +0 -1
- package/lib/rules/no-multi-str.js +0 -1
- package/lib/rules/no-multiple-empty-lines.js +0 -1
- package/lib/rules/no-native-reassign.js +0 -1
- package/lib/rules/no-negated-condition.js +0 -1
- package/lib/rules/no-negated-in-lhs.js +0 -1
- package/lib/rules/no-nested-ternary.js +0 -1
- package/lib/rules/no-new-func.js +34 -7
- package/lib/rules/no-new-object.js +0 -1
- package/lib/rules/no-new-require.js +1 -1
- package/lib/rules/no-new-symbol.js +0 -1
- package/lib/rules/no-new-wrappers.js +0 -1
- package/lib/rules/no-new.js +0 -1
- package/lib/rules/no-nonoctal-decimal-escape.js +0 -1
- package/lib/rules/no-obj-calls.js +0 -1
- package/lib/rules/no-octal-escape.js +0 -1
- package/lib/rules/no-octal.js +0 -1
- package/lib/rules/no-param-reassign.js +0 -1
- package/lib/rules/no-path-concat.js +1 -1
- package/lib/rules/no-plusplus.js +0 -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 +0 -1
- package/lib/rules/no-proto.js +0 -1
- package/lib/rules/no-prototype-builtins.js +0 -1
- package/lib/rules/no-redeclare.js +0 -1
- package/lib/rules/no-regex-spaces.js +0 -1
- package/lib/rules/no-restricted-exports.js +0 -1
- package/lib/rules/no-restricted-globals.js +1 -2
- package/lib/rules/no-restricted-imports.js +5 -6
- package/lib/rules/no-restricted-modules.js +3 -3
- package/lib/rules/no-restricted-properties.js +2 -3
- package/lib/rules/no-restricted-syntax.js +1 -2
- package/lib/rules/no-return-assign.js +0 -1
- package/lib/rules/no-return-await.js +0 -1
- package/lib/rules/no-script-url.js +1 -3
- package/lib/rules/no-self-assign.js +0 -1
- package/lib/rules/no-self-compare.js +0 -1
- package/lib/rules/no-sequences.js +0 -1
- package/lib/rules/no-setter-return.js +0 -1
- package/lib/rules/no-shadow-restricted-names.js +0 -1
- package/lib/rules/no-shadow.js +1 -2
- package/lib/rules/no-spaced-func.js +0 -1
- package/lib/rules/no-sparse-arrays.js +0 -1
- package/lib/rules/no-sync.js +1 -3
- package/lib/rules/no-tabs.js +0 -1
- package/lib/rules/no-template-curly-in-string.js +0 -1
- package/lib/rules/no-ternary.js +0 -1
- package/lib/rules/no-this-before-super.js +0 -1
- package/lib/rules/no-throw-literal.js +0 -1
- package/lib/rules/no-trailing-spaces.js +0 -1
- package/lib/rules/no-undef-init.js +9 -61
- package/lib/rules/no-undef.js +0 -1
- package/lib/rules/no-undefined.js +0 -1
- package/lib/rules/no-underscore-dangle.js +0 -1
- package/lib/rules/no-unexpected-multiline.js +0 -1
- package/lib/rules/no-unmodified-loop-condition.js +0 -1
- package/lib/rules/no-unneeded-ternary.js +0 -1
- package/lib/rules/no-unreachable-loop.js +0 -1
- package/lib/rules/no-unreachable.js +26 -25
- package/lib/rules/no-unsafe-finally.js +0 -1
- package/lib/rules/no-unsafe-negation.js +0 -1
- package/lib/rules/no-unsafe-optional-chaining.js +0 -1
- package/lib/rules/no-unused-expressions.js +4 -5
- package/lib/rules/no-unused-labels.js +0 -1
- package/lib/rules/no-unused-vars.js +26 -28
- package/lib/rules/no-use-before-define.js +0 -1
- package/lib/rules/no-useless-backreference.js +0 -1
- package/lib/rules/no-useless-call.js +0 -1
- package/lib/rules/no-useless-catch.js +0 -1
- package/lib/rules/no-useless-computed-key.js +1 -1
- package/lib/rules/no-useless-concat.js +0 -1
- package/lib/rules/no-useless-constructor.js +0 -1
- package/lib/rules/no-useless-escape.js +9 -9
- package/lib/rules/no-useless-rename.js +0 -1
- package/lib/rules/no-useless-return.js +0 -1
- package/lib/rules/no-var.js +0 -1
- package/lib/rules/no-void.js +0 -1
- package/lib/rules/no-warning-comments.js +0 -1
- package/lib/rules/no-whitespace-before-property.js +0 -1
- package/lib/rules/no-with.js +0 -1
- package/lib/rules/nonblock-statement-body-position.js +0 -1
- package/lib/rules/object-curly-newline.js +0 -1
- package/lib/rules/object-curly-spacing.js +0 -1
- package/lib/rules/object-property-newline.js +0 -1
- package/lib/rules/object-shorthand.js +3 -8
- package/lib/rules/one-var-declaration-per-line.js +0 -1
- package/lib/rules/one-var.js +1 -2
- package/lib/rules/operator-assignment.js +6 -7
- package/lib/rules/operator-linebreak.js +0 -1
- package/lib/rules/padded-blocks.js +1 -1
- package/lib/rules/padding-line-between-statements.js +0 -1
- package/lib/rules/prefer-arrow-callback.js +1 -1
- package/lib/rules/prefer-const.js +0 -1
- package/lib/rules/prefer-destructuring.js +1 -2
- package/lib/rules/prefer-exponentiation-operator.js +0 -1
- package/lib/rules/prefer-named-capture-group.js +0 -1
- package/lib/rules/prefer-numeric-literals.js +0 -1
- package/lib/rules/prefer-object-spread.js +0 -1
- package/lib/rules/prefer-promise-reject-errors.js +0 -1
- package/lib/rules/prefer-reflect.js +0 -1
- package/lib/rules/prefer-regex-literals.js +0 -1
- package/lib/rules/prefer-rest-params.js +0 -1
- package/lib/rules/prefer-spread.js +0 -1
- package/lib/rules/prefer-template.js +0 -1
- package/lib/rules/quote-props.js +8 -9
- package/lib/rules/quotes.js +0 -1
- package/lib/rules/radix.js +0 -1
- package/lib/rules/require-atomic-updates.js +24 -9
- package/lib/rules/require-await.js +0 -1
- package/lib/rules/require-jsdoc.js +1 -1
- package/lib/rules/require-unicode-regexp.js +0 -1
- package/lib/rules/require-yield.js +0 -1
- package/lib/rules/rest-spread-spacing.js +0 -1
- package/lib/rules/semi-spacing.js +0 -1
- package/lib/rules/semi-style.js +0 -1
- package/lib/rules/semi.js +66 -6
- package/lib/rules/sort-imports.js +0 -1
- package/lib/rules/sort-keys.js +0 -1
- package/lib/rules/sort-vars.js +0 -1
- package/lib/rules/space-before-blocks.js +14 -3
- package/lib/rules/space-before-function-paren.js +0 -1
- package/lib/rules/space-in-parens.js +0 -1
- package/lib/rules/space-infix-ops.js +0 -1
- package/lib/rules/space-unary-ops.js +0 -1
- package/lib/rules/spaced-comment.js +0 -1
- package/lib/rules/strict.js +0 -1
- package/lib/rules/switch-colon-spacing.js +1 -14
- package/lib/rules/symbol-description.js +0 -1
- package/lib/rules/template-curly-spacing.js +0 -1
- package/lib/rules/template-tag-spacing.js +0 -1
- package/lib/rules/unicode-bom.js +0 -1
- package/lib/rules/use-isnan.js +0 -1
- package/lib/rules/utils/ast-utils.js +29 -7
- package/lib/rules/utils/lazy-loading-rule-map.js +3 -3
- package/lib/rules/valid-jsdoc.js +1 -1
- package/lib/rules/valid-typeof.js +0 -1
- package/lib/rules/vars-on-top.js +1 -2
- package/lib/rules/wrap-iife.js +0 -1
- package/lib/rules/wrap-regex.js +0 -1
- package/lib/rules/yield-star-spacing.js +0 -1
- package/lib/rules/yoda.js +0 -1
- package/lib/shared/ajv.js +1 -1
- package/lib/shared/config-validator.js +10 -5
- package/lib/shared/logging.js +1 -1
- package/lib/shared/relative-module-resolver.js +1 -0
- package/lib/shared/runtime-info.js +3 -0
- package/lib/shared/traverser.js +2 -2
- package/lib/shared/types.js +2 -2
- package/lib/source-code/source-code.js +11 -5
- package/lib/source-code/token-store/cursor.js +1 -1
- package/package.json +5 -5
package/lib/linter/linter.js
CHANGED
@@ -50,8 +50,8 @@ const parserSymbol = Symbol.for("eslint.RuleTester.parser");
|
|
50
50
|
// Typedefs
|
51
51
|
//------------------------------------------------------------------------------
|
52
52
|
|
53
|
-
/** @typedef {InstanceType<import("../cli-engine/config-array")
|
54
|
-
/** @typedef {InstanceType<import("../cli-engine/config-array")
|
53
|
+
/** @typedef {InstanceType<import("../cli-engine/config-array").ConfigArray>} ConfigArray */
|
54
|
+
/** @typedef {InstanceType<import("../cli-engine/config-array").ExtractedConfig>} ExtractedConfig */
|
55
55
|
/** @typedef {import("../shared/types").ConfigData} ConfigData */
|
56
56
|
/** @typedef {import("../shared/types").Environment} Environment */
|
57
57
|
/** @typedef {import("../shared/types").GlobalConf} GlobalConf */
|
@@ -60,17 +60,19 @@ const parserSymbol = Symbol.for("eslint.RuleTester.parser");
|
|
60
60
|
/** @typedef {import("../shared/types").Processor} Processor */
|
61
61
|
/** @typedef {import("../shared/types").Rule} Rule */
|
62
62
|
|
63
|
+
/* eslint-disable jsdoc/valid-types -- https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/4#issuecomment-778805577 */
|
63
64
|
/**
|
64
65
|
* @template T
|
65
66
|
* @typedef {{ [P in keyof T]-?: T[P] }} Required
|
66
67
|
*/
|
68
|
+
/* eslint-enable jsdoc/valid-types -- https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/4#issuecomment-778805577 */
|
67
69
|
|
68
70
|
/**
|
69
71
|
* @typedef {Object} DisableDirective
|
70
|
-
* @property {("disable"|"enable"|"disable-line"|"disable-next-line")} type
|
71
|
-
* @property {number} line
|
72
|
-
* @property {number} column
|
73
|
-
* @property {(string|null)} ruleId
|
72
|
+
* @property {("disable"|"enable"|"disable-line"|"disable-next-line")} type Type of directive
|
73
|
+
* @property {number} line The line number
|
74
|
+
* @property {number} column The column number
|
75
|
+
* @property {(string|null)} ruleId The rule ID
|
74
76
|
*/
|
75
77
|
|
76
78
|
/**
|
@@ -98,12 +100,12 @@ const parserSymbol = Symbol.for("eslint.RuleTester.parser");
|
|
98
100
|
* @typedef {Object} ProcessorOptions
|
99
101
|
* @property {(filename:string, text:string) => boolean} [filterCodeBlock] the
|
100
102
|
* predicate function that selects adopt code blocks.
|
101
|
-
* @property {Processor
|
103
|
+
* @property {Processor.postprocess} [postprocess] postprocessor for report
|
102
104
|
* messages. If provided, this should accept an array of the message lists
|
103
105
|
* for each code block returned from the preprocessor, apply a mapping to
|
104
106
|
* the messages as appropriate, and return a one-dimensional array of
|
105
107
|
* messages.
|
106
|
-
* @property {Processor
|
108
|
+
* @property {Processor.preprocess} [preprocess] preprocessor for source text.
|
107
109
|
* If provided, this should accept a string of source text, and return an
|
108
110
|
* array of code blocks to lint.
|
109
111
|
*/
|
@@ -313,7 +315,11 @@ function getDirectiveComments(filename, ast, ruleMapper, warnInlineConfig) {
|
|
313
315
|
return;
|
314
316
|
}
|
315
317
|
const directiveText = match[1];
|
316
|
-
const
|
318
|
+
const lineCommentSupported = /^eslint-disable-(next-)?line$/u.test(directiveText);
|
319
|
+
|
320
|
+
if (comment.type === "Line" && !lineCommentSupported) {
|
321
|
+
return;
|
322
|
+
}
|
317
323
|
|
318
324
|
if (warnInlineConfig) {
|
319
325
|
const kind = comment.type === "Block" ? `/*${directiveText}*/` : `//${directiveText}`;
|
@@ -327,7 +333,7 @@ function getDirectiveComments(filename, ast, ruleMapper, warnInlineConfig) {
|
|
327
333
|
return;
|
328
334
|
}
|
329
335
|
|
330
|
-
if (
|
336
|
+
if (lineCommentSupported && comment.loc.start.line !== comment.loc.end.line) {
|
331
337
|
const message = `${directiveText} comment should not span multiple lines.`;
|
332
338
|
|
333
339
|
problems.push(createLintingProblem({
|
@@ -454,10 +460,7 @@ function normalizeEcmaVersion(parser, ecmaVersion) {
|
|
454
460
|
return ecmaVersion >= 2015 ? ecmaVersion - 2009 : ecmaVersion;
|
455
461
|
}
|
456
462
|
|
457
|
-
const
|
458
|
-
/\/\*\s*eslint-env\s(.+?)\*\//gsu, // block comments
|
459
|
-
/\/\/[^\S\r\n\u2028\u2029]*eslint-env[^\S\r\n\u2028\u2029](.+)/gu // line comments
|
460
|
-
];
|
463
|
+
const eslintEnvPattern = /\/\*\s*eslint-env\s(.+?)(?:\*\/|$)/gsu;
|
461
464
|
|
462
465
|
/**
|
463
466
|
* Checks whether or not there is a comment which has "eslint-env *" in a given text.
|
@@ -467,16 +470,17 @@ const eslintEnvPatterns = [
|
|
467
470
|
function findEslintEnv(text) {
|
468
471
|
let match, retv;
|
469
472
|
|
470
|
-
|
471
|
-
eslintEnvPattern.lastIndex = 0;
|
473
|
+
eslintEnvPattern.lastIndex = 0;
|
472
474
|
|
473
|
-
|
475
|
+
while ((match = eslintEnvPattern.exec(text)) !== null) {
|
476
|
+
if (match[0].endsWith("*/")) {
|
474
477
|
retv = Object.assign(
|
475
478
|
retv || {},
|
476
479
|
commentParser.parseListConfig(stripDirectiveComment(match[1]))
|
477
480
|
);
|
478
481
|
}
|
479
482
|
}
|
483
|
+
|
480
484
|
return retv;
|
481
485
|
}
|
482
486
|
|
@@ -764,6 +768,7 @@ function markVariableAsUsed(scopeManager, currentNode, parserOptions, name) {
|
|
764
768
|
* Runs a rule, and gets its listeners
|
765
769
|
* @param {Rule} rule A normalized rule with a `create` method
|
766
770
|
* @param {Context} ruleContext The context that should be passed to the rule
|
771
|
+
* @throws {any} Any error during the rule's `create`
|
767
772
|
* @returns {Object} A map of selector listeners provided by the rule
|
768
773
|
*/
|
769
774
|
function createRuleListeners(rule, ruleContext) {
|
@@ -950,13 +955,31 @@ function runRules(sourceCode, configuredRules, ruleMapper, parserOptions, parser
|
|
950
955
|
|
951
956
|
const ruleListeners = createRuleListeners(rule, ruleContext);
|
952
957
|
|
958
|
+
/**
|
959
|
+
* Include `ruleId` in error logs
|
960
|
+
* @param {Function} ruleListener A rule method that listens for a node.
|
961
|
+
* @returns {Function} ruleListener wrapped in error handler
|
962
|
+
*/
|
963
|
+
function addRuleErrorHandler(ruleListener) {
|
964
|
+
return function ruleErrorHandler(...listenerArgs) {
|
965
|
+
try {
|
966
|
+
return ruleListener(...listenerArgs);
|
967
|
+
} catch (e) {
|
968
|
+
e.ruleId = ruleId;
|
969
|
+
throw e;
|
970
|
+
}
|
971
|
+
};
|
972
|
+
}
|
973
|
+
|
953
974
|
// add all the selectors from the rule as listeners
|
954
975
|
Object.keys(ruleListeners).forEach(selector => {
|
976
|
+
const ruleListener = timing.enabled
|
977
|
+
? timing.time(ruleId, ruleListeners[selector])
|
978
|
+
: ruleListeners[selector];
|
979
|
+
|
955
980
|
emitter.on(
|
956
981
|
selector,
|
957
|
-
|
958
|
-
? timing.time(ruleId, ruleListeners[selector])
|
959
|
-
: ruleListeners[selector]
|
982
|
+
addRuleErrorHandler(ruleListener)
|
960
983
|
);
|
961
984
|
});
|
962
985
|
});
|
@@ -1041,7 +1064,7 @@ function normalizeCwd(cwd) {
|
|
1041
1064
|
}
|
1042
1065
|
|
1043
1066
|
// It's more explicit to assign the undefined
|
1044
|
-
// eslint-disable-next-line no-undefined
|
1067
|
+
// eslint-disable-next-line no-undefined -- Consistently returning a value
|
1045
1068
|
return undefined;
|
1046
1069
|
}
|
1047
1070
|
|
@@ -1064,7 +1087,7 @@ class Linter {
|
|
1064
1087
|
/**
|
1065
1088
|
* Initialize the Linter.
|
1066
1089
|
* @param {Object} [config] the config object
|
1067
|
-
* @param {string} [config.cwd]
|
1090
|
+
* @param {string} [config.cwd] path to a directory that should be considered as the current working directory, can be undefined.
|
1068
1091
|
*/
|
1069
1092
|
constructor({ cwd } = {}) {
|
1070
1093
|
internalSlotsMap.set(this, {
|
@@ -1092,6 +1115,7 @@ class Linter {
|
|
1092
1115
|
* @param {string|SourceCode} textOrSourceCode The text to parse or a SourceCode object.
|
1093
1116
|
* @param {ConfigData} providedConfig An ESLintConfig instance to configure everything.
|
1094
1117
|
* @param {VerifyOptions} [providedOptions] The optional filename of the file being checked.
|
1118
|
+
* @throws {Error} If during rule execution.
|
1095
1119
|
* @returns {LintMessage[]} The results as an array of messages or an empty array if no messages.
|
1096
1120
|
*/
|
1097
1121
|
_verifyWithoutProcessors(textOrSourceCode, providedConfig, providedOptions) {
|
@@ -1217,6 +1241,11 @@ class Linter {
|
|
1217
1241
|
debug("Parser Options:", parserOptions);
|
1218
1242
|
debug("Parser Path:", parserName);
|
1219
1243
|
debug("Settings:", settings);
|
1244
|
+
|
1245
|
+
if (err.ruleId) {
|
1246
|
+
err.message += `\nRule: "${err.ruleId}"`;
|
1247
|
+
}
|
1248
|
+
|
1220
1249
|
throw err;
|
1221
1250
|
}
|
1222
1251
|
|
@@ -237,7 +237,6 @@ function parseSelector(rawSelector) {
|
|
237
237
|
*/
|
238
238
|
class NodeEventGenerator {
|
239
239
|
|
240
|
-
// eslint-disable-next-line jsdoc/require-description
|
241
240
|
/**
|
242
241
|
* @param {SafeEmitter} emitter
|
243
242
|
* An SafeEmitter which is the destination of events. This emitter must already
|
@@ -32,18 +32,18 @@ const interpolate = require("./interpolate");
|
|
32
32
|
/**
|
33
33
|
* Information about the report
|
34
34
|
* @typedef {Object} ReportInfo
|
35
|
-
* @property {string} ruleId
|
36
|
-
* @property {(0|1|2)} severity
|
37
|
-
* @property {(string|undefined)} message
|
38
|
-
* @property {(string|undefined)} [messageId]
|
39
|
-
* @property {number} line
|
40
|
-
* @property {number} column
|
41
|
-
* @property {(number|undefined)} [endLine]
|
42
|
-
* @property {(number|undefined)} [endColumn]
|
43
|
-
* @property {(string|null)} nodeType
|
44
|
-
* @property {string} source
|
45
|
-
* @property {({text: string, range: (number[]|null)}|null)} [fix]
|
46
|
-
* @property {Array<{text: string, range: (number[]|null)}|null>} [suggestions]
|
35
|
+
* @property {string} ruleId The rule ID
|
36
|
+
* @property {(0|1|2)} severity Severity of the error
|
37
|
+
* @property {(string|undefined)} message The message
|
38
|
+
* @property {(string|undefined)} [messageId] The message ID
|
39
|
+
* @property {number} line The line number
|
40
|
+
* @property {number} column The column number
|
41
|
+
* @property {(number|undefined)} [endLine] The ending line number
|
42
|
+
* @property {(number|undefined)} [endColumn] The ending column number
|
43
|
+
* @property {(string|null)} nodeType Type of node
|
44
|
+
* @property {string} source Source text
|
45
|
+
* @property {({text: string, range: (number[]|null)}|null)} [fix] The fix object
|
46
|
+
* @property {Array<{text: string, range: (number[]|null)}|null>} [suggestions] Suggestion info
|
47
47
|
*/
|
48
48
|
|
49
49
|
//------------------------------------------------------------------------------
|
package/lib/linter/rules.js
CHANGED
@@ -12,8 +12,8 @@
|
|
12
12
|
/**
|
13
13
|
* An event emitter
|
14
14
|
* @typedef {Object} SafeEmitter
|
15
|
-
* @property {
|
16
|
-
* @property {
|
15
|
+
* @property {(eventName: string, listenerFunc: Function) => void} on Adds a listener for a given event name
|
16
|
+
* @property {(eventName: string, arg1?: any, arg2?: any, arg3?: any) => void} emit Emits an event with a given name.
|
17
17
|
* This calls all the listeners that were listening for that name, with `arg1`, `arg2`, and `arg3` as arguments.
|
18
18
|
* @property {function(): string[]} eventNames Gets the list of event names that have registered listeners.
|
19
19
|
*/
|
@@ -80,8 +80,8 @@ SourceCodeFixer.applyFixes = function(sourceText, messages, shouldFix) {
|
|
80
80
|
|
81
81
|
/**
|
82
82
|
* Try to use the 'fix' from a problem.
|
83
|
-
* @param
|
84
|
-
* @returns {boolean}
|
83
|
+
* @param {Message} problem The message object to apply fixes from
|
84
|
+
* @returns {boolean} Whether fix was successfully applied
|
85
85
|
*/
|
86
86
|
function attemptFix(problem) {
|
87
87
|
const fix = problem.fix;
|
package/lib/linter/timing.js
CHANGED
@@ -116,7 +116,7 @@ function display(data) {
|
|
116
116
|
return ALIGN[index](":", width + extraAlignment, "-");
|
117
117
|
}).join("|"));
|
118
118
|
|
119
|
-
console.log(table.join("\n")); // eslint-disable-line no-console
|
119
|
+
console.log(table.join("\n")); // eslint-disable-line no-console -- Debugging function
|
120
120
|
}
|
121
121
|
|
122
122
|
/* istanbul ignore next */
|
@@ -126,7 +126,7 @@ module.exports = (function() {
|
|
126
126
|
|
127
127
|
/**
|
128
128
|
* Time the run
|
129
|
-
* @param {
|
129
|
+
* @param {any} key key from the data object
|
130
130
|
* @param {Function} fn function to be called
|
131
131
|
* @returns {Function} function to be executed
|
132
132
|
* @private
|
@@ -4,7 +4,7 @@
|
|
4
4
|
*/
|
5
5
|
"use strict";
|
6
6
|
|
7
|
-
/*
|
7
|
+
/* eslint-env mocha -- Mocha wrapper */
|
8
8
|
|
9
9
|
/*
|
10
10
|
* This is a wrapper around mocha to allow for DRY unittests for eslint
|
@@ -63,6 +63,7 @@ const { SourceCode } = require("../source-code");
|
|
63
63
|
|
64
64
|
/** @typedef {import("../shared/types").Parser} Parser */
|
65
65
|
|
66
|
+
/* eslint-disable jsdoc/valid-types -- https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/4#issuecomment-778805577 */
|
66
67
|
/**
|
67
68
|
* A test case that is expected to pass lint.
|
68
69
|
* @typedef {Object} ValidTestCase
|
@@ -105,6 +106,7 @@ const { SourceCode } = require("../source-code");
|
|
105
106
|
* @property {number} [endLine] The 1-based line number of the reported end location.
|
106
107
|
* @property {number} [endColumn] The 1-based column number of the reported end location.
|
107
108
|
*/
|
109
|
+
/* eslint-enable jsdoc/valid-types -- https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/4#issuecomment-778805577 */
|
108
110
|
|
109
111
|
//------------------------------------------------------------------------------
|
110
112
|
// Private Members
|
@@ -212,7 +214,7 @@ function freezeDeeply(x) {
|
|
212
214
|
*/
|
213
215
|
function sanitize(text) {
|
214
216
|
return text.replace(
|
215
|
-
/[\u0000-\u0009\u000b-\u001a]/gu, // eslint-disable-line no-control-regex
|
217
|
+
/[\u0000-\u0009\u000b-\u001a]/gu, // eslint-disable-line no-control-regex -- Escaping controls
|
216
218
|
c => `\\u${c.codePointAt(0).toString(16).padStart(4, "0")}`
|
217
219
|
);
|
218
220
|
}
|
@@ -311,6 +313,7 @@ const IT_ONLY = Symbol("itOnly");
|
|
311
313
|
* @this {Mocha}
|
312
314
|
* @param {string} text The description of the test case.
|
313
315
|
* @param {Function} method The logic of the test case.
|
316
|
+
* @throws {Error} Any error upon execution of `method`.
|
314
317
|
* @returns {any} Returned value of `method`.
|
315
318
|
*/
|
316
319
|
function itDefaultHandler(text, method) {
|
@@ -335,6 +338,9 @@ function describeDefaultHandler(text, method) {
|
|
335
338
|
return method.call(this);
|
336
339
|
}
|
337
340
|
|
341
|
+
/**
|
342
|
+
* Mocha test wrapper.
|
343
|
+
*/
|
338
344
|
class RuleTester {
|
339
345
|
|
340
346
|
/**
|
@@ -366,6 +372,7 @@ class RuleTester {
|
|
366
372
|
/**
|
367
373
|
* Set the configuration to use for all future tests
|
368
374
|
* @param {Object} config the configuration to use.
|
375
|
+
* @throws {TypeError} If non-object config.
|
369
376
|
* @returns {void}
|
370
377
|
*/
|
371
378
|
static setDefaultConfig(config) {
|
@@ -481,6 +488,8 @@ class RuleTester {
|
|
481
488
|
* valid: (ValidTestCase | string)[],
|
482
489
|
* invalid: InvalidTestCase[]
|
483
490
|
* }} test The collection of tests to run.
|
491
|
+
* @throws {TypeError|Error} If non-object `test`, or if a required
|
492
|
+
* scenario of the given type is missing.
|
484
493
|
* @returns {void}
|
485
494
|
*/
|
486
495
|
run(ruleName, rule, test) {
|
@@ -524,6 +533,7 @@ class RuleTester {
|
|
524
533
|
/**
|
525
534
|
* Run the rule for the given item
|
526
535
|
* @param {string|Object} item Item to run the rule against
|
536
|
+
* @throws {Error} If an invalid schema.
|
527
537
|
* @returns {Object} Eslint run result
|
528
538
|
* @private
|
529
539
|
*/
|
package/lib/rules/brace-style.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* @fileoverview Enforce return after a callback.
|
3
3
|
* @author Jamund Ferguson
|
4
|
+
* @deprecated in ESLint v7.0.0
|
4
5
|
*/
|
5
6
|
"use strict";
|
6
7
|
|
@@ -18,7 +19,6 @@ module.exports = {
|
|
18
19
|
|
19
20
|
docs: {
|
20
21
|
description: "require `return` statements after callbacks",
|
21
|
-
category: "Node.js and CommonJS",
|
22
22
|
recommended: false,
|
23
23
|
url: "https://eslint.org/docs/rules/callback-return"
|
24
24
|
},
|
package/lib/rules/camelcase.js
CHANGED
@@ -15,7 +15,6 @@ module.exports = {
|
|
15
15
|
|
16
16
|
docs: {
|
17
17
|
description: "enforce camelcase naming convention",
|
18
|
-
category: "Stylistic Issues",
|
19
18
|
recommended: false,
|
20
19
|
url: "https://eslint.org/docs/rules/camelcase"
|
21
20
|
},
|
@@ -240,27 +239,26 @@ module.exports = {
|
|
240
239
|
|
241
240
|
// Report camelcase of global variable references ------------------
|
242
241
|
Program() {
|
243
|
-
if (ignoreGlobals) {
|
244
|
-
return;
|
245
|
-
}
|
246
|
-
|
247
242
|
const scope = context.getScope();
|
248
243
|
|
249
|
-
|
250
|
-
for (const variable of scope.variables) {
|
251
|
-
if (
|
252
|
-
variable.identifiers.length > 0 ||
|
253
|
-
isGoodName(variable.name)
|
254
|
-
) {
|
255
|
-
continue;
|
256
|
-
}
|
257
|
-
for (const reference of variable.references) {
|
244
|
+
if (!ignoreGlobals) {
|
258
245
|
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
246
|
+
// Defined globals in config files or directive comments.
|
247
|
+
for (const variable of scope.variables) {
|
248
|
+
if (
|
249
|
+
variable.identifiers.length > 0 ||
|
250
|
+
isGoodName(variable.name)
|
251
|
+
) {
|
252
|
+
continue;
|
253
|
+
}
|
254
|
+
for (const reference of variable.references) {
|
255
|
+
|
256
|
+
/*
|
257
|
+
* For backward compatibility, this rule reports read-only
|
258
|
+
* references as well.
|
259
|
+
*/
|
260
|
+
reportReferenceId(reference.identifier);
|
261
|
+
}
|
264
262
|
}
|
265
263
|
}
|
266
264
|
|
@@ -21,7 +21,6 @@ module.exports = {
|
|
21
21
|
|
22
22
|
docs: {
|
23
23
|
description: "enforce that class methods utilize `this`",
|
24
|
-
category: "Best Practices",
|
25
24
|
recommended: false,
|
26
25
|
url: "https://eslint.org/docs/rules/class-methods-use-this"
|
27
26
|
},
|
@@ -34,6 +33,10 @@ module.exports = {
|
|
34
33
|
items: {
|
35
34
|
type: "string"
|
36
35
|
}
|
36
|
+
},
|
37
|
+
enforceForClassFields: {
|
38
|
+
type: "boolean",
|
39
|
+
default: true
|
37
40
|
}
|
38
41
|
},
|
39
42
|
additionalProperties: false
|
@@ -45,10 +48,27 @@ module.exports = {
|
|
45
48
|
},
|
46
49
|
create(context) {
|
47
50
|
const config = Object.assign({}, context.options[0]);
|
51
|
+
const enforceForClassFields = config.enforceForClassFields !== false;
|
48
52
|
const exceptMethods = new Set(config.exceptMethods || []);
|
49
53
|
|
50
54
|
const stack = [];
|
51
55
|
|
56
|
+
/**
|
57
|
+
* Push `this` used flag initialized with `false` onto the stack.
|
58
|
+
* @returns {void}
|
59
|
+
*/
|
60
|
+
function pushContext() {
|
61
|
+
stack.push(false);
|
62
|
+
}
|
63
|
+
|
64
|
+
/**
|
65
|
+
* Pop `this` used flag from the stack.
|
66
|
+
* @returns {boolean | undefined} `this` used flag
|
67
|
+
*/
|
68
|
+
function popContext() {
|
69
|
+
return stack.pop();
|
70
|
+
}
|
71
|
+
|
52
72
|
/**
|
53
73
|
* Initializes the current context to false and pushes it onto the stack.
|
54
74
|
* These booleans represent whether 'this' has been used in the context.
|
@@ -56,7 +76,7 @@ module.exports = {
|
|
56
76
|
* @private
|
57
77
|
*/
|
58
78
|
function enterFunction() {
|
59
|
-
|
79
|
+
pushContext();
|
60
80
|
}
|
61
81
|
|
62
82
|
/**
|
@@ -70,7 +90,7 @@ module.exports = {
|
|
70
90
|
case "MethodDefinition":
|
71
91
|
return !node.static && node.kind !== "constructor";
|
72
92
|
case "PropertyDefinition":
|
73
|
-
return !node.static;
|
93
|
+
return !node.static && enforceForClassFields;
|
74
94
|
default:
|
75
95
|
return false;
|
76
96
|
}
|
@@ -83,8 +103,19 @@ module.exports = {
|
|
83
103
|
* @private
|
84
104
|
*/
|
85
105
|
function isIncludedInstanceMethod(node) {
|
86
|
-
|
87
|
-
(node.computed
|
106
|
+
if (isInstanceMethod(node)) {
|
107
|
+
if (node.computed) {
|
108
|
+
return true;
|
109
|
+
}
|
110
|
+
|
111
|
+
const hashIfNeeded = node.key.type === "PrivateIdentifier" ? "#" : "";
|
112
|
+
const name = node.key.type === "Literal"
|
113
|
+
? astUtils.getStaticStringValue(node.key)
|
114
|
+
: (node.key.name || "");
|
115
|
+
|
116
|
+
return !exceptMethods.has(hashIfNeeded + name);
|
117
|
+
}
|
118
|
+
return false;
|
88
119
|
}
|
89
120
|
|
90
121
|
/**
|
@@ -96,7 +127,7 @@ module.exports = {
|
|
96
127
|
* @private
|
97
128
|
*/
|
98
129
|
function exitFunction(node) {
|
99
|
-
const methodUsesThis =
|
130
|
+
const methodUsesThis = popContext();
|
100
131
|
|
101
132
|
if (isIncludedInstanceMethod(node.parent) && !methodUsesThis) {
|
102
133
|
context.report({
|
@@ -126,10 +157,21 @@ module.exports = {
|
|
126
157
|
"FunctionDeclaration:exit": exitFunction,
|
127
158
|
FunctionExpression: enterFunction,
|
128
159
|
"FunctionExpression:exit": exitFunction,
|
129
|
-
|
130
|
-
|
160
|
+
|
161
|
+
/*
|
162
|
+
* Class field value are implicit functions.
|
163
|
+
*/
|
164
|
+
"PropertyDefinition:exit": popContext,
|
165
|
+
"PropertyDefinition > *.key:exit": pushContext,
|
166
|
+
|
131
167
|
ThisExpression: markThisUsed,
|
132
|
-
Super: markThisUsed
|
168
|
+
Super: markThisUsed,
|
169
|
+
...(
|
170
|
+
enforceForClassFields && {
|
171
|
+
"PropertyDefinition > ArrowFunctionExpression.value": enterFunction,
|
172
|
+
"PropertyDefinition > ArrowFunctionExpression.value:exit": exitFunction
|
173
|
+
}
|
174
|
+
)
|
133
175
|
};
|
134
176
|
}
|
135
177
|
};
|