eslint 6.5.1 → 6.6.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/CHANGELOG.md +54 -0
- package/README.md +4 -3
- package/lib/cli-engine/cascading-config-array-factory.js +2 -1
- package/lib/cli-engine/cli-engine.js +9 -7
- package/lib/cli-engine/config-array/config-array.js +0 -4
- package/lib/cli-engine/config-array/config-dependency.js +2 -0
- package/lib/cli-engine/config-array/override-tester.js +2 -0
- package/lib/cli-engine/config-array-factory.js +7 -1
- package/lib/cli-engine/file-enumerator.js +5 -3
- package/lib/cli-engine/formatters/html.js +1 -0
- package/lib/cli-engine/ignored-paths.js +1 -0
- package/lib/init/autoconfig.js +1 -11
- package/lib/init/config-file.js +0 -1
- package/lib/init/config-initializer.js +0 -1
- 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/rule-tester/rule-tester.js +6 -8
- 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/capitalized-comments.js +0 -7
- package/lib/rules/class-methods-use-this.js +3 -3
- package/lib/rules/comma-dangle.js +15 -23
- package/lib/rules/comma-spacing.js +1 -1
- package/lib/rules/computed-property-spacing.js +10 -10
- 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 +3 -5
- 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 +5 -5
- package/lib/rules/generator-star-spacing.js +4 -9
- package/lib/rules/getter-return.js +4 -7
- package/lib/rules/indent.js +2 -2
- 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-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-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-dupe-args.js +1 -1
- package/lib/rules/no-dupe-class-members.js +3 -4
- 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-implied-eval.js +0 -1
- package/lib/rules/no-invalid-this.js +1 -3
- 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-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-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-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-concat.js +4 -4
- package/lib/rules/no-useless-constructor.js +14 -22
- package/lib/rules/no-useless-escape.js +3 -5
- package/lib/rules/no-useless-rename.js +7 -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 +13 -14
- 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 +22 -1
- 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 +13 -21
- package/lib/rules/prefer-destructuring.js +1 -7
- 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 +2 -5
- package/lib/rules/require-yield.js +2 -2
- package/lib/rules/rest-spread-spacing.js +1 -1
- 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 +5 -5
- package/lib/rules/spaced-comment.js +15 -18
- 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 +53 -81
- 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/source-code/source-code.js +8 -8
- 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 +6 -5
@@ -116,7 +116,7 @@ module.exports = {
|
|
116
116
|
|
117
117
|
/**
|
118
118
|
* Checks to see if "*" is being used to import everything.
|
119
|
-
* @param {Set.<string>} importNames
|
119
|
+
* @param {Set.<string>} importNames Set of import names that are being imported
|
120
120
|
* @returns {boolean} whether everything is imported or not
|
121
121
|
*/
|
122
122
|
function isEverythingImported(importNames) {
|
@@ -145,7 +145,7 @@ module.exports = {
|
|
145
145
|
|
146
146
|
/**
|
147
147
|
* Report a restricted path specifically for patterns.
|
148
|
-
* @param {node} node
|
148
|
+
* @param {node} node representing the restricted path reference
|
149
149
|
* @returns {void}
|
150
150
|
* @private
|
151
151
|
*/
|
@@ -163,8 +163,8 @@ module.exports = {
|
|
163
163
|
|
164
164
|
/**
|
165
165
|
* Report a restricted path specifically when using the '*' import.
|
166
|
-
* @param {string} importSource
|
167
|
-
* @param {node} node
|
166
|
+
* @param {string} importSource path of the import
|
167
|
+
* @param {node} node representing the restricted path reference
|
168
168
|
* @returns {void}
|
169
169
|
* @private
|
170
170
|
*/
|
@@ -185,8 +185,8 @@ module.exports = {
|
|
185
185
|
|
186
186
|
/**
|
187
187
|
* Check if the given importSource is restricted because '*' is being imported.
|
188
|
-
* @param {string} importSource
|
189
|
-
* @param {Set.<string>} importNames
|
188
|
+
* @param {string} importSource path of the import
|
189
|
+
* @param {Set.<string>} importNames Set of import names that are being imported
|
190
190
|
* @returns {boolean} whether the path is restricted
|
191
191
|
* @private
|
192
192
|
*/
|
@@ -198,8 +198,8 @@ module.exports = {
|
|
198
198
|
|
199
199
|
/**
|
200
200
|
* Check if the given importNames are restricted given a list of restrictedImportNames.
|
201
|
-
* @param {Set.<string>} importNames
|
202
|
-
* @param {string[]} restrictedImportNames
|
201
|
+
* @param {Set.<string>} importNames Set of import names that are being imported
|
202
|
+
* @param {string[]} restrictedImportNames array of import names that are restricted for this import
|
203
203
|
* @returns {boolean} whether the objectName is restricted
|
204
204
|
* @private
|
205
205
|
*/
|
@@ -211,8 +211,8 @@ module.exports = {
|
|
211
211
|
|
212
212
|
/**
|
213
213
|
* Check if the given importSource is a restricted path.
|
214
|
-
* @param {string} importSource
|
215
|
-
* @param {Set.<string>} importNames
|
214
|
+
* @param {string} importSource path of the import
|
215
|
+
* @param {Set.<string>} importNames Set of import names that are being imported
|
216
216
|
* @returns {boolean} whether the variable is a restricted path or not
|
217
217
|
* @private
|
218
218
|
*/
|
@@ -232,7 +232,7 @@ module.exports = {
|
|
232
232
|
|
233
233
|
/**
|
234
234
|
* Check if the given importSource is restricted by a pattern.
|
235
|
-
* @param {string} importSource
|
235
|
+
* @param {string} importSource path of the import
|
236
236
|
* @returns {boolean} whether the variable is a restricted pattern or not
|
237
237
|
* @private
|
238
238
|
*/
|
@@ -20,9 +20,8 @@ const SPACES = /\s+/gu;
|
|
20
20
|
/**
|
21
21
|
* Checks whether the property of 2 given member expression nodes are the same
|
22
22
|
* property or not.
|
23
|
-
*
|
24
|
-
* @param {ASTNode}
|
25
|
-
* @param {ASTNode} right - Another member expression node to check.
|
23
|
+
* @param {ASTNode} left A member expression node to check.
|
24
|
+
* @param {ASTNode} right Another member expression node to check.
|
26
25
|
* @returns {boolean} `true` if the member expressions have the same property.
|
27
26
|
*/
|
28
27
|
function isSameProperty(left, right) {
|
@@ -43,9 +42,8 @@ function isSameProperty(left, right) {
|
|
43
42
|
/**
|
44
43
|
* Checks whether 2 given member expression nodes are the reference to the same
|
45
44
|
* property or not.
|
46
|
-
*
|
47
|
-
* @param {ASTNode}
|
48
|
-
* @param {ASTNode} right - Another member expression node to check.
|
45
|
+
* @param {ASTNode} left A member expression node to check.
|
46
|
+
* @param {ASTNode} right Another member expression node to check.
|
49
47
|
* @returns {boolean} `true` if the member expressions are the reference to the
|
50
48
|
* same property or not.
|
51
49
|
*/
|
@@ -63,18 +61,20 @@ function isSameMember(left, right) {
|
|
63
61
|
if (lobj.type === "MemberExpression") {
|
64
62
|
return isSameMember(lobj, robj);
|
65
63
|
}
|
64
|
+
if (lobj.type === "ThisExpression") {
|
65
|
+
return true;
|
66
|
+
}
|
66
67
|
return lobj.type === "Identifier" && lobj.name === robj.name;
|
67
68
|
}
|
68
69
|
|
69
70
|
/**
|
70
71
|
* Traverses 2 Pattern nodes in parallel, then reports self-assignments.
|
71
|
-
*
|
72
|
-
* @param {ASTNode|null} left - A left node to traverse. This is a Pattern or
|
72
|
+
* @param {ASTNode|null} left A left node to traverse. This is a Pattern or
|
73
73
|
* a Property.
|
74
|
-
* @param {ASTNode|null} right
|
74
|
+
* @param {ASTNode|null} right A right node to traverse. This is a Pattern or
|
75
75
|
* a Property.
|
76
|
-
* @param {boolean} props
|
77
|
-
* @param {Function} report
|
76
|
+
* @param {boolean} props The flag to check member expressions as well.
|
77
|
+
* @param {Function} report A callback function to report.
|
78
78
|
* @returns {void}
|
79
79
|
*/
|
80
80
|
function eachSelfAssignment(left, right, props, report) {
|
@@ -205,8 +205,7 @@ module.exports = {
|
|
205
205
|
|
206
206
|
/**
|
207
207
|
* Reports a given node as self assignments.
|
208
|
-
*
|
209
|
-
* @param {ASTNode} node - A node to report. This is an Identifier node.
|
208
|
+
* @param {ASTNode} node A node to report. This is an Identifier node.
|
210
209
|
* @returns {void}
|
211
210
|
*/
|
212
211
|
function report(node) {
|
@@ -54,7 +54,7 @@ module.exports = {
|
|
54
54
|
/**
|
55
55
|
* Determines whether a node is required by the grammar to be wrapped in
|
56
56
|
* parens, e.g. the test of an if statement.
|
57
|
-
* @param {ASTNode} node
|
57
|
+
* @param {ASTNode} node The AST node
|
58
58
|
* @returns {boolean} True if parens around node belong to parent node.
|
59
59
|
*/
|
60
60
|
function requiresExtraParens(node) {
|
@@ -64,7 +64,7 @@ module.exports = {
|
|
64
64
|
|
65
65
|
/**
|
66
66
|
* Check if a node is wrapped in parens.
|
67
|
-
* @param {ASTNode} node
|
67
|
+
* @param {ASTNode} node The AST node
|
68
68
|
* @returns {boolean} True if the node has a paren on each side.
|
69
69
|
*/
|
70
70
|
function isParenthesised(node) {
|
@@ -73,7 +73,7 @@ module.exports = {
|
|
73
73
|
|
74
74
|
/**
|
75
75
|
* Check if a node is wrapped in two levels of parens.
|
76
|
-
* @param {ASTNode} node
|
76
|
+
* @param {ASTNode} node The AST node
|
77
77
|
* @returns {boolean} True if two parens surround the node on each side.
|
78
78
|
*/
|
79
79
|
function isParenthesisedTwice(node) {
|
package/lib/rules/no-shadow.js
CHANGED
@@ -54,7 +54,6 @@ module.exports = {
|
|
54
54
|
|
55
55
|
/**
|
56
56
|
* Check if variable name is allowed.
|
57
|
-
*
|
58
57
|
* @param {ASTNode} variable The variable to check.
|
59
58
|
* @returns {boolean} Whether or not the variable name is allowed.
|
60
59
|
*/
|
@@ -67,7 +66,6 @@ module.exports = {
|
|
67
66
|
*
|
68
67
|
* ClassDeclaration creates two variables of its name into its outer scope and its class scope.
|
69
68
|
* So we should ignore the variable in the class scope.
|
70
|
-
*
|
71
69
|
* @param {Object} variable The variable to check.
|
72
70
|
* @returns {boolean} Whether or not the variable of the class name in the class scope of ClassDeclaration.
|
73
71
|
*/
|
@@ -82,7 +80,6 @@ module.exports = {
|
|
82
80
|
*
|
83
81
|
* To avoid reporting at declarations such as `var a = function a() {};`.
|
84
82
|
* But it should report `var a = function(a) {};` or `var a = function() { function a() {} };`.
|
85
|
-
*
|
86
83
|
* @param {Object} variable The variable to check.
|
87
84
|
* @param {Object} scopeVar The scope variable to look for.
|
88
85
|
* @returns {boolean} Whether or not the variable is inside initializer of scopeVar.
|
@@ -139,7 +136,7 @@ module.exports = {
|
|
139
136
|
|
140
137
|
/**
|
141
138
|
* Checks the current context for shadowed variables.
|
142
|
-
* @param {Scope} scope
|
139
|
+
* @param {Scope} scope Fixme
|
143
140
|
* @returns {void}
|
144
141
|
*/
|
145
142
|
function checkForShadows(scope) {
|
package/lib/rules/no-tabs.js
CHANGED
@@ -55,8 +55,14 @@ module.exports = {
|
|
55
55
|
context.report({
|
56
56
|
node,
|
57
57
|
loc: {
|
58
|
-
|
59
|
-
|
58
|
+
start: {
|
59
|
+
line: index + 1,
|
60
|
+
column: match.index
|
61
|
+
},
|
62
|
+
end: {
|
63
|
+
line: index + 1,
|
64
|
+
column: match.index + match[0].length
|
65
|
+
}
|
60
66
|
},
|
61
67
|
message: "Unexpected tab character."
|
62
68
|
});
|
@@ -17,7 +17,7 @@ const astUtils = require("./utils/ast-utils");
|
|
17
17
|
|
18
18
|
/**
|
19
19
|
* Checks whether or not a given node is a constructor.
|
20
|
-
* @param {ASTNode} node
|
20
|
+
* @param {ASTNode} node A node to check. This node type is one of
|
21
21
|
* `Program`, `FunctionDeclaration`, `FunctionExpression`, and
|
22
22
|
* `ArrowFunctionExpression`.
|
23
23
|
* @returns {boolean} `true` if the node is a constructor.
|
@@ -71,7 +71,7 @@ module.exports = {
|
|
71
71
|
|
72
72
|
/**
|
73
73
|
* Gets whether or not `super()` is called in a given code path segment.
|
74
|
-
* @param {CodePathSegment} segment
|
74
|
+
* @param {CodePathSegment} segment A code path segment to get.
|
75
75
|
* @returns {boolean} `true` if `super()` is called.
|
76
76
|
*/
|
77
77
|
function isCalled(segment) {
|
@@ -99,7 +99,7 @@ module.exports = {
|
|
99
99
|
|
100
100
|
/**
|
101
101
|
* Sets a given node as invalid.
|
102
|
-
* @param {ASTNode} node
|
102
|
+
* @param {ASTNode} node A node to set as invalid. This is one of
|
103
103
|
* a ThisExpression and a Super.
|
104
104
|
* @returns {void}
|
105
105
|
*/
|
@@ -135,8 +135,8 @@ module.exports = {
|
|
135
135
|
|
136
136
|
/**
|
137
137
|
* Adds information of a constructor into the stack.
|
138
|
-
* @param {CodePath} codePath
|
139
|
-
* @param {ASTNode} node
|
138
|
+
* @param {CodePath} codePath A code path which was started.
|
139
|
+
* @param {ASTNode} node The current node.
|
140
140
|
* @returns {void}
|
141
141
|
*/
|
142
142
|
onCodePathStart(codePath, node) {
|
@@ -169,8 +169,7 @@ module.exports = {
|
|
169
169
|
*
|
170
170
|
* And this treverses all segments of this code path then reports every
|
171
171
|
* invalid node.
|
172
|
-
*
|
173
|
-
* @param {CodePath} codePath - A code path which was ended.
|
172
|
+
* @param {CodePath} codePath A code path which was ended.
|
174
173
|
* @returns {void}
|
175
174
|
*/
|
176
175
|
onCodePathEnd(codePath) {
|
@@ -204,7 +203,7 @@ module.exports = {
|
|
204
203
|
|
205
204
|
/**
|
206
205
|
* Initialize information of a given code path segment.
|
207
|
-
* @param {CodePathSegment} segment
|
206
|
+
* @param {CodePathSegment} segment A code path segment to initialize.
|
208
207
|
* @returns {void}
|
209
208
|
*/
|
210
209
|
onCodePathSegmentStart(segment) {
|
@@ -225,9 +224,9 @@ module.exports = {
|
|
225
224
|
/**
|
226
225
|
* Update information of the code path segment when a code path was
|
227
226
|
* looped.
|
228
|
-
* @param {CodePathSegment} fromSegment
|
227
|
+
* @param {CodePathSegment} fromSegment The code path segment of the
|
229
228
|
* end of a loop.
|
230
|
-
* @param {CodePathSegment} toSegment
|
229
|
+
* @param {CodePathSegment} toSegment A code path segment of the head
|
231
230
|
* of a loop.
|
232
231
|
* @returns {void}
|
233
232
|
*/
|
@@ -258,7 +257,7 @@ module.exports = {
|
|
258
257
|
|
259
258
|
/**
|
260
259
|
* Reports if this is before `super()`.
|
261
|
-
* @param {ASTNode} node
|
260
|
+
* @param {ASTNode} node A target node.
|
262
261
|
* @returns {void}
|
263
262
|
*/
|
264
263
|
ThisExpression(node) {
|
@@ -269,7 +268,7 @@ module.exports = {
|
|
269
268
|
|
270
269
|
/**
|
271
270
|
* Reports if this is before `super()`.
|
272
|
-
* @param {ASTNode} node
|
271
|
+
* @param {ASTNode} node A target node.
|
273
272
|
* @returns {void}
|
274
273
|
*/
|
275
274
|
Super(node) {
|
@@ -280,7 +279,7 @@ module.exports = {
|
|
280
279
|
|
281
280
|
/**
|
282
281
|
* Marks `super()` called.
|
283
|
-
* @param {ASTNode} node
|
282
|
+
* @param {ASTNode} node A target node.
|
284
283
|
* @returns {void}
|
285
284
|
*/
|
286
285
|
"CallExpression:exit"(node) {
|
@@ -90,7 +90,11 @@ module.exports = {
|
|
90
90
|
const lines = new Set();
|
91
91
|
|
92
92
|
comments.forEach(comment => {
|
93
|
-
|
93
|
+
const endLine = comment.type === "Block"
|
94
|
+
? comment.loc.end.line - 1
|
95
|
+
: comment.loc.end.line;
|
96
|
+
|
97
|
+
for (let i = comment.loc.start.line; i <= endLine; i++) {
|
94
98
|
lines.add(i);
|
95
99
|
}
|
96
100
|
});
|
@@ -122,7 +126,7 @@ module.exports = {
|
|
122
126
|
fixRange = [];
|
123
127
|
|
124
128
|
for (let i = 0, ii = lines.length; i < ii; i++) {
|
125
|
-
const
|
129
|
+
const lineNumber = i + 1;
|
126
130
|
|
127
131
|
/*
|
128
132
|
* Always add linebreak length to line length to accommodate for line break (\n or \r\n)
|
@@ -132,14 +136,22 @@ module.exports = {
|
|
132
136
|
const linebreakLength = linebreaks && linebreaks[i] ? linebreaks[i].length : 1;
|
133
137
|
const lineLength = lines[i].length + linebreakLength;
|
134
138
|
|
139
|
+
const matches = re.exec(lines[i]);
|
140
|
+
|
135
141
|
if (matches) {
|
136
142
|
const location = {
|
137
|
-
|
138
|
-
|
143
|
+
start: {
|
144
|
+
line: lineNumber,
|
145
|
+
column: matches.index
|
146
|
+
},
|
147
|
+
end: {
|
148
|
+
line: lineNumber,
|
149
|
+
column: lineLength - linebreakLength
|
150
|
+
}
|
139
151
|
};
|
140
152
|
|
141
|
-
const rangeStart = totalLength + location.column;
|
142
|
-
const rangeEnd = totalLength +
|
153
|
+
const rangeStart = totalLength + location.start.column;
|
154
|
+
const rangeEnd = totalLength + location.end.column;
|
143
155
|
const containingNode = sourceCode.getNodeByRangeIndex(rangeStart);
|
144
156
|
|
145
157
|
if (containingNode && containingNode.type === "TemplateElement" &&
|
@@ -160,7 +172,7 @@ module.exports = {
|
|
160
172
|
|
161
173
|
fixRange = [rangeStart, rangeEnd];
|
162
174
|
|
163
|
-
if (!ignoreComments || !commentLineNumbers.has(
|
175
|
+
if (!ignoreComments || !commentLineNumbers.has(lineNumber)) {
|
164
176
|
report(node, location, fixRange);
|
165
177
|
}
|
166
178
|
}
|
@@ -35,8 +35,7 @@ const DYNAMIC_PATTERN = /^(?:Call|Member|New|TaggedTemplate|Yield)Expression$/u;
|
|
35
35
|
|
36
36
|
/**
|
37
37
|
* Checks whether or not a given reference is a write reference.
|
38
|
-
*
|
39
|
-
* @param {eslint-scope.Reference} reference - A reference to check.
|
38
|
+
* @param {eslint-scope.Reference} reference A reference to check.
|
40
39
|
* @returns {boolean} `true` if the reference is a write reference.
|
41
40
|
*/
|
42
41
|
function isWriteReference(reference) {
|
@@ -53,8 +52,7 @@ function isWriteReference(reference) {
|
|
53
52
|
/**
|
54
53
|
* Checks whether or not a given loop condition info does not have the modified
|
55
54
|
* flag.
|
56
|
-
*
|
57
|
-
* @param {LoopConditionInfo} condition - A loop condition info to check.
|
55
|
+
* @param {LoopConditionInfo} condition A loop condition info to check.
|
58
56
|
* @returns {boolean} `true` if the loop condition info is "unmodified".
|
59
57
|
*/
|
60
58
|
function isUnmodified(condition) {
|
@@ -64,8 +62,7 @@ function isUnmodified(condition) {
|
|
64
62
|
/**
|
65
63
|
* Checks whether or not a given loop condition info does not have the modified
|
66
64
|
* flag and does not have the group this condition belongs to.
|
67
|
-
*
|
68
|
-
* @param {LoopConditionInfo} condition - A loop condition info to check.
|
65
|
+
* @param {LoopConditionInfo} condition A loop condition info to check.
|
69
66
|
* @returns {boolean} `true` if the loop condition info is "unmodified".
|
70
67
|
*/
|
71
68
|
function isUnmodifiedAndNotBelongToGroup(condition) {
|
@@ -74,9 +71,8 @@ function isUnmodifiedAndNotBelongToGroup(condition) {
|
|
74
71
|
|
75
72
|
/**
|
76
73
|
* Checks whether or not a given reference is inside of a given node.
|
77
|
-
*
|
78
|
-
* @param {
|
79
|
-
* @param {eslint-scope.Reference} reference - A reference to check.
|
74
|
+
* @param {ASTNode} node A node to check.
|
75
|
+
* @param {eslint-scope.Reference} reference A reference to check.
|
80
76
|
* @returns {boolean} `true` if the reference is inside of the node.
|
81
77
|
*/
|
82
78
|
function isInRange(node, reference) {
|
@@ -88,9 +84,8 @@ function isInRange(node, reference) {
|
|
88
84
|
|
89
85
|
/**
|
90
86
|
* Checks whether or not a given reference is inside of a loop node's condition.
|
91
|
-
*
|
92
|
-
* @param {
|
93
|
-
* @param {eslint-scope.Reference} reference - A reference to check.
|
87
|
+
* @param {ASTNode} node A node to check.
|
88
|
+
* @param {eslint-scope.Reference} reference A reference to check.
|
94
89
|
* @returns {boolean} `true` if the reference is inside of the loop node's
|
95
90
|
* condition.
|
96
91
|
*/
|
@@ -108,8 +103,7 @@ const isInLoop = {
|
|
108
103
|
/**
|
109
104
|
* Gets the function which encloses a given reference.
|
110
105
|
* This supports only FunctionDeclaration.
|
111
|
-
*
|
112
|
-
* @param {eslint-scope.Reference} reference - A reference to get.
|
106
|
+
* @param {eslint-scope.Reference} reference A reference to get.
|
113
107
|
* @returns {ASTNode|null} The function node or null.
|
114
108
|
*/
|
115
109
|
function getEncloseFunctionDeclaration(reference) {
|
@@ -128,9 +122,8 @@ function getEncloseFunctionDeclaration(reference) {
|
|
128
122
|
|
129
123
|
/**
|
130
124
|
* Updates the "modified" flags of given loop conditions with given modifiers.
|
131
|
-
*
|
132
|
-
* @param {
|
133
|
-
* @param {eslint-scope.Reference[]} modifiers - The references to update.
|
125
|
+
* @param {LoopConditionInfo[]} conditions The loop conditions to be updated.
|
126
|
+
* @param {eslint-scope.Reference[]} modifiers The references to update.
|
134
127
|
* @returns {void}
|
135
128
|
*/
|
136
129
|
function updateModifiedFlag(conditions, modifiers) {
|
@@ -183,8 +176,7 @@ module.exports = {
|
|
183
176
|
|
184
177
|
/**
|
185
178
|
* Reports a given condition info.
|
186
|
-
*
|
187
|
-
* @param {LoopConditionInfo} condition - A loop condition info to report.
|
179
|
+
* @param {LoopConditionInfo} condition A loop condition info to report.
|
188
180
|
* @returns {void}
|
189
181
|
*/
|
190
182
|
function report(condition) {
|
@@ -199,8 +191,7 @@ module.exports = {
|
|
199
191
|
|
200
192
|
/**
|
201
193
|
* Registers given conditions to the group the condition belongs to.
|
202
|
-
*
|
203
|
-
* @param {LoopConditionInfo[]} conditions - A loop condition info to
|
194
|
+
* @param {LoopConditionInfo[]} conditions A loop condition info to
|
204
195
|
* register.
|
205
196
|
* @returns {void}
|
206
197
|
*/
|
@@ -222,8 +213,7 @@ module.exports = {
|
|
222
213
|
|
223
214
|
/**
|
224
215
|
* Reports references which are inside of unmodified groups.
|
225
|
-
*
|
226
|
-
* @param {LoopConditionInfo[]} conditions - A loop condition info to report.
|
216
|
+
* @param {LoopConditionInfo[]} conditions A loop condition info to report.
|
227
217
|
* @returns {void}
|
228
218
|
*/
|
229
219
|
function checkConditionsInGroup(conditions) {
|
@@ -234,8 +224,7 @@ module.exports = {
|
|
234
224
|
|
235
225
|
/**
|
236
226
|
* Checks whether or not a given group node has any dynamic elements.
|
237
|
-
*
|
238
|
-
* @param {ASTNode} root - A node to check.
|
227
|
+
* @param {ASTNode} root A node to check.
|
239
228
|
* This node is one of BinaryExpression or ConditionalExpression.
|
240
229
|
* @returns {boolean} `true` if the node is dynamic.
|
241
230
|
*/
|
@@ -259,8 +248,7 @@ module.exports = {
|
|
259
248
|
|
260
249
|
/**
|
261
250
|
* Creates the loop condition information from a given reference.
|
262
|
-
*
|
263
|
-
* @param {eslint-scope.Reference} reference - A reference to create.
|
251
|
+
* @param {eslint-scope.Reference} reference A reference to create.
|
264
252
|
* @returns {LoopConditionInfo|null} Created loop condition info, or null.
|
265
253
|
*/
|
266
254
|
function toLoopCondition(reference) {
|
@@ -313,8 +301,7 @@ module.exports = {
|
|
313
301
|
/**
|
314
302
|
* Finds unmodified references which are inside of a loop condition.
|
315
303
|
* Then reports the references which are outside of groups.
|
316
|
-
*
|
317
|
-
* @param {eslint-scope.Variable} variable - A variable to report.
|
304
|
+
* @param {eslint-scope.Variable} variable A variable to report.
|
318
305
|
* @returns {void}
|
319
306
|
*/
|
320
307
|
function checkReferences(variable) {
|
@@ -57,7 +57,7 @@ module.exports = {
|
|
57
57
|
|
58
58
|
/**
|
59
59
|
* Test if the node is a boolean literal
|
60
|
-
* @param {ASTNode} node
|
60
|
+
* @param {ASTNode} node The node to report.
|
61
61
|
* @returns {boolean} True if the its a boolean literal
|
62
62
|
* @private
|
63
63
|
*/
|
@@ -91,7 +91,7 @@ module.exports = {
|
|
91
91
|
|
92
92
|
/**
|
93
93
|
* Tests if a given node always evaluates to a boolean value
|
94
|
-
* @param {ASTNode} node
|
94
|
+
* @param {ASTNode} node An expression node
|
95
95
|
* @returns {boolean} True if it is determined that the node will always evaluate to a boolean value
|
96
96
|
*/
|
97
97
|
function isBooleanExpression(node) {
|
@@ -101,7 +101,7 @@ module.exports = {
|
|
101
101
|
|
102
102
|
/**
|
103
103
|
* Test if the node matches the pattern id ? id : expression
|
104
|
-
* @param {ASTNode} node
|
104
|
+
* @param {ASTNode} node The ConditionalExpression to check.
|
105
105
|
* @returns {boolean} True if the pattern is matched, and false otherwise
|
106
106
|
* @private
|
107
107
|
*/
|
@@ -10,7 +10,7 @@
|
|
10
10
|
|
11
11
|
/**
|
12
12
|
* Checks whether or not a given variable declarator has the initializer.
|
13
|
-
* @param {ASTNode} node
|
13
|
+
* @param {ASTNode} node A VariableDeclarator node to check.
|
14
14
|
* @returns {boolean} `true` if the node has the initializer.
|
15
15
|
*/
|
16
16
|
function isInitialized(node) {
|
@@ -19,7 +19,7 @@ function isInitialized(node) {
|
|
19
19
|
|
20
20
|
/**
|
21
21
|
* Checks whether or not a given code path segment is unreachable.
|
22
|
-
* @param {CodePathSegment} segment
|
22
|
+
* @param {CodePathSegment} segment A CodePathSegment to check.
|
23
23
|
* @returns {boolean} `true` if the segment is unreachable.
|
24
24
|
*/
|
25
25
|
function isUnreachable(segment) {
|
@@ -57,7 +57,7 @@ class ConsecutiveRange {
|
|
57
57
|
|
58
58
|
/**
|
59
59
|
* Checks whether the given node is inside of this range.
|
60
|
-
* @param {ASTNode|Token} node
|
60
|
+
* @param {ASTNode|Token} node The node to check.
|
61
61
|
* @returns {boolean} `true` if the node is inside of this range.
|
62
62
|
*/
|
63
63
|
contains(node) {
|
@@ -69,7 +69,7 @@ class ConsecutiveRange {
|
|
69
69
|
|
70
70
|
/**
|
71
71
|
* Checks whether the given node is consecutive to this range.
|
72
|
-
* @param {ASTNode} node
|
72
|
+
* @param {ASTNode} node The node to check.
|
73
73
|
* @returns {boolean} `true` if the node is consecutive to this range.
|
74
74
|
*/
|
75
75
|
isConsecutive(node) {
|
@@ -78,7 +78,7 @@ class ConsecutiveRange {
|
|
78
78
|
|
79
79
|
/**
|
80
80
|
* Merges the given node to this range.
|
81
|
-
* @param {ASTNode} node
|
81
|
+
* @param {ASTNode} node The node to merge.
|
82
82
|
* @returns {void}
|
83
83
|
*/
|
84
84
|
merge(node) {
|
@@ -87,7 +87,7 @@ class ConsecutiveRange {
|
|
87
87
|
|
88
88
|
/**
|
89
89
|
* Resets this range by the given node or null.
|
90
|
-
* @param {ASTNode|null} node
|
90
|
+
* @param {ASTNode|null} node The node to reset, or null.
|
91
91
|
* @returns {void}
|
92
92
|
*/
|
93
93
|
reset(node) {
|
@@ -120,7 +120,7 @@ module.exports = {
|
|
120
120
|
|
121
121
|
/**
|
122
122
|
* Reports a given node if it's unreachable.
|
123
|
-
* @param {ASTNode} node
|
123
|
+
* @param {ASTNode} node A statement node to report.
|
124
124
|
* @returns {void}
|
125
125
|
*/
|
126
126
|
function reportIfUnreachable(node) {
|
@@ -35,8 +35,7 @@ module.exports = {
|
|
35
35
|
|
36
36
|
/**
|
37
37
|
* Checks if the node is the finalizer of a TryStatement
|
38
|
-
*
|
39
|
-
* @param {ASTNode} node - node to check.
|
38
|
+
* @param {ASTNode} node node to check.
|
40
39
|
* @returns {boolean} - true if the node is the finalizer of a TryStatement
|
41
40
|
*/
|
42
41
|
function isFinallyBlock(node) {
|
@@ -45,9 +44,8 @@ module.exports = {
|
|
45
44
|
|
46
45
|
/**
|
47
46
|
* Climbs up the tree if the node is not a sentinel node
|
48
|
-
*
|
49
|
-
* @param {
|
50
|
-
* @param {string} label - label of the break or continue statement
|
47
|
+
* @param {ASTNode} node node to check.
|
48
|
+
* @param {string} label label of the break or continue statement
|
51
49
|
* @returns {boolean} - return whether the node is a finally block or a sentinel node
|
52
50
|
*/
|
53
51
|
function isInFinallyBlock(node, label) {
|
@@ -82,8 +80,7 @@ module.exports = {
|
|
82
80
|
|
83
81
|
/**
|
84
82
|
* Checks whether the possibly-unsafe statement is inside a finally block.
|
85
|
-
*
|
86
|
-
* @param {ASTNode} node - node to check.
|
83
|
+
* @param {ASTNode} node node to check.
|
87
84
|
* @returns {void}
|
88
85
|
*/
|
89
86
|
function check(node) {
|