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/rules/comma-style.js
CHANGED
package/lib/rules/complexity.js
CHANGED
@@ -23,7 +23,6 @@ module.exports = {
|
|
23
23
|
|
24
24
|
docs: {
|
25
25
|
description: "enforce a maximum cyclomatic complexity allowed in a program",
|
26
|
-
category: "Best Practices",
|
27
26
|
recommended: false,
|
28
27
|
url: "https://eslint.org/docs/rules/complexity"
|
29
28
|
},
|
@@ -75,60 +74,16 @@ module.exports = {
|
|
75
74
|
// Helpers
|
76
75
|
//--------------------------------------------------------------------------
|
77
76
|
|
78
|
-
// Using a stack to store complexity
|
79
|
-
const
|
77
|
+
// Using a stack to store complexity per code path
|
78
|
+
const complexities = [];
|
80
79
|
|
81
80
|
/**
|
82
|
-
*
|
83
|
-
* @returns {void}
|
84
|
-
* @private
|
85
|
-
*/
|
86
|
-
function startFunction() {
|
87
|
-
fns.push(1);
|
88
|
-
}
|
89
|
-
|
90
|
-
/**
|
91
|
-
* Evaluate the node at the end of function
|
92
|
-
* @param {ASTNode} node node to evaluate
|
93
|
-
* @returns {void}
|
94
|
-
* @private
|
95
|
-
*/
|
96
|
-
function endFunction(node) {
|
97
|
-
const name = upperCaseFirst(astUtils.getFunctionNameWithKind(node));
|
98
|
-
const complexity = fns.pop();
|
99
|
-
|
100
|
-
if (complexity > THRESHOLD) {
|
101
|
-
context.report({
|
102
|
-
node,
|
103
|
-
messageId: "complex",
|
104
|
-
data: { name, complexity, max: THRESHOLD }
|
105
|
-
});
|
106
|
-
}
|
107
|
-
}
|
108
|
-
|
109
|
-
/**
|
110
|
-
* Increase the complexity of the function in context
|
81
|
+
* Increase the complexity of the code path in context
|
111
82
|
* @returns {void}
|
112
83
|
* @private
|
113
84
|
*/
|
114
85
|
function increaseComplexity() {
|
115
|
-
|
116
|
-
fns[fns.length - 1]++;
|
117
|
-
}
|
118
|
-
}
|
119
|
-
|
120
|
-
/**
|
121
|
-
* Increase the switch complexity in context
|
122
|
-
* @param {ASTNode} node node to evaluate
|
123
|
-
* @returns {void}
|
124
|
-
* @private
|
125
|
-
*/
|
126
|
-
function increaseSwitchComplexity(node) {
|
127
|
-
|
128
|
-
// Avoiding `default`
|
129
|
-
if (node.test) {
|
130
|
-
increaseComplexity();
|
131
|
-
}
|
86
|
+
complexities[complexities.length - 1]++;
|
132
87
|
}
|
133
88
|
|
134
89
|
//--------------------------------------------------------------------------
|
@@ -136,13 +91,14 @@ module.exports = {
|
|
136
91
|
//--------------------------------------------------------------------------
|
137
92
|
|
138
93
|
return {
|
139
|
-
FunctionDeclaration: startFunction,
|
140
|
-
FunctionExpression: startFunction,
|
141
|
-
ArrowFunctionExpression: startFunction,
|
142
|
-
"FunctionDeclaration:exit": endFunction,
|
143
|
-
"FunctionExpression:exit": endFunction,
|
144
|
-
"ArrowFunctionExpression:exit": endFunction,
|
145
94
|
|
95
|
+
onCodePathStart() {
|
96
|
+
|
97
|
+
// The initial complexity is 1, representing one execution path in the CodePath
|
98
|
+
complexities.push(1);
|
99
|
+
},
|
100
|
+
|
101
|
+
// Each branching in the code adds 1 to the complexity
|
146
102
|
CatchClause: increaseComplexity,
|
147
103
|
ConditionalExpression: increaseComplexity,
|
148
104
|
LogicalExpression: increaseComplexity,
|
@@ -150,14 +106,49 @@ module.exports = {
|
|
150
106
|
ForInStatement: increaseComplexity,
|
151
107
|
ForOfStatement: increaseComplexity,
|
152
108
|
IfStatement: increaseComplexity,
|
153
|
-
SwitchCase: increaseSwitchComplexity,
|
154
109
|
WhileStatement: increaseComplexity,
|
155
110
|
DoWhileStatement: increaseComplexity,
|
156
111
|
|
112
|
+
// Avoid `default`
|
113
|
+
"SwitchCase[test]": increaseComplexity,
|
114
|
+
|
115
|
+
// Logical assignment operators have short-circuiting behavior
|
157
116
|
AssignmentExpression(node) {
|
158
117
|
if (astUtils.isLogicalAssignmentOperator(node.operator)) {
|
159
118
|
increaseComplexity();
|
160
119
|
}
|
120
|
+
},
|
121
|
+
|
122
|
+
onCodePathEnd(codePath, node) {
|
123
|
+
const complexity = complexities.pop();
|
124
|
+
|
125
|
+
/*
|
126
|
+
* This rule only evaluates complexity of functions, so "program" is excluded.
|
127
|
+
* Class field initializers are implicit functions. Therefore, they shouldn't contribute
|
128
|
+
* to the enclosing function's complexity, but their own complexity should be evaluated.
|
129
|
+
*/
|
130
|
+
if (
|
131
|
+
codePath.origin !== "function" &&
|
132
|
+
codePath.origin !== "class-field-initializer"
|
133
|
+
) {
|
134
|
+
return;
|
135
|
+
}
|
136
|
+
|
137
|
+
if (complexity > THRESHOLD) {
|
138
|
+
const name = codePath.origin === "class-field-initializer"
|
139
|
+
? "class field initializer"
|
140
|
+
: astUtils.getFunctionNameWithKind(node);
|
141
|
+
|
142
|
+
context.report({
|
143
|
+
node,
|
144
|
+
messageId: "complex",
|
145
|
+
data: {
|
146
|
+
name: upperCaseFirst(name),
|
147
|
+
complexity,
|
148
|
+
max: THRESHOLD
|
149
|
+
}
|
150
|
+
});
|
151
|
+
}
|
161
152
|
}
|
162
153
|
};
|
163
154
|
|
@@ -14,7 +14,6 @@ module.exports = {
|
|
14
14
|
|
15
15
|
docs: {
|
16
16
|
description: "enforce consistent naming when capturing the current execution context",
|
17
|
-
category: "Stylistic Issues",
|
18
17
|
recommended: false,
|
19
18
|
url: "https://eslint.org/docs/rules/consistent-this"
|
20
19
|
},
|
@@ -47,7 +46,7 @@ module.exports = {
|
|
47
46
|
* Reports that a variable declarator or assignment expression is assigning
|
48
47
|
* a non-'this' value to the specified alias.
|
49
48
|
* @param {ASTNode} node The assigning node.
|
50
|
-
* @param {string}
|
49
|
+
* @param {string} name the name of the alias that was incorrectly used.
|
51
50
|
* @returns {void}
|
52
51
|
*/
|
53
52
|
function reportBadAssignment(node, name) {
|
package/lib/rules/curly.js
CHANGED
@@ -16,7 +16,6 @@ module.exports = {
|
|
16
16
|
|
17
17
|
docs: {
|
18
18
|
description: "require `default` cases in `switch` statements",
|
19
|
-
category: "Best Practices",
|
20
19
|
recommended: false,
|
21
20
|
url: "https://eslint.org/docs/rules/default-case"
|
22
21
|
},
|
@@ -50,8 +49,8 @@ module.exports = {
|
|
50
49
|
|
51
50
|
/**
|
52
51
|
* Shortcut to get last element of array
|
53
|
-
* @param
|
54
|
-
* @returns {
|
52
|
+
* @param {*[]} collection Array
|
53
|
+
* @returns {any} Last element
|
55
54
|
*/
|
56
55
|
function last(collection) {
|
57
56
|
return collection[collection.length - 1];
|
@@ -11,7 +11,6 @@ module.exports = {
|
|
11
11
|
|
12
12
|
docs: {
|
13
13
|
description: "enforce default parameters to be last",
|
14
|
-
category: "Best Practices",
|
15
14
|
recommended: false,
|
16
15
|
url: "https://eslint.org/docs/rules/default-param-last"
|
17
16
|
},
|
@@ -25,8 +24,8 @@ module.exports = {
|
|
25
24
|
|
26
25
|
create(context) {
|
27
26
|
|
28
|
-
// eslint-disable-next-line jsdoc/require-description
|
29
27
|
/**
|
28
|
+
* Handler for function contexts.
|
30
29
|
* @param {ASTNode} node function node
|
31
30
|
* @returns {void}
|
32
31
|
*/
|
package/lib/rules/eol-last.js
CHANGED
@@ -14,7 +14,6 @@ module.exports = {
|
|
14
14
|
|
15
15
|
docs: {
|
16
16
|
description: "require or disallow newline at the end of files",
|
17
|
-
category: "Stylistic Issues",
|
18
17
|
recommended: false,
|
19
18
|
url: "https://eslint.org/docs/rules/eol-last"
|
20
19
|
},
|
@@ -86,10 +85,15 @@ module.exports = {
|
|
86
85
|
});
|
87
86
|
} else if (mode === "never" && endsWithNewline) {
|
88
87
|
|
88
|
+
const secondLastLine = sourceCode.lines[sourceCode.lines.length - 2];
|
89
|
+
|
89
90
|
// File is newline-terminated, but shouldn't be
|
90
91
|
context.report({
|
91
92
|
node,
|
92
|
-
loc:
|
93
|
+
loc: {
|
94
|
+
start: { line: sourceCode.lines.length - 1, column: secondLastLine.length },
|
95
|
+
end: { line: sourceCode.lines.length, column: 0 }
|
96
|
+
},
|
93
97
|
messageId: "unexpected",
|
94
98
|
fix(fixer) {
|
95
99
|
const finalEOLs = /(?:\r?\n)+$/u,
|
package/lib/rules/eqeqeq.js
CHANGED
@@ -21,7 +21,6 @@ module.exports = {
|
|
21
21
|
|
22
22
|
docs: {
|
23
23
|
description: "require the use of `===` and `!==`",
|
24
|
-
category: "Best Practices",
|
25
24
|
recommended: false,
|
26
25
|
url: "https://eslint.org/docs/rules/eqeqeq"
|
27
26
|
},
|
@@ -78,7 +77,7 @@ module.exports = {
|
|
78
77
|
|
79
78
|
/**
|
80
79
|
* Checks if an expression is a typeof expression
|
81
|
-
* @param
|
80
|
+
* @param {ASTNode} node The node to check
|
82
81
|
* @returns {boolean} if the node is a typeof expression
|
83
82
|
*/
|
84
83
|
function isTypeOf(node) {
|
@@ -74,7 +74,6 @@ module.exports = {
|
|
74
74
|
|
75
75
|
docs: {
|
76
76
|
description: "require function names to match the name of the variable or property to which they are assigned",
|
77
|
-
category: "Stylistic Issues",
|
78
77
|
recommended: false,
|
79
78
|
url: "https://eslint.org/docs/rules/func-name-matching"
|
80
79
|
},
|
@@ -196,21 +195,25 @@ module.exports = {
|
|
196
195
|
const isProp = node.left.type === "MemberExpression";
|
197
196
|
const name = isProp ? astUtils.getStaticPropertyName(node.left) : node.left.name;
|
198
197
|
|
199
|
-
if (node.right.id && isIdentifier(name) && shouldWarn(name, node.right.id.name)) {
|
198
|
+
if (node.right.id && name && isIdentifier(name) && shouldWarn(name, node.right.id.name)) {
|
200
199
|
report(node, name, node.right.id.name, isProp);
|
201
200
|
}
|
202
201
|
},
|
203
202
|
|
204
|
-
Property(node) {
|
205
|
-
if (node.value.type
|
203
|
+
"Property, PropertyDefinition[value]"(node) {
|
204
|
+
if (!(node.value.type === "FunctionExpression" && node.value.id)) {
|
206
205
|
return;
|
207
206
|
}
|
208
207
|
|
209
|
-
if (node.key.type === "Identifier") {
|
208
|
+
if (node.key.type === "Identifier" && !node.computed) {
|
210
209
|
const functionName = node.value.id.name;
|
211
210
|
let propertyName = node.key.name;
|
212
211
|
|
213
|
-
if (
|
212
|
+
if (
|
213
|
+
considerPropertyDescriptor &&
|
214
|
+
propertyName === "value" &&
|
215
|
+
node.parent.type === "ObjectExpression"
|
216
|
+
) {
|
214
217
|
if (isPropertyCall("Object", "defineProperty", node.parent.parent) || isPropertyCall("Reflect", "defineProperty", node.parent.parent)) {
|
215
218
|
const property = node.parent.parent.arguments[1];
|
216
219
|
|
package/lib/rules/func-names.js
CHANGED
package/lib/rules/func-style.js
CHANGED
@@ -20,7 +20,6 @@ module.exports = {
|
|
20
20
|
|
21
21
|
docs: {
|
22
22
|
description: "enforce consistent line breaks inside function parentheses",
|
23
|
-
category: "Stylistic Issues",
|
24
23
|
recommended: false,
|
25
24
|
url: "https://eslint.org/docs/rules/function-paren-newline"
|
26
25
|
},
|
@@ -183,6 +182,7 @@ module.exports = {
|
|
183
182
|
/**
|
184
183
|
* Gets the left paren and right paren tokens of a node.
|
185
184
|
* @param {ASTNode} node The node with parens
|
185
|
+
* @throws {TypeError} Unexecpted node type.
|
186
186
|
* @returns {Object} An object with keys `leftParen` for the left paren token, and `rightParen` for the right paren token.
|
187
187
|
* Can also return `null` if an expression has no parens (e.g. a NewExpression with no arguments, or an ArrowFunctionExpression
|
188
188
|
* with a single parameter)
|
@@ -1,6 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* @fileoverview Rule for disallowing require() outside of the top-level module context
|
3
3
|
* @author Jamund Ferguson
|
4
|
+
* @deprecated in ESLint v7.0.0
|
4
5
|
*/
|
5
6
|
|
6
7
|
"use strict";
|
@@ -57,7 +58,6 @@ module.exports = {
|
|
57
58
|
|
58
59
|
docs: {
|
59
60
|
description: "require `require()` calls to be placed at top-level module scope",
|
60
|
-
category: "Node.js and CommonJS",
|
61
61
|
recommended: false,
|
62
62
|
url: "https://eslint.org/docs/rules/global-require"
|
63
63
|
},
|
@@ -1,6 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* @fileoverview Ensure handling of errors when we know they exist.
|
3
3
|
* @author Jamund Ferguson
|
4
|
+
* @deprecated in ESLint v7.0.0
|
4
5
|
*/
|
5
6
|
|
6
7
|
"use strict";
|
@@ -19,7 +20,6 @@ module.exports = {
|
|
19
20
|
|
20
21
|
docs: {
|
21
22
|
description: "require error handling in callbacks",
|
22
|
-
category: "Node.js and CommonJS",
|
23
23
|
recommended: false,
|
24
24
|
url: "https://eslint.org/docs/rules/handle-callback-err"
|
25
25
|
},
|
@@ -2,6 +2,7 @@
|
|
2
2
|
* @fileoverview Rule that warns when identifier names that are
|
3
3
|
* specified in the configuration are used.
|
4
4
|
* @author Keith Cirkel (http://keithcirkel.co.uk)
|
5
|
+
* @deprecated in ESLint v7.5.0
|
5
6
|
*/
|
6
7
|
|
7
8
|
"use strict";
|
@@ -118,7 +119,6 @@ module.exports = {
|
|
118
119
|
|
119
120
|
docs: {
|
120
121
|
description: "disallow specified identifiers",
|
121
|
-
category: "Stylistic Issues",
|
122
122
|
recommended: false,
|
123
123
|
url: "https://eslint.org/docs/rules/id-blacklist"
|
124
124
|
},
|
package/lib/rules/id-denylist.js
CHANGED
package/lib/rules/id-length.js
CHANGED
package/lib/rules/id-match.js
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
* This rule has been ported and modified from nodeca.
|
5
5
|
* @author Vitaly Puzrin
|
6
6
|
* @author Gyandeep Singh
|
7
|
+
* @deprecated in ESLint v4.0.0
|
7
8
|
*/
|
8
9
|
|
9
10
|
"use strict";
|
@@ -25,7 +26,6 @@ module.exports = {
|
|
25
26
|
|
26
27
|
docs: {
|
27
28
|
description: "enforce consistent indentation",
|
28
|
-
category: "Stylistic Issues",
|
29
29
|
recommended: false,
|
30
30
|
url: "https://eslint.org/docs/rules/indent-legacy"
|
31
31
|
},
|
package/lib/rules/indent.js
CHANGED
@@ -140,7 +140,7 @@ class BinarySearchTree {
|
|
140
140
|
/**
|
141
141
|
* Inserts an entry into the tree.
|
142
142
|
* @param {number} key The entry's key
|
143
|
-
* @param {
|
143
|
+
* @param {any} value The entry's value
|
144
144
|
* @returns {void}
|
145
145
|
*/
|
146
146
|
insert(key, value) {
|
@@ -190,7 +190,6 @@ class BinarySearchTree {
|
|
190
190
|
*/
|
191
191
|
class TokenInfo {
|
192
192
|
|
193
|
-
// eslint-disable-next-line jsdoc/require-description
|
194
193
|
/**
|
195
194
|
* @param {SourceCode} sourceCode A SourceCode object
|
196
195
|
*/
|
@@ -240,7 +239,6 @@ class TokenInfo {
|
|
240
239
|
*/
|
241
240
|
class OffsetStorage {
|
242
241
|
|
243
|
-
// eslint-disable-next-line jsdoc/require-description
|
244
242
|
/**
|
245
243
|
* @param {TokenInfo} tokenInfo a TokenInfo instance
|
246
244
|
* @param {number} indentSize The desired size of each indentation level
|
@@ -265,7 +263,7 @@ class OffsetStorage {
|
|
265
263
|
|
266
264
|
/**
|
267
265
|
* Sets the offset column of token B to match the offset column of token A.
|
268
|
-
* **WARNING**: This matches a *column*, even if baseToken is not the first token on its line. In
|
266
|
+
* - **WARNING**: This matches a *column*, even if baseToken is not the first token on its line. In
|
269
267
|
* most cases, `setDesiredOffset` should be used instead.
|
270
268
|
* @param {Token} baseToken The first token
|
271
269
|
* @param {Token} offsetToken The second token, whose offset should be matched to the first token
|
@@ -354,11 +352,11 @@ class OffsetStorage {
|
|
354
352
|
* Instead, the offset tree is represented as a collection of contiguous offset ranges in a file. For example, the following
|
355
353
|
* list could represent the state of the offset tree at a given point:
|
356
354
|
*
|
357
|
-
*
|
358
|
-
*
|
359
|
-
*
|
360
|
-
*
|
361
|
-
*
|
355
|
+
* - Tokens starting in the interval [0, 15) are aligned with the beginning of the file
|
356
|
+
* - Tokens starting in the interval [15, 30) are offset by 1 indent level from the `bar` token
|
357
|
+
* - Tokens starting in the interval [30, 43) are offset by 1 indent level from the `foo` token
|
358
|
+
* - Tokens starting in the interval [43, 820) are offset by 2 indent levels from the `bar` token
|
359
|
+
* - Tokens starting in the interval [820, ∞) are offset by 1 indent level from the `baz` token
|
362
360
|
*
|
363
361
|
* The `setDesiredOffsets` methods inserts ranges like the ones above. The third line above would be inserted by using:
|
364
362
|
* `setDesiredOffsets([30, 43], fooToken, 1);`
|
@@ -501,7 +499,6 @@ module.exports = {
|
|
501
499
|
|
502
500
|
docs: {
|
503
501
|
description: "enforce consistent indentation",
|
504
|
-
category: "Stylistic Issues",
|
505
502
|
recommended: false,
|
506
503
|
url: "https://eslint.org/docs/rules/indent"
|
507
504
|
},
|
package/lib/rules/index.js
CHANGED
package/lib/rules/jsx-quotes.js
CHANGED