eslint 6.5.0 → 6.7.1
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/CHANGELOG.md +115 -0
- package/README.md +10 -9
- package/conf/config-schema.js +1 -0
- package/conf/default-cli-options.js +1 -1
- package/lib/cli-engine/cascading-config-array-factory.js +40 -14
- package/lib/cli-engine/cli-engine.js +49 -21
- package/lib/cli-engine/config-array/config-array.js +13 -4
- package/lib/cli-engine/config-array/config-dependency.js +2 -0
- package/lib/cli-engine/config-array/extracted-config.js +27 -0
- package/lib/cli-engine/config-array/ignore-pattern.js +231 -0
- package/lib/cli-engine/config-array/index.js +2 -0
- package/lib/cli-engine/config-array/override-tester.js +2 -0
- package/lib/cli-engine/config-array-factory.js +120 -2
- package/lib/cli-engine/file-enumerator.js +51 -30
- package/lib/cli-engine/formatters/html.js +1 -0
- package/lib/init/autoconfig.js +1 -11
- package/lib/init/config-file.js +0 -1
- package/lib/init/config-initializer.js +4 -4
- package/lib/init/config-rule.js +1 -5
- package/lib/init/npm-utils.js +0 -5
- package/lib/linter/code-path-analysis/code-path-analyzer.js +24 -38
- package/lib/linter/code-path-analysis/code-path-segment.js +17 -25
- package/lib/linter/code-path-analysis/code-path-state.js +40 -81
- package/lib/linter/code-path-analysis/code-path.js +10 -11
- package/lib/linter/code-path-analysis/debug-helpers.js +8 -12
- package/lib/linter/code-path-analysis/fork-context.js +23 -34
- package/lib/linter/code-path-analysis/id-generator.js +2 -2
- package/lib/linter/linter.js +121 -95
- package/lib/linter/node-event-generator.js +3 -2
- package/lib/linter/report-translator.js +73 -7
- package/lib/rule-tester/rule-tester.js +46 -14
- package/lib/rules/accessor-pairs.js +8 -8
- package/lib/rules/array-bracket-newline.js +12 -15
- package/lib/rules/array-bracket-spacing.js +12 -12
- package/lib/rules/array-callback-return.js +6 -11
- package/lib/rules/array-element-newline.js +5 -8
- package/lib/rules/arrow-parens.js +0 -1
- package/lib/rules/block-scoped-var.js +3 -3
- package/lib/rules/block-spacing.js +4 -4
- package/lib/rules/camelcase.js +19 -6
- package/lib/rules/capitalized-comments.js +0 -7
- package/lib/rules/class-methods-use-this.js +3 -3
- package/lib/rules/comma-dangle.js +20 -25
- package/lib/rules/comma-spacing.js +1 -1
- package/lib/rules/computed-property-spacing.js +14 -14
- package/lib/rules/consistent-return.js +4 -5
- package/lib/rules/consistent-this.js +5 -5
- package/lib/rules/constructor-super.js +14 -16
- package/lib/rules/curly.js +12 -9
- package/lib/rules/default-param-last.js +1 -0
- package/lib/rules/dot-location.js +11 -12
- package/lib/rules/func-names.js +6 -6
- package/lib/rules/function-call-argument-newline.js +8 -6
- package/lib/rules/generator-star-spacing.js +4 -9
- package/lib/rules/getter-return.js +4 -7
- package/lib/rules/grouped-accessor-pairs.js +224 -0
- package/lib/rules/indent.js +13 -2
- package/lib/rules/index.js +5 -0
- package/lib/rules/init-declarations.js +2 -2
- package/lib/rules/jsx-quotes.js +1 -1
- package/lib/rules/keyword-spacing.js +32 -56
- package/lib/rules/lines-around-directive.js +1 -1
- package/lib/rules/max-len.js +0 -5
- package/lib/rules/max-statements-per-line.js +3 -7
- package/lib/rules/multiline-comment-style.js +237 -106
- package/lib/rules/multiline-ternary.js +3 -3
- package/lib/rules/newline-after-var.js +6 -7
- package/lib/rules/newline-before-return.js +8 -9
- package/lib/rules/newline-per-chained-call.js +2 -4
- package/lib/rules/no-class-assign.js +2 -2
- package/lib/rules/no-compare-neg-zero.js +1 -2
- package/lib/rules/no-cond-assign.js +14 -4
- package/lib/rules/no-confusing-arrow.js +2 -2
- package/lib/rules/no-console.js +4 -8
- package/lib/rules/no-const-assign.js +1 -1
- package/lib/rules/no-constructor-return.js +62 -0
- package/lib/rules/no-dupe-args.js +1 -1
- package/lib/rules/no-dupe-class-members.js +3 -4
- package/lib/rules/no-dupe-else-if.js +122 -0
- package/lib/rules/no-dupe-keys.js +6 -5
- package/lib/rules/no-duplicate-imports.js +14 -18
- package/lib/rules/no-else-return.js +0 -8
- package/lib/rules/no-empty-function.js +2 -4
- package/lib/rules/no-eval.js +10 -18
- package/lib/rules/no-ex-assign.js +1 -1
- package/lib/rules/no-extra-bind.js +5 -12
- package/lib/rules/no-extra-boolean-cast.js +0 -2
- package/lib/rules/no-extra-label.js +4 -9
- package/lib/rules/no-extra-parens.js +17 -15
- package/lib/rules/no-extra-semi.js +5 -6
- package/lib/rules/no-fallthrough.js +6 -6
- package/lib/rules/no-func-assign.js +3 -3
- package/lib/rules/no-global-assign.js +4 -4
- package/lib/rules/no-implicit-coercion.js +10 -10
- package/lib/rules/no-implicit-globals.js +90 -8
- package/lib/rules/no-implied-eval.js +0 -1
- package/lib/rules/no-inline-comments.js +25 -11
- package/lib/rules/no-invalid-this.js +17 -5
- package/lib/rules/no-labels.js +3 -6
- package/lib/rules/no-lone-blocks.js +1 -1
- package/lib/rules/no-loop-func.js +6 -11
- package/lib/rules/no-magic-numbers.js +6 -6
- package/lib/rules/no-misleading-character-class.js +14 -7
- package/lib/rules/no-mixed-operators.js +13 -22
- package/lib/rules/no-mixed-requires.js +0 -1
- package/lib/rules/no-multi-spaces.js +1 -1
- package/lib/rules/no-native-reassign.js +4 -4
- package/lib/rules/no-octal-escape.js +1 -1
- package/lib/rules/no-param-reassign.js +28 -7
- package/lib/rules/no-redeclare.js +1 -1
- package/lib/rules/no-regex-spaces.js +0 -1
- package/lib/rules/no-restricted-imports.js +11 -11
- package/lib/rules/no-self-assign.js +12 -13
- package/lib/rules/no-sequences.js +3 -3
- package/lib/rules/no-setter-return.js +227 -0
- package/lib/rules/no-shadow.js +1 -4
- package/lib/rules/no-tabs.js +8 -2
- package/lib/rules/no-this-before-super.js +12 -13
- package/lib/rules/no-trailing-spaces.js +19 -7
- package/lib/rules/no-underscore-dangle.js +23 -4
- package/lib/rules/no-unmodified-loop-condition.js +16 -29
- package/lib/rules/no-unneeded-ternary.js +3 -3
- package/lib/rules/no-unreachable.js +7 -7
- package/lib/rules/no-unsafe-finally.js +4 -7
- package/lib/rules/no-unsafe-negation.js +32 -9
- package/lib/rules/no-unused-expressions.js +11 -7
- package/lib/rules/no-unused-labels.js +3 -6
- package/lib/rules/no-unused-vars.js +22 -29
- package/lib/rules/no-use-before-define.js +10 -15
- package/lib/rules/no-useless-call.js +4 -4
- package/lib/rules/no-useless-computed-key.js +60 -33
- package/lib/rules/no-useless-concat.js +4 -4
- package/lib/rules/no-useless-constructor.js +14 -22
- package/lib/rules/no-useless-escape.js +29 -8
- package/lib/rules/no-useless-rename.js +15 -7
- package/lib/rules/no-useless-return.js +8 -15
- package/lib/rules/no-var.js +12 -25
- package/lib/rules/no-warning-comments.js +0 -1
- package/lib/rules/no-whitespace-before-property.js +3 -3
- package/lib/rules/object-curly-newline.js +7 -10
- package/lib/rules/object-curly-spacing.js +21 -22
- package/lib/rules/object-shorthand.js +1 -1
- package/lib/rules/one-var-declaration-per-line.js +2 -2
- package/lib/rules/operator-assignment.js +33 -3
- package/lib/rules/padded-blocks.js +1 -1
- package/lib/rules/padding-line-between-statements.js +0 -16
- package/lib/rules/prefer-arrow-callback.js +6 -6
- package/lib/rules/prefer-const.js +27 -28
- package/lib/rules/prefer-destructuring.js +1 -7
- package/lib/rules/prefer-exponentiation-operator.js +189 -0
- package/lib/rules/prefer-named-capture-group.js +0 -1
- package/lib/rules/prefer-numeric-literals.js +32 -4
- package/lib/rules/prefer-object-spread.js +7 -7
- package/lib/rules/prefer-rest-params.js +3 -6
- package/lib/rules/prefer-spread.js +4 -4
- package/lib/rules/prefer-template.js +5 -6
- package/lib/rules/quote-props.js +1 -1
- package/lib/rules/quotes.js +5 -6
- package/lib/rules/radix.js +5 -10
- package/lib/rules/require-await.js +10 -5
- package/lib/rules/require-yield.js +2 -2
- package/lib/rules/rest-spread-spacing.js +1 -1
- package/lib/rules/semi.js +6 -3
- package/lib/rules/sort-imports.js +3 -4
- package/lib/rules/sort-keys.js +1 -3
- package/lib/rules/space-before-blocks.js +1 -2
- package/lib/rules/space-in-parens.js +4 -4
- package/lib/rules/space-infix-ops.js +6 -6
- package/lib/rules/spaced-comment.js +20 -22
- package/lib/rules/strict.js +2 -4
- package/lib/rules/symbol-description.js +1 -2
- package/lib/rules/template-curly-spacing.js +2 -2
- package/lib/rules/use-isnan.js +40 -3
- package/lib/rules/utils/ast-utils.js +84 -85
- package/lib/rules/utils/fix-tracker.js +0 -6
- package/lib/rules/utils/lazy-loading-rule-map.js +0 -1
- package/lib/rules/vars-on-top.js +11 -11
- package/lib/shared/config-ops.js +2 -2
- package/lib/shared/runtime-info.js +8 -8
- package/lib/shared/traverser.js +2 -0
- package/lib/shared/types.js +9 -0
- package/lib/source-code/source-code.js +62 -17
- package/lib/source-code/token-store/backward-token-comment-cursor.js +5 -5
- package/lib/source-code/token-store/backward-token-cursor.js +5 -5
- package/lib/source-code/token-store/cursors.js +17 -19
- package/lib/source-code/token-store/decorative-cursor.js +1 -1
- package/lib/source-code/token-store/filter-cursor.js +2 -2
- package/lib/source-code/token-store/forward-token-comment-cursor.js +5 -5
- package/lib/source-code/token-store/forward-token-cursor.js +5 -5
- package/lib/source-code/token-store/index.js +86 -92
- package/lib/source-code/token-store/limit-cursor.js +2 -2
- package/lib/source-code/token-store/padded-token-cursor.js +7 -7
- package/lib/source-code/token-store/skip-cursor.js +2 -2
- package/lib/source-code/token-store/utils.js +9 -13
- package/package.json +9 -7
- package/lib/cli-engine/ignored-paths.js +0 -362
@@ -10,8 +10,7 @@
|
|
10
10
|
|
11
11
|
/**
|
12
12
|
* Checks whether a given array of statements is a single call of `super`.
|
13
|
-
*
|
14
|
-
* @param {ASTNode[]} body - An array of statements to check.
|
13
|
+
* @param {ASTNode[]} body An array of statements to check.
|
15
14
|
* @returns {boolean} `true` if the body is a single call of `super`.
|
16
15
|
*/
|
17
16
|
function isSingleSuperCall(body) {
|
@@ -26,8 +25,7 @@ function isSingleSuperCall(body) {
|
|
26
25
|
/**
|
27
26
|
* Checks whether a given node is a pattern which doesn't have any side effects.
|
28
27
|
* Default parameters and Destructuring parameters can have side effects.
|
29
|
-
*
|
30
|
-
* @param {ASTNode} node - A pattern node.
|
28
|
+
* @param {ASTNode} node A pattern node.
|
31
29
|
* @returns {boolean} `true` if the node doesn't have any side effects.
|
32
30
|
*/
|
33
31
|
function isSimple(node) {
|
@@ -37,8 +35,7 @@ function isSimple(node) {
|
|
37
35
|
/**
|
38
36
|
* Checks whether a given array of expressions is `...arguments` or not.
|
39
37
|
* `super(...arguments)` passes all arguments through.
|
40
|
-
*
|
41
|
-
* @param {ASTNode[]} superArgs - An array of expressions to check.
|
38
|
+
* @param {ASTNode[]} superArgs An array of expressions to check.
|
42
39
|
* @returns {boolean} `true` if the superArgs is `...arguments`.
|
43
40
|
*/
|
44
41
|
function isSpreadArguments(superArgs) {
|
@@ -52,9 +49,8 @@ function isSpreadArguments(superArgs) {
|
|
52
49
|
|
53
50
|
/**
|
54
51
|
* Checks whether given 2 nodes are identifiers which have the same name or not.
|
55
|
-
*
|
56
|
-
* @param {ASTNode}
|
57
|
-
* @param {ASTNode} superArg - A node to check.
|
52
|
+
* @param {ASTNode} ctorParam A node to check.
|
53
|
+
* @param {ASTNode} superArg A node to check.
|
58
54
|
* @returns {boolean} `true` if the nodes are identifiers which have the same
|
59
55
|
* name.
|
60
56
|
*/
|
@@ -68,9 +64,8 @@ function isValidIdentifierPair(ctorParam, superArg) {
|
|
68
64
|
|
69
65
|
/**
|
70
66
|
* Checks whether given 2 nodes are a rest/spread pair which has the same values.
|
71
|
-
*
|
72
|
-
* @param {ASTNode}
|
73
|
-
* @param {ASTNode} superArg - A node to check.
|
67
|
+
* @param {ASTNode} ctorParam A node to check.
|
68
|
+
* @param {ASTNode} superArg A node to check.
|
74
69
|
* @returns {boolean} `true` if the nodes are a rest/spread pair which has the
|
75
70
|
* same values.
|
76
71
|
*/
|
@@ -84,9 +79,8 @@ function isValidRestSpreadPair(ctorParam, superArg) {
|
|
84
79
|
|
85
80
|
/**
|
86
81
|
* Checks whether given 2 nodes have the same value or not.
|
87
|
-
*
|
88
|
-
* @param {ASTNode}
|
89
|
-
* @param {ASTNode} superArg - A node to check.
|
82
|
+
* @param {ASTNode} ctorParam A node to check.
|
83
|
+
* @param {ASTNode} superArg A node to check.
|
90
84
|
* @returns {boolean} `true` if the nodes have the same value or not.
|
91
85
|
*/
|
92
86
|
function isValidPair(ctorParam, superArg) {
|
@@ -99,9 +93,8 @@ function isValidPair(ctorParam, superArg) {
|
|
99
93
|
/**
|
100
94
|
* Checks whether the parameters of a constructor and the arguments of `super()`
|
101
95
|
* have the same values or not.
|
102
|
-
*
|
103
|
-
* @param {ASTNode}
|
104
|
-
* @param {ASTNode} superArgs - The arguments of `super()` to check.
|
96
|
+
* @param {ASTNode} ctorParams The parameters of a constructor to check.
|
97
|
+
* @param {ASTNode} superArgs The arguments of `super()` to check.
|
105
98
|
* @returns {boolean} `true` if those have the same values.
|
106
99
|
*/
|
107
100
|
function isPassingThrough(ctorParams, superArgs) {
|
@@ -120,9 +113,8 @@ function isPassingThrough(ctorParams, superArgs) {
|
|
120
113
|
|
121
114
|
/**
|
122
115
|
* Checks whether the constructor body is a redundant super call.
|
123
|
-
*
|
124
|
-
* @param {Array}
|
125
|
-
* @param {Array} ctorParams - The params to check against super call.
|
116
|
+
* @param {Array} body constructor body content.
|
117
|
+
* @param {Array} ctorParams The params to check against super call.
|
126
118
|
* @returns {boolean} true if the construtor body is redundant
|
127
119
|
*/
|
128
120
|
function isRedundantSuperCall(body, ctorParams) {
|
@@ -158,7 +150,7 @@ module.exports = {
|
|
158
150
|
|
159
151
|
/**
|
160
152
|
* Checks whether a node is a redundant constructor
|
161
|
-
* @param {ASTNode} node
|
153
|
+
* @param {ASTNode} node node to check
|
162
154
|
* @returns {void}
|
163
155
|
*/
|
164
156
|
function checkForConstructor(node) {
|
@@ -85,7 +85,14 @@ module.exports = {
|
|
85
85
|
description: "disallow unnecessary escape characters",
|
86
86
|
category: "Best Practices",
|
87
87
|
recommended: true,
|
88
|
-
url: "https://eslint.org/docs/rules/no-useless-escape"
|
88
|
+
url: "https://eslint.org/docs/rules/no-useless-escape",
|
89
|
+
suggestion: true
|
90
|
+
},
|
91
|
+
|
92
|
+
messages: {
|
93
|
+
unnecessaryEscape: "Unnecessary escape character: \\{{character}}.",
|
94
|
+
removeEscape: "Remove the `\\`. This maintains the current functionality.",
|
95
|
+
escapeBackslash: "Replace the `\\` with `\\\\` to include the actual backslash character."
|
89
96
|
},
|
90
97
|
|
91
98
|
schema: []
|
@@ -103,6 +110,8 @@ module.exports = {
|
|
103
110
|
*/
|
104
111
|
function report(node, startOffset, character) {
|
105
112
|
const start = sourceCode.getLocFromIndex(sourceCode.getIndexFromLoc(node.loc.start) + startOffset);
|
113
|
+
const rangeStart = sourceCode.getIndexFromLoc(node.loc.start) + startOffset;
|
114
|
+
const range = [rangeStart, rangeStart + 1];
|
106
115
|
|
107
116
|
context.report({
|
108
117
|
node,
|
@@ -110,17 +119,30 @@ module.exports = {
|
|
110
119
|
start,
|
111
120
|
end: { line: start.line, column: start.column + 1 }
|
112
121
|
},
|
113
|
-
|
114
|
-
data: { character }
|
122
|
+
messageId: "unnecessaryEscape",
|
123
|
+
data: { character },
|
124
|
+
suggest: [
|
125
|
+
{
|
126
|
+
messageId: "removeEscape",
|
127
|
+
fix(fixer) {
|
128
|
+
return fixer.removeRange(range);
|
129
|
+
}
|
130
|
+
},
|
131
|
+
{
|
132
|
+
messageId: "escapeBackslash",
|
133
|
+
fix(fixer) {
|
134
|
+
return fixer.insertTextBeforeRange(range, "\\");
|
135
|
+
}
|
136
|
+
}
|
137
|
+
]
|
115
138
|
});
|
116
139
|
}
|
117
140
|
|
118
141
|
/**
|
119
142
|
* Checks if the escape character in given string slice is unnecessary.
|
120
|
-
*
|
121
143
|
* @private
|
122
|
-
* @param {ASTNode} node
|
123
|
-
* @param {string} match
|
144
|
+
* @param {ASTNode} node node to validate.
|
145
|
+
* @param {string} match string slice to validate.
|
124
146
|
* @returns {void}
|
125
147
|
*/
|
126
148
|
function validateString(node, match) {
|
@@ -156,8 +178,7 @@ module.exports = {
|
|
156
178
|
|
157
179
|
/**
|
158
180
|
* Checks if a node has an escape.
|
159
|
-
*
|
160
|
-
* @param {ASTNode} node - node to check.
|
181
|
+
* @param {ASTNode} node node to check.
|
161
182
|
* @returns {void}
|
162
183
|
*/
|
163
184
|
function check(node) {
|
@@ -48,10 +48,10 @@ module.exports = {
|
|
48
48
|
|
49
49
|
/**
|
50
50
|
* Reports error for unnecessarily renamed assignments
|
51
|
-
* @param {ASTNode} node
|
52
|
-
* @param {ASTNode} initial
|
53
|
-
* @param {ASTNode} result
|
54
|
-
* @param {string} type
|
51
|
+
* @param {ASTNode} node node to report
|
52
|
+
* @param {ASTNode} initial node with initial name value
|
53
|
+
* @param {ASTNode} result node with new name value
|
54
|
+
* @param {string} type the type of the offending node
|
55
55
|
* @returns {void}
|
56
56
|
*/
|
57
57
|
function reportError(node, initial, result, type) {
|
@@ -83,7 +83,7 @@ module.exports = {
|
|
83
83
|
|
84
84
|
/**
|
85
85
|
* Checks whether a destructured assignment is unnecessarily renamed
|
86
|
-
* @param {ASTNode} node
|
86
|
+
* @param {ASTNode} node node to check
|
87
87
|
* @returns {void}
|
88
88
|
*/
|
89
89
|
function checkDestructured(node) {
|
@@ -93,6 +93,14 @@ module.exports = {
|
|
93
93
|
|
94
94
|
for (const property of node.properties) {
|
95
95
|
|
96
|
+
/*
|
97
|
+
* TODO: Remove after babel-eslint removes ExperimentalRestProperty
|
98
|
+
* https://github.com/eslint/eslint/issues/12335
|
99
|
+
*/
|
100
|
+
if (property.type === "ExperimentalRestProperty") {
|
101
|
+
continue;
|
102
|
+
}
|
103
|
+
|
96
104
|
/**
|
97
105
|
* Properties using shorthand syntax and rest elements can not be renamed.
|
98
106
|
* If the property is computed, we have no idea if a rename is useless or not.
|
@@ -112,7 +120,7 @@ module.exports = {
|
|
112
120
|
|
113
121
|
/**
|
114
122
|
* Checks whether an import is unnecessarily renamed
|
115
|
-
* @param {ASTNode} node
|
123
|
+
* @param {ASTNode} node node to check
|
116
124
|
* @returns {void}
|
117
125
|
*/
|
118
126
|
function checkImport(node) {
|
@@ -128,7 +136,7 @@ module.exports = {
|
|
128
136
|
|
129
137
|
/**
|
130
138
|
* Checks whether an export is unnecessarily renamed
|
131
|
-
* @param {ASTNode} node
|
139
|
+
* @param {ASTNode} node node to check
|
132
140
|
* @returns {void}
|
133
141
|
*/
|
134
142
|
function checkExport(node) {
|
@@ -17,9 +17,8 @@ const astUtils = require("./utils/ast-utils"),
|
|
17
17
|
|
18
18
|
/**
|
19
19
|
* Removes the given element from the array.
|
20
|
-
*
|
21
|
-
* @param {
|
22
|
-
* @param {any} element - The target item to remove.
|
20
|
+
* @param {Array} array The source array to remove.
|
21
|
+
* @param {any} element The target item to remove.
|
23
22
|
* @returns {void}
|
24
23
|
*/
|
25
24
|
function remove(array, element) {
|
@@ -32,8 +31,7 @@ function remove(array, element) {
|
|
32
31
|
|
33
32
|
/**
|
34
33
|
* Checks whether it can remove the given return statement or not.
|
35
|
-
*
|
36
|
-
* @param {ASTNode} node - The return statement node to check.
|
34
|
+
* @param {ASTNode} node The return statement node to check.
|
37
35
|
* @returns {boolean} `true` if the node is removeable.
|
38
36
|
*/
|
39
37
|
function isRemovable(node) {
|
@@ -42,8 +40,7 @@ function isRemovable(node) {
|
|
42
40
|
|
43
41
|
/**
|
44
42
|
* Checks whether the given return statement is in a `finally` block or not.
|
45
|
-
*
|
46
|
-
* @param {ASTNode} node - The return statement node to check.
|
43
|
+
* @param {ASTNode} node The return statement node to check.
|
47
44
|
* @returns {boolean} `true` if the node is in a `finally` block.
|
48
45
|
*/
|
49
46
|
function isInFinally(node) {
|
@@ -87,8 +84,7 @@ module.exports = {
|
|
87
84
|
|
88
85
|
/**
|
89
86
|
* Checks whether the given segment is terminated by a return statement or not.
|
90
|
-
*
|
91
|
-
* @param {CodePathSegment} segment - The segment to check.
|
87
|
+
* @param {CodePathSegment} segment The segment to check.
|
92
88
|
* @returns {boolean} `true` if the segment is terminated by a return statement, or if it's still a part of unreachable.
|
93
89
|
*/
|
94
90
|
function isReturned(segment) {
|
@@ -110,9 +106,8 @@ module.exports = {
|
|
110
106
|
*
|
111
107
|
* This behavior would simulate code paths for the case that the return
|
112
108
|
* statement does not exist.
|
113
|
-
*
|
114
|
-
* @param {
|
115
|
-
* @param {CodePathSegment[]} prevSegments - The previous segments to traverse.
|
109
|
+
* @param {ASTNode[]} uselessReturns The collected return statements.
|
110
|
+
* @param {CodePathSegment[]} prevSegments The previous segments to traverse.
|
116
111
|
* @param {WeakSet<CodePathSegment>} [providedTraversedSegments] A set of segments that have already been traversed in this call
|
117
112
|
* @returns {ASTNode[]} `uselessReturns`.
|
118
113
|
*/
|
@@ -152,8 +147,7 @@ module.exports = {
|
|
152
147
|
*
|
153
148
|
* This behavior would simulate code paths for the case that the return
|
154
149
|
* statement does not exist.
|
155
|
-
*
|
156
|
-
* @param {CodePathSegment} segment - The segment to get return statements.
|
150
|
+
* @param {CodePathSegment} segment The segment to get return statements.
|
157
151
|
* @returns {void}
|
158
152
|
*/
|
159
153
|
function markReturnStatementsOnSegmentAsUsed(segment) {
|
@@ -184,7 +178,6 @@ module.exports = {
|
|
184
178
|
* - FunctionDeclarations are always executed whether it's returned or not.
|
185
179
|
* - BlockStatements do nothing.
|
186
180
|
* - BreakStatements go the next merely.
|
187
|
-
*
|
188
181
|
* @returns {void}
|
189
182
|
*/
|
190
183
|
function markReturnStatementsOnCurrentSegmentsAsUsed() {
|
package/lib/rules/no-var.js
CHANGED
@@ -27,8 +27,7 @@ function isGlobal(variable) {
|
|
27
27
|
/**
|
28
28
|
* Finds the nearest function scope or global scope walking up the scope
|
29
29
|
* hierarchy.
|
30
|
-
*
|
31
|
-
* @param {eslint-scope.Scope} scope - The scope to traverse.
|
30
|
+
* @param {eslint-scope.Scope} scope The scope to traverse.
|
32
31
|
* @returns {eslint-scope.Scope} a function scope or global scope containing the given
|
33
32
|
* scope.
|
34
33
|
*/
|
@@ -44,8 +43,7 @@ function getEnclosingFunctionScope(scope) {
|
|
44
43
|
/**
|
45
44
|
* Checks whether the given variable has any references from a more specific
|
46
45
|
* function expression (i.e. a closure).
|
47
|
-
*
|
48
|
-
* @param {eslint-scope.Variable} variable - A variable to check.
|
46
|
+
* @param {eslint-scope.Variable} variable A variable to check.
|
49
47
|
* @returns {boolean} `true` if the variable is used from a closure.
|
50
48
|
*/
|
51
49
|
function isReferencedInClosure(variable) {
|
@@ -57,8 +55,7 @@ function isReferencedInClosure(variable) {
|
|
57
55
|
|
58
56
|
/**
|
59
57
|
* Checks whether the given node is the assignee of a loop.
|
60
|
-
*
|
61
|
-
* @param {ASTNode} node - A VariableDeclaration node to check.
|
58
|
+
* @param {ASTNode} node A VariableDeclaration node to check.
|
62
59
|
* @returns {boolean} `true` if the declaration is assigned as part of loop
|
63
60
|
* iteration.
|
64
61
|
*/
|
@@ -69,8 +66,7 @@ function isLoopAssignee(node) {
|
|
69
66
|
|
70
67
|
/**
|
71
68
|
* Checks whether the given variable declaration is immediately initialized.
|
72
|
-
*
|
73
|
-
* @param {ASTNode} node - A VariableDeclaration node to check.
|
69
|
+
* @param {ASTNode} node A VariableDeclaration node to check.
|
74
70
|
* @returns {boolean} `true` if the declaration has an initializer.
|
75
71
|
*/
|
76
72
|
function isDeclarationInitialized(node) {
|
@@ -81,8 +77,7 @@ const SCOPE_NODE_TYPE = /^(?:Program|BlockStatement|SwitchStatement|ForStatement
|
|
81
77
|
|
82
78
|
/**
|
83
79
|
* Gets the scope node which directly contains a given node.
|
84
|
-
*
|
85
|
-
* @param {ASTNode} node - A node to get. This is a `VariableDeclaration` or
|
80
|
+
* @param {ASTNode} node A node to get. This is a `VariableDeclaration` or
|
86
81
|
* an `Identifier`.
|
87
82
|
* @returns {ASTNode} A scope node. This is one of `Program`, `BlockStatement`,
|
88
83
|
* `SwitchStatement`, `ForStatement`, `ForInStatement`, and
|
@@ -101,8 +96,7 @@ function getScopeNode(node) {
|
|
101
96
|
|
102
97
|
/**
|
103
98
|
* Checks whether a given variable is redeclared or not.
|
104
|
-
*
|
105
|
-
* @param {eslint-scope.Variable} variable - A variable to check.
|
99
|
+
* @param {eslint-scope.Variable} variable A variable to check.
|
106
100
|
* @returns {boolean} `true` if the variable is redeclared.
|
107
101
|
*/
|
108
102
|
function isRedeclared(variable) {
|
@@ -111,8 +105,7 @@ function isRedeclared(variable) {
|
|
111
105
|
|
112
106
|
/**
|
113
107
|
* Checks whether a given variable is used from outside of the specified scope.
|
114
|
-
*
|
115
|
-
* @param {ASTNode} scopeNode - A scope node to check.
|
108
|
+
* @param {ASTNode} scopeNode A scope node to check.
|
116
109
|
* @returns {Function} The predicate function which checks whether a given
|
117
110
|
* variable is used from outside of the specified scope.
|
118
111
|
*/
|
@@ -120,8 +113,7 @@ function isUsedFromOutsideOf(scopeNode) {
|
|
120
113
|
|
121
114
|
/**
|
122
115
|
* Checks whether a given reference is inside of the specified scope or not.
|
123
|
-
*
|
124
|
-
* @param {eslint-scope.Reference} reference - A reference to check.
|
116
|
+
* @param {eslint-scope.Reference} reference A reference to check.
|
125
117
|
* @returns {boolean} `true` if the reference is inside of the specified
|
126
118
|
* scope.
|
127
119
|
*/
|
@@ -145,8 +137,7 @@ function isUsedFromOutsideOf(scopeNode) {
|
|
145
137
|
* - if a reference is before the declarator. E.g. (var a = b, b = 1;)(var {a = b, b} = {};)
|
146
138
|
* - if a reference is in the expression of their default value. E.g. (var {a = a} = {};)
|
147
139
|
* - if a reference is in the expression of their initializer. E.g. (var a = a;)
|
148
|
-
*
|
149
|
-
* @param {ASTNode} node - The initializer node of VariableDeclarator.
|
140
|
+
* @param {ASTNode} node The initializer node of VariableDeclarator.
|
150
141
|
* @returns {Function} The predicate function.
|
151
142
|
* @private
|
152
143
|
*/
|
@@ -177,7 +168,6 @@ function hasReferenceInTDZ(node) {
|
|
177
168
|
/**
|
178
169
|
* Checks whether a given variable has name that is allowed for 'var' declarations,
|
179
170
|
* but disallowed for `let` declarations.
|
180
|
-
*
|
181
171
|
* @param {eslint-scope.Variable} variable The variable to check.
|
182
172
|
* @returns {boolean} `true` if the variable has a disallowed name.
|
183
173
|
*/
|
@@ -209,8 +199,7 @@ module.exports = {
|
|
209
199
|
|
210
200
|
/**
|
211
201
|
* Checks whether the variables which are defined by the given declarator node have their references in TDZ.
|
212
|
-
*
|
213
|
-
* @param {ASTNode} declarator - The VariableDeclarator node to check.
|
202
|
+
* @param {ASTNode} declarator The VariableDeclarator node to check.
|
214
203
|
* @returns {boolean} `true` if one of the variables which are defined by the given declarator node have their references in TDZ.
|
215
204
|
*/
|
216
205
|
function hasSelfReferenceInTDZ(declarator) {
|
@@ -271,8 +260,7 @@ module.exports = {
|
|
271
260
|
* the implementation simple, we only convert `var` to `let` within
|
272
261
|
* loops when the variable is a loop assignee or the declaration has an
|
273
262
|
* initializer.
|
274
|
-
*
|
275
|
-
* @param {ASTNode} node - A variable declaration node to check.
|
263
|
+
* @param {ASTNode} node A variable declaration node to check.
|
276
264
|
* @returns {boolean} `true` if it can fix the node.
|
277
265
|
*/
|
278
266
|
function canFix(node) {
|
@@ -313,8 +301,7 @@ module.exports = {
|
|
313
301
|
|
314
302
|
/**
|
315
303
|
* Reports a given variable declaration node.
|
316
|
-
*
|
317
|
-
* @param {ASTNode} node - A variable declaration node to report.
|
304
|
+
* @param {ASTNode} node A variable declaration node to report.
|
318
305
|
* @returns {void}
|
319
306
|
*/
|
320
307
|
function report(node) {
|
@@ -54,7 +54,6 @@ module.exports = {
|
|
54
54
|
* Convert a warning term into a RegExp which will match a comment containing that whole word in the specified
|
55
55
|
* location ("start" or "anywhere"). If the term starts or ends with non word characters, then the match will not
|
56
56
|
* require word boundaries on that side.
|
57
|
-
*
|
58
57
|
* @param {string} term A term to convert to a RegExp
|
59
58
|
* @returns {RegExp} The term converted to a RegExp
|
60
59
|
*/
|
@@ -38,9 +38,9 @@ module.exports = {
|
|
38
38
|
|
39
39
|
/**
|
40
40
|
* Reports whitespace before property token
|
41
|
-
* @param {ASTNode} node
|
42
|
-
* @param {Token} leftToken
|
43
|
-
* @param {Token} rightToken
|
41
|
+
* @param {ASTNode} node the node to report in the event of an error
|
42
|
+
* @param {Token} leftToken the left token
|
43
|
+
* @param {Token} rightToken the right token
|
44
44
|
* @returns {void}
|
45
45
|
* @private
|
46
46
|
*/
|
@@ -44,8 +44,7 @@ const OPTION_VALUE = {
|
|
44
44
|
|
45
45
|
/**
|
46
46
|
* Normalizes a given option value.
|
47
|
-
*
|
48
|
-
* @param {string|Object|undefined} value - An option value to parse.
|
47
|
+
* @param {string|Object|undefined} value An option value to parse.
|
49
48
|
* @returns {{multiline: boolean, minProperties: number, consistent: boolean}} Normalized option object.
|
50
49
|
*/
|
51
50
|
function normalizeOptionValue(value) {
|
@@ -72,8 +71,7 @@ function normalizeOptionValue(value) {
|
|
72
71
|
|
73
72
|
/**
|
74
73
|
* Normalizes a given option value.
|
75
|
-
*
|
76
|
-
* @param {string|Object|undefined} options - An option value to parse.
|
74
|
+
* @param {string|Object|undefined} options An option value to parse.
|
77
75
|
* @returns {{
|
78
76
|
* ObjectExpression: {multiline: boolean, minProperties: number, consistent: boolean},
|
79
77
|
* ObjectPattern: {multiline: boolean, minProperties: number, consistent: boolean},
|
@@ -101,11 +99,10 @@ function normalizeOptions(options) {
|
|
101
99
|
/**
|
102
100
|
* Determines if ObjectExpression, ObjectPattern, ImportDeclaration or ExportNamedDeclaration
|
103
101
|
* node needs to be checked for missing line breaks
|
104
|
-
*
|
105
|
-
* @param {
|
106
|
-
* @param {
|
107
|
-
* @param {Token}
|
108
|
-
* @param {Token} last - Last object property
|
102
|
+
* @param {ASTNode} node Node under inspection
|
103
|
+
* @param {Object} options option specific to node type
|
104
|
+
* @param {Token} first First object property
|
105
|
+
* @param {Token} last Last object property
|
109
106
|
* @returns {boolean} `true` if node needs to be checked for missing line breaks
|
110
107
|
*/
|
111
108
|
function areLineBreaksRequired(node, options, first, last) {
|
@@ -171,7 +168,7 @@ module.exports = {
|
|
171
168
|
|
172
169
|
/**
|
173
170
|
* Reports a given node if it violated this rule.
|
174
|
-
* @param {ASTNode} node
|
171
|
+
* @param {ASTNode} node A node to check. This is an ObjectExpression, ObjectPattern, ImportDeclaration or ExportNamedDeclaration node.
|
175
172
|
* @returns {void}
|
176
173
|
*/
|
177
174
|
function check(node) {
|
@@ -50,7 +50,7 @@ module.exports = {
|
|
50
50
|
* Determines whether an option is set, relative to the spacing option.
|
51
51
|
* If spaced is "always", then check whether option is set to false.
|
52
52
|
* If spaced is "never", then check whether option is set to true.
|
53
|
-
* @param {Object} option
|
53
|
+
* @param {Object} option The option to exclude.
|
54
54
|
* @returns {boolean} Whether or not the property is excluded.
|
55
55
|
*/
|
56
56
|
function isOptionSet(option) {
|
@@ -69,21 +69,21 @@ module.exports = {
|
|
69
69
|
|
70
70
|
/**
|
71
71
|
* Reports that there shouldn't be a space after the first token
|
72
|
-
* @param {ASTNode} node
|
73
|
-
* @param {Token} token
|
72
|
+
* @param {ASTNode} node The node to report in the event of an error.
|
73
|
+
* @param {Token} token The token to use for the report.
|
74
74
|
* @returns {void}
|
75
75
|
*/
|
76
76
|
function reportNoBeginningSpace(node, token) {
|
77
|
+
const nextToken = context.getSourceCode().getTokenAfter(token, { includeComments: true });
|
78
|
+
|
77
79
|
context.report({
|
78
80
|
node,
|
79
|
-
loc: token.loc.start,
|
81
|
+
loc: { start: token.loc.end, end: nextToken.loc.start },
|
80
82
|
message: "There should be no space after '{{token}}'.",
|
81
83
|
data: {
|
82
84
|
token: token.value
|
83
85
|
},
|
84
86
|
fix(fixer) {
|
85
|
-
const nextToken = context.getSourceCode().getTokenAfter(token, { includeComments: true });
|
86
|
-
|
87
87
|
return fixer.removeRange([token.range[1], nextToken.range[0]]);
|
88
88
|
}
|
89
89
|
});
|
@@ -91,21 +91,21 @@ module.exports = {
|
|
91
91
|
|
92
92
|
/**
|
93
93
|
* Reports that there shouldn't be a space before the last token
|
94
|
-
* @param {ASTNode} node
|
95
|
-
* @param {Token} token
|
94
|
+
* @param {ASTNode} node The node to report in the event of an error.
|
95
|
+
* @param {Token} token The token to use for the report.
|
96
96
|
* @returns {void}
|
97
97
|
*/
|
98
98
|
function reportNoEndingSpace(node, token) {
|
99
|
+
const previousToken = context.getSourceCode().getTokenBefore(token, { includeComments: true });
|
100
|
+
|
99
101
|
context.report({
|
100
102
|
node,
|
101
|
-
loc: token.loc.start,
|
103
|
+
loc: { start: previousToken.loc.end, end: token.loc.start },
|
102
104
|
message: "There should be no space before '{{token}}'.",
|
103
105
|
data: {
|
104
106
|
token: token.value
|
105
107
|
},
|
106
108
|
fix(fixer) {
|
107
|
-
const previousToken = context.getSourceCode().getTokenBefore(token, { includeComments: true });
|
108
|
-
|
109
109
|
return fixer.removeRange([previousToken.range[1], token.range[0]]);
|
110
110
|
}
|
111
111
|
});
|
@@ -113,14 +113,14 @@ module.exports = {
|
|
113
113
|
|
114
114
|
/**
|
115
115
|
* Reports that there should be a space after the first token
|
116
|
-
* @param {ASTNode} node
|
117
|
-
* @param {Token} token
|
116
|
+
* @param {ASTNode} node The node to report in the event of an error.
|
117
|
+
* @param {Token} token The token to use for the report.
|
118
118
|
* @returns {void}
|
119
119
|
*/
|
120
120
|
function reportRequiredBeginningSpace(node, token) {
|
121
121
|
context.report({
|
122
122
|
node,
|
123
|
-
loc: token.loc
|
123
|
+
loc: token.loc,
|
124
124
|
message: "A space is required after '{{token}}'.",
|
125
125
|
data: {
|
126
126
|
token: token.value
|
@@ -133,14 +133,14 @@ module.exports = {
|
|
133
133
|
|
134
134
|
/**
|
135
135
|
* Reports that there should be a space before the last token
|
136
|
-
* @param {ASTNode} node
|
137
|
-
* @param {Token} token
|
136
|
+
* @param {ASTNode} node The node to report in the event of an error.
|
137
|
+
* @param {Token} token The token to use for the report.
|
138
138
|
* @returns {void}
|
139
139
|
*/
|
140
140
|
function reportRequiredEndingSpace(node, token) {
|
141
141
|
context.report({
|
142
142
|
node,
|
143
|
-
loc: token.loc
|
143
|
+
loc: token.loc,
|
144
144
|
message: "A space is required before '{{token}}'.",
|
145
145
|
data: {
|
146
146
|
token: token.value
|
@@ -201,8 +201,7 @@ module.exports = {
|
|
201
201
|
* Because the last token of object patterns might be a type annotation,
|
202
202
|
* this traverses tokens preceded by the last property, then returns the
|
203
203
|
* first '}' token.
|
204
|
-
*
|
205
|
-
* @param {ASTNode} node - The node to get. This node is an
|
204
|
+
* @param {ASTNode} node The node to get. This node is an
|
206
205
|
* ObjectExpression or an ObjectPattern. And this node has one or
|
207
206
|
* more properties.
|
208
207
|
* @returns {Token} '}' token.
|
@@ -215,7 +214,7 @@ module.exports = {
|
|
215
214
|
|
216
215
|
/**
|
217
216
|
* Reports a given object node if spacing in curly braces is invalid.
|
218
|
-
* @param {ASTNode} node
|
217
|
+
* @param {ASTNode} node An ObjectExpression or ObjectPattern node to check.
|
219
218
|
* @returns {void}
|
220
219
|
*/
|
221
220
|
function checkForObject(node) {
|
@@ -233,7 +232,7 @@ module.exports = {
|
|
233
232
|
|
234
233
|
/**
|
235
234
|
* Reports a given import node if spacing in curly braces is invalid.
|
236
|
-
* @param {ASTNode} node
|
235
|
+
* @param {ASTNode} node An ImportDeclaration node to check.
|
237
236
|
* @returns {void}
|
238
237
|
*/
|
239
238
|
function checkForImport(node) {
|
@@ -261,7 +260,7 @@ module.exports = {
|
|
261
260
|
|
262
261
|
/**
|
263
262
|
* Reports a given export node if spacing in curly braces is invalid.
|
264
|
-
* @param {ASTNode} node
|
263
|
+
* @param {ASTNode} node An ExportNamedDeclaration node to check.
|
265
264
|
* @returns {void}
|
266
265
|
*/
|
267
266
|
function checkForExport(node) {
|
@@ -147,7 +147,7 @@ module.exports = {
|
|
147
147
|
|
148
148
|
/**
|
149
149
|
* Checks whether a node is a string literal.
|
150
|
-
* @param {ASTNode} node
|
150
|
+
* @param {ASTNode} node Any AST node.
|
151
151
|
* @returns {boolean} `true` if it is a string literal.
|
152
152
|
*/
|
153
153
|
function isStringLiteral(node) {
|
@@ -41,7 +41,7 @@ module.exports = {
|
|
41
41
|
/**
|
42
42
|
* Determine if provided keyword is a variant of for specifiers
|
43
43
|
* @private
|
44
|
-
* @param {string} keyword
|
44
|
+
* @param {string} keyword keyword to test
|
45
45
|
* @returns {boolean} True if `keyword` is a variant of for specifier
|
46
46
|
*/
|
47
47
|
function isForTypeSpecifier(keyword) {
|
@@ -51,7 +51,7 @@ module.exports = {
|
|
51
51
|
/**
|
52
52
|
* Checks newlines around variable declarations.
|
53
53
|
* @private
|
54
|
-
* @param {ASTNode} node
|
54
|
+
* @param {ASTNode} node `VariableDeclaration` node to test
|
55
55
|
* @returns {void}
|
56
56
|
*/
|
57
57
|
function checkForNewLine(node) {
|