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
@@ -17,7 +17,6 @@ module.exports = {
|
|
17
17
|
|
18
18
|
docs: {
|
19
19
|
description: "disallow initializing variables to `undefined`",
|
20
|
-
category: "Variables",
|
21
20
|
recommended: false,
|
22
21
|
url: "https://eslint.org/docs/rules/no-undef-init"
|
23
22
|
},
|
@@ -34,88 +33,37 @@ module.exports = {
|
|
34
33
|
|
35
34
|
const sourceCode = context.getSourceCode();
|
36
35
|
|
37
|
-
/**
|
38
|
-
* Get the node of init target.
|
39
|
-
* @param {ASTNode} node The node to get.
|
40
|
-
* @returns {ASTNode} The node of init target.
|
41
|
-
*/
|
42
|
-
function getIdNode(node) {
|
43
|
-
switch (node.type) {
|
44
|
-
case "VariableDeclarator":
|
45
|
-
return node.id;
|
46
|
-
case "PropertyDefinition":
|
47
|
-
return node.key;
|
48
|
-
default:
|
49
|
-
throw new Error("unreachable");
|
50
|
-
}
|
51
|
-
}
|
52
|
-
|
53
|
-
/**
|
54
|
-
* Get the node of init value.
|
55
|
-
* @param {ASTNode} node The node to get.
|
56
|
-
* @returns {ASTNode} The node of init value.
|
57
|
-
*/
|
58
|
-
function getInitNode(node) {
|
59
|
-
switch (node.type) {
|
60
|
-
case "VariableDeclarator":
|
61
|
-
return node.init;
|
62
|
-
case "PropertyDefinition":
|
63
|
-
return node.value;
|
64
|
-
default:
|
65
|
-
throw new Error("unreachable");
|
66
|
-
}
|
67
|
-
}
|
68
|
-
|
69
|
-
/**
|
70
|
-
* Get the parent kind of the node.
|
71
|
-
* @param {ASTNode} node The node to get.
|
72
|
-
* @returns {string} The parent kind.
|
73
|
-
*/
|
74
|
-
function getParentKind(node) {
|
75
|
-
switch (node.type) {
|
76
|
-
case "VariableDeclarator":
|
77
|
-
return node.parent.kind;
|
78
|
-
case "PropertyDefinition":
|
79
|
-
return "field";
|
80
|
-
default:
|
81
|
-
throw new Error("unreachable");
|
82
|
-
}
|
83
|
-
}
|
84
|
-
|
85
36
|
return {
|
86
37
|
|
87
|
-
|
88
|
-
const
|
89
|
-
|
90
|
-
initNode = getInitNode(node),
|
91
|
-
initIsUndefined = initNode && initNode.type === "Identifier" && initNode.name === "undefined",
|
92
|
-
parentKind = getParentKind(node),
|
38
|
+
VariableDeclarator(node) {
|
39
|
+
const name = sourceCode.getText(node.id),
|
40
|
+
init = node.init && node.init.name,
|
93
41
|
scope = context.getScope(),
|
94
42
|
undefinedVar = astUtils.getVariableByName(scope, "undefined"),
|
95
43
|
shadowed = undefinedVar && undefinedVar.defs.length > 0,
|
96
|
-
lastToken = sourceCode.getLastToken(node
|
44
|
+
lastToken = sourceCode.getLastToken(node);
|
97
45
|
|
98
|
-
if (
|
46
|
+
if (init === "undefined" && node.parent.kind !== "const" && !shadowed) {
|
99
47
|
context.report({
|
100
48
|
node,
|
101
49
|
messageId: "unnecessaryUndefinedInit",
|
102
50
|
data: { name },
|
103
51
|
fix(fixer) {
|
104
|
-
if (
|
52
|
+
if (node.parent.kind === "var") {
|
105
53
|
return null;
|
106
54
|
}
|
107
55
|
|
108
|
-
if (
|
56
|
+
if (node.id.type === "ArrayPattern" || node.id.type === "ObjectPattern") {
|
109
57
|
|
110
58
|
// Don't fix destructuring assignment to `undefined`.
|
111
59
|
return null;
|
112
60
|
}
|
113
61
|
|
114
|
-
if (sourceCode.commentsExistBetween(
|
62
|
+
if (sourceCode.commentsExistBetween(node.id, lastToken)) {
|
115
63
|
return null;
|
116
64
|
}
|
117
65
|
|
118
|
-
return fixer.removeRange([
|
66
|
+
return fixer.removeRange([node.id.range[1], node.range[1]]);
|
119
67
|
}
|
120
68
|
});
|
121
69
|
}
|
package/lib/rules/no-undef.js
CHANGED
@@ -9,9 +9,8 @@
|
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
11
|
/**
|
12
|
-
* @typedef {Object}
|
13
|
-
* @property {
|
14
|
-
* @property {boolean} hasConstructor The flag about having user-defined constructor.
|
12
|
+
* @typedef {Object} ConstructorInfo
|
13
|
+
* @property {ConstructorInfo | null} upper Info about the constructor that encloses this constructor.
|
15
14
|
* @property {boolean} hasSuperCall The flag about having `super()` expressions.
|
16
15
|
*/
|
17
16
|
|
@@ -112,7 +111,6 @@ module.exports = {
|
|
112
111
|
|
113
112
|
docs: {
|
114
113
|
description: "disallow unreachable code after `return`, `throw`, `continue`, and `break` statements",
|
115
|
-
category: "Possible Errors",
|
116
114
|
recommended: true,
|
117
115
|
url: "https://eslint.org/docs/rules/no-unreachable"
|
118
116
|
},
|
@@ -127,8 +125,8 @@ module.exports = {
|
|
127
125
|
create(context) {
|
128
126
|
let currentCodePath = null;
|
129
127
|
|
130
|
-
/** @type {
|
131
|
-
let
|
128
|
+
/** @type {ConstructorInfo | null} */
|
129
|
+
let constructorInfo = null;
|
132
130
|
|
133
131
|
/** @type {ConsecutiveRange} */
|
134
132
|
const range = new ConsecutiveRange(context.getSourceCode());
|
@@ -225,36 +223,39 @@ module.exports = {
|
|
225
223
|
reportIfUnreachable();
|
226
224
|
},
|
227
225
|
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
226
|
+
/*
|
227
|
+
* Instance fields defined in a subclass are never created if the constructor of the subclass
|
228
|
+
* doesn't call `super()`, so their definitions are unreachable code.
|
229
|
+
*/
|
230
|
+
"MethodDefinition[kind='constructor']"() {
|
231
|
+
constructorInfo = {
|
232
|
+
upper: constructorInfo,
|
233
233
|
hasSuperCall: false
|
234
234
|
};
|
235
235
|
},
|
236
|
-
"
|
237
|
-
const {
|
238
|
-
|
236
|
+
"MethodDefinition[kind='constructor']:exit"(node) {
|
237
|
+
const { hasSuperCall } = constructorInfo;
|
238
|
+
|
239
|
+
constructorInfo = constructorInfo.upper;
|
240
|
+
|
241
|
+
// skip typescript constructors without the body
|
242
|
+
if (!node.value.body) {
|
243
|
+
return;
|
244
|
+
}
|
239
245
|
|
240
|
-
|
246
|
+
const classDefinition = node.parent.parent;
|
241
247
|
|
242
|
-
if (
|
243
|
-
for (const element of
|
244
|
-
if (element.type === "PropertyDefinition") {
|
248
|
+
if (classDefinition.superClass && !hasSuperCall) {
|
249
|
+
for (const element of classDefinition.body.body) {
|
250
|
+
if (element.type === "PropertyDefinition" && !element.static) {
|
245
251
|
reportIfUnreachable(element);
|
246
252
|
}
|
247
253
|
}
|
248
254
|
}
|
249
255
|
},
|
250
|
-
"MethodDefinition[kind='constructor']"() {
|
251
|
-
if (classInfo) {
|
252
|
-
classInfo.hasConstructor = true;
|
253
|
-
}
|
254
|
-
},
|
255
256
|
"CallExpression > Super.callee"() {
|
256
|
-
if (
|
257
|
-
|
257
|
+
if (constructorInfo) {
|
258
|
+
constructorInfo.hasSuperCall = true;
|
258
259
|
}
|
259
260
|
}
|
260
261
|
};
|
@@ -24,7 +24,6 @@ module.exports = {
|
|
24
24
|
|
25
25
|
docs: {
|
26
26
|
description: "disallow use of optional chaining in contexts where the `undefined` value is not allowed",
|
27
|
-
category: "Possible Errors",
|
28
27
|
recommended: true,
|
29
28
|
url: "https://eslint.org/docs/rules/no-unsafe-optional-chaining"
|
30
29
|
},
|
@@ -30,7 +30,6 @@ module.exports = {
|
|
30
30
|
|
31
31
|
docs: {
|
32
32
|
description: "disallow unused expressions",
|
33
|
-
category: "Best Practices",
|
34
33
|
recommended: false,
|
35
34
|
url: "https://eslint.org/docs/rules/no-unused-expressions"
|
36
35
|
},
|
@@ -72,8 +71,8 @@ module.exports = {
|
|
72
71
|
allowTaggedTemplates = config.allowTaggedTemplates || false,
|
73
72
|
enforceForJSX = config.enforceForJSX || false;
|
74
73
|
|
75
|
-
// eslint-disable-next-line jsdoc/require-description
|
76
74
|
/**
|
75
|
+
* Has AST suggesting a directive.
|
77
76
|
* @param {ASTNode} node any node
|
78
77
|
* @returns {boolean} whether the given node structurally represents a directive
|
79
78
|
*/
|
@@ -82,8 +81,8 @@ module.exports = {
|
|
82
81
|
node.expression.type === "Literal" && typeof node.expression.value === "string";
|
83
82
|
}
|
84
83
|
|
85
|
-
// eslint-disable-next-line jsdoc/require-description
|
86
84
|
/**
|
85
|
+
* Gets the leading sequence of members in a list that pass the predicate.
|
87
86
|
* @param {Function} predicate ([a] -> Boolean) the function used to make the determination
|
88
87
|
* @param {a[]} list the input list
|
89
88
|
* @returns {a[]} the leading sequence of members in the given list that pass the given predicate
|
@@ -97,8 +96,8 @@ module.exports = {
|
|
97
96
|
return list.slice();
|
98
97
|
}
|
99
98
|
|
100
|
-
// eslint-disable-next-line jsdoc/require-description
|
101
99
|
/**
|
100
|
+
* Gets leading directives nodes in a Node body.
|
102
101
|
* @param {ASTNode} node a Program or BlockStatement node
|
103
102
|
* @returns {ASTNode[]} the leading sequence of directive nodes in the given node's body
|
104
103
|
*/
|
@@ -106,8 +105,8 @@ module.exports = {
|
|
106
105
|
return takeWhile(looksLikeDirective, node.body);
|
107
106
|
}
|
108
107
|
|
109
|
-
// eslint-disable-next-line jsdoc/require-description
|
110
108
|
/**
|
109
|
+
* Detect if a Node is a directive.
|
111
110
|
* @param {ASTNode} node any node
|
112
111
|
* @param {ASTNode[]} ancestors the given node's ancestors
|
113
112
|
* @returns {boolean} whether the given node is considered a directive in its current position
|
@@ -33,7 +33,6 @@ module.exports = {
|
|
33
33
|
|
34
34
|
docs: {
|
35
35
|
description: "disallow unused variables",
|
36
|
-
category: "Variables",
|
37
36
|
recommended: true,
|
38
37
|
url: "https://eslint.org/docs/rules/no-unused-vars"
|
39
38
|
},
|
@@ -295,6 +294,31 @@ module.exports = {
|
|
295
294
|
);
|
296
295
|
}
|
297
296
|
|
297
|
+
/**
|
298
|
+
* Checks whether a given node is unused expression or not.
|
299
|
+
* @param {ASTNode} node The node itself
|
300
|
+
* @returns {boolean} The node is an unused expression.
|
301
|
+
* @private
|
302
|
+
*/
|
303
|
+
function isUnusedExpression(node) {
|
304
|
+
const parent = node.parent;
|
305
|
+
|
306
|
+
if (parent.type === "ExpressionStatement") {
|
307
|
+
return true;
|
308
|
+
}
|
309
|
+
|
310
|
+
if (parent.type === "SequenceExpression") {
|
311
|
+
const isLastExpression = parent.expressions[parent.expressions.length - 1] === node;
|
312
|
+
|
313
|
+
if (!isLastExpression) {
|
314
|
+
return true;
|
315
|
+
}
|
316
|
+
return isUnusedExpression(parent);
|
317
|
+
}
|
318
|
+
|
319
|
+
return false;
|
320
|
+
}
|
321
|
+
|
298
322
|
/**
|
299
323
|
* If a given reference is left-hand side of an assignment, this gets
|
300
324
|
* the right-hand side node of the assignment.
|
@@ -313,7 +337,6 @@ module.exports = {
|
|
313
337
|
function getRhsNode(ref, prevRhsNode) {
|
314
338
|
const id = ref.identifier;
|
315
339
|
const parent = id.parent;
|
316
|
-
const grandparent = parent.parent;
|
317
340
|
const refScope = ref.from.variableScope;
|
318
341
|
const varScope = ref.resolved.scope.variableScope;
|
319
342
|
const canBeUsedLater = refScope !== varScope || astUtils.isInLoop(id);
|
@@ -327,7 +350,7 @@ module.exports = {
|
|
327
350
|
}
|
328
351
|
|
329
352
|
if (parent.type === "AssignmentExpression" &&
|
330
|
-
|
353
|
+
isUnusedExpression(parent) &&
|
331
354
|
id === parent.left &&
|
332
355
|
!canBeUsedLater
|
333
356
|
) {
|
@@ -410,31 +433,6 @@ module.exports = {
|
|
410
433
|
);
|
411
434
|
}
|
412
435
|
|
413
|
-
/**
|
414
|
-
* Checks whether a given node is unused expression or not.
|
415
|
-
* @param {ASTNode} node The node itself
|
416
|
-
* @returns {boolean} The node is an unused expression.
|
417
|
-
* @private
|
418
|
-
*/
|
419
|
-
function isUnusedExpression(node) {
|
420
|
-
const parent = node.parent;
|
421
|
-
|
422
|
-
if (parent.type === "ExpressionStatement") {
|
423
|
-
return true;
|
424
|
-
}
|
425
|
-
|
426
|
-
if (parent.type === "SequenceExpression") {
|
427
|
-
const isLastExpression = parent.expressions[parent.expressions.length - 1] === node;
|
428
|
-
|
429
|
-
if (!isLastExpression) {
|
430
|
-
return true;
|
431
|
-
}
|
432
|
-
return isUnusedExpression(parent);
|
433
|
-
}
|
434
|
-
|
435
|
-
return false;
|
436
|
-
}
|
437
|
-
|
438
436
|
/**
|
439
437
|
* Checks whether a given reference is a read to update itself or not.
|
440
438
|
* @param {eslint-scope.Reference} ref A reference to check.
|
@@ -36,6 +36,7 @@ const astUtils = require("./utils/ast-utils");
|
|
36
36
|
* - class C { static ["prototype"]() {} } produces a runtime error (doesn't break the whole script)
|
37
37
|
* class C { static "prototype"() {} } produces a parsing error (breaks the whole script)
|
38
38
|
* @param {ASTNode} node The node to check. It can be `Property`, `PropertyDefinition` or `MethodDefinition`.
|
39
|
+
* @throws {Error} (Unreachable.)
|
39
40
|
* @returns {void} `true` if the node has useless computed key.
|
40
41
|
*/
|
41
42
|
function hasUselessComputedKey(node) {
|
@@ -90,7 +91,6 @@ module.exports = {
|
|
90
91
|
|
91
92
|
docs: {
|
92
93
|
description: "disallow unnecessary computed property keys in objects and classes",
|
93
|
-
category: "ECMAScript 6",
|
94
94
|
recommended: false,
|
95
95
|
url: "https://eslint.org/docs/rules/no-useless-computed-key"
|
96
96
|
},
|
@@ -34,16 +34,17 @@ const REGEX_NON_CHARCLASS_ESCAPES = union(REGEX_GENERAL_ESCAPES, new Set("^/.$*+
|
|
34
34
|
* @returns {Object[]} A list of characters, each with info on escaping and whether they're in a character class.
|
35
35
|
* @example
|
36
36
|
*
|
37
|
-
* parseRegExp(
|
37
|
+
* parseRegExp("a\\b[cd-]");
|
38
38
|
*
|
39
|
-
* returns:
|
39
|
+
* // returns:
|
40
40
|
* [
|
41
|
-
*
|
42
|
-
*
|
43
|
-
*
|
44
|
-
*
|
45
|
-
*
|
46
|
-
* ]
|
41
|
+
* { text: "a", index: 0, escaped: false, inCharClass: false, startsCharClass: false, endsCharClass: false },
|
42
|
+
* { text: "b", index: 2, escaped: true, inCharClass: false, startsCharClass: false, endsCharClass: false },
|
43
|
+
* { text: "c", index: 4, escaped: false, inCharClass: true, startsCharClass: true, endsCharClass: false },
|
44
|
+
* { text: "d", index: 5, escaped: false, inCharClass: true, startsCharClass: false, endsCharClass: false },
|
45
|
+
* { text: "-", index: 6, escaped: false, inCharClass: true, startsCharClass: false, endsCharClass: false }
|
46
|
+
* ];
|
47
|
+
*
|
47
48
|
*/
|
48
49
|
function parseRegExp(regExpText) {
|
49
50
|
const charList = [];
|
@@ -83,7 +84,6 @@ module.exports = {
|
|
83
84
|
|
84
85
|
docs: {
|
85
86
|
description: "disallow unnecessary escape characters",
|
86
|
-
category: "Best Practices",
|
87
87
|
recommended: true,
|
88
88
|
url: "https://eslint.org/docs/rules/no-useless-escape"
|
89
89
|
},
|
package/lib/rules/no-var.js
CHANGED
package/lib/rules/no-void.js
CHANGED
package/lib/rules/no-with.js
CHANGED