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
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,8 +69,8 @@ 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) {
|
@@ -91,8 +91,8 @@ 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) {
|
@@ -113,8 +113,8 @@ 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) {
|
@@ -133,8 +133,8 @@ 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) {
|
@@ -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) {
|
@@ -150,6 +150,11 @@ module.exports = {
|
|
150
150
|
const leftText = sourceCode.getText().slice(node.range[0], equalsToken.range[0]);
|
151
151
|
const rightText = sourceCode.getText().slice(operatorToken.range[1], node.right.range[1]);
|
152
152
|
|
153
|
+
// Check for comments that would be removed.
|
154
|
+
if (sourceCode.commentsExistBetween(equalsToken, operatorToken)) {
|
155
|
+
return null;
|
156
|
+
}
|
157
|
+
|
153
158
|
return fixer.replaceText(node, `${leftText}${expr.operator}=${rightText}`);
|
154
159
|
}
|
155
160
|
return null;
|
@@ -182,11 +187,17 @@ module.exports = {
|
|
182
187
|
messageId: "unexpected",
|
183
188
|
fix(fixer) {
|
184
189
|
if (canBeFixed(node.left)) {
|
190
|
+
const firstToken = sourceCode.getFirstToken(node);
|
185
191
|
const operatorToken = getOperatorToken(node);
|
186
192
|
const leftText = sourceCode.getText().slice(node.range[0], operatorToken.range[0]);
|
187
193
|
const newOperator = node.operator.slice(0, -1);
|
188
194
|
let rightText;
|
189
195
|
|
196
|
+
// Check for comments that would be duplicated.
|
197
|
+
if (sourceCode.commentsExistBetween(firstToken, operatorToken)) {
|
198
|
+
return null;
|
199
|
+
}
|
200
|
+
|
190
201
|
// If this change would modify precedence (e.g. `foo *= bar + 1` => `foo = foo * (bar + 1)`), parenthesize the right side.
|
191
202
|
if (
|
192
203
|
astUtils.getPrecedence(node.right) <= astUtils.getPrecedence({ type: "BinaryExpression", operator: newOperator }) &&
|
@@ -194,7 +205,17 @@ module.exports = {
|
|
194
205
|
) {
|
195
206
|
rightText = `${sourceCode.text.slice(operatorToken.range[1], node.right.range[0])}(${sourceCode.getText(node.right)})`;
|
196
207
|
} else {
|
197
|
-
|
208
|
+
const firstRightToken = sourceCode.getFirstToken(node.right);
|
209
|
+
let rightTextPrefix = "";
|
210
|
+
|
211
|
+
if (
|
212
|
+
operatorToken.range[1] === firstRightToken.range[0] &&
|
213
|
+
!astUtils.canTokensBeAdjacent(newOperator, firstRightToken)
|
214
|
+
) {
|
215
|
+
rightTextPrefix = " "; // foo+=+bar -> foo= foo+ +bar
|
216
|
+
}
|
217
|
+
|
218
|
+
rightText = `${rightTextPrefix}${sourceCode.text.slice(operatorToken.range[1], node.range[1])}`;
|
198
219
|
}
|
199
220
|
|
200
221
|
return fixer.replaceText(node, `${leftText}= ${leftText}${newOperator}${rightText}`);
|
@@ -97,7 +97,7 @@ module.exports = {
|
|
97
97
|
|
98
98
|
/**
|
99
99
|
* Gets the open brace token from a given node.
|
100
|
-
* @param {ASTNode} node
|
100
|
+
* @param {ASTNode} node A BlockStatement or SwitchStatement node from which to get the open brace.
|
101
101
|
* @returns {Token} The token of the open brace.
|
102
102
|
*/
|
103
103
|
function getOpenBrace(node) {
|
@@ -25,7 +25,6 @@ const CJS_IMPORT = /^require\(/u;
|
|
25
25
|
|
26
26
|
/**
|
27
27
|
* Creates tester which check if a node starts with specific keyword.
|
28
|
-
*
|
29
28
|
* @param {string} keyword The keyword to test.
|
30
29
|
* @returns {Object} the created tester.
|
31
30
|
* @private
|
@@ -39,7 +38,6 @@ function newKeywordTester(keyword) {
|
|
39
38
|
|
40
39
|
/**
|
41
40
|
* Creates tester which check if a node starts with specific keyword and spans a single line.
|
42
|
-
*
|
43
41
|
* @param {string} keyword The keyword to test.
|
44
42
|
* @returns {Object} the created tester.
|
45
43
|
* @private
|
@@ -54,7 +52,6 @@ function newSinglelineKeywordTester(keyword) {
|
|
54
52
|
|
55
53
|
/**
|
56
54
|
* Creates tester which check if a node starts with specific keyword and spans multiple lines.
|
57
|
-
*
|
58
55
|
* @param {string} keyword The keyword to test.
|
59
56
|
* @returns {Object} the created tester.
|
60
57
|
* @private
|
@@ -69,7 +66,6 @@ function newMultilineKeywordTester(keyword) {
|
|
69
66
|
|
70
67
|
/**
|
71
68
|
* Creates tester which check if a node is specific type.
|
72
|
-
*
|
73
69
|
* @param {string} type The node type to test.
|
74
70
|
* @returns {Object} the created tester.
|
75
71
|
* @private
|
@@ -83,7 +79,6 @@ function newNodeTypeTester(type) {
|
|
83
79
|
|
84
80
|
/**
|
85
81
|
* Checks the given node is an expression statement of IIFE.
|
86
|
-
*
|
87
82
|
* @param {ASTNode} node The node to check.
|
88
83
|
* @returns {boolean} `true` if the node is an expression statement of IIFE.
|
89
84
|
* @private
|
@@ -103,7 +98,6 @@ function isIIFEStatement(node) {
|
|
103
98
|
/**
|
104
99
|
* Checks whether the given node is a block-like statement.
|
105
100
|
* This checks the last token of the node is the closing brace of a block.
|
106
|
-
*
|
107
101
|
* @param {SourceCode} sourceCode The source code to get tokens.
|
108
102
|
* @param {ASTNode} node The node to check.
|
109
103
|
* @returns {boolean} `true` if the node is a block-like statement.
|
@@ -187,7 +181,6 @@ function isDirectivePrologue(node, sourceCode) {
|
|
187
181
|
*
|
188
182
|
* foo()
|
189
183
|
* ;[1, 2, 3].forEach(bar)
|
190
|
-
*
|
191
184
|
* @param {SourceCode} sourceCode The source code to get tokens.
|
192
185
|
* @param {ASTNode} node The node to get.
|
193
186
|
* @returns {Token} The actual last token.
|
@@ -224,7 +217,6 @@ function replacerToRemovePaddingLines(_, trailingSpaces, indentSpaces) {
|
|
224
217
|
/**
|
225
218
|
* Check and report statements for `any` configuration.
|
226
219
|
* It does nothing.
|
227
|
-
*
|
228
220
|
* @returns {void}
|
229
221
|
* @private
|
230
222
|
*/
|
@@ -236,7 +228,6 @@ function verifyForAny() {
|
|
236
228
|
* This autofix removes blank lines between the given 2 statements.
|
237
229
|
* However, if comments exist between 2 blank lines, it does not remove those
|
238
230
|
* blank lines automatically.
|
239
|
-
*
|
240
231
|
* @param {RuleContext} context The rule context to report.
|
241
232
|
* @param {ASTNode} _ Unused. The previous node to check.
|
242
233
|
* @param {ASTNode} nextNode The next node to check.
|
@@ -276,7 +267,6 @@ function verifyForNever(context, _, nextNode, paddingLines) {
|
|
276
267
|
* This autofix inserts a blank line between the given 2 statements.
|
277
268
|
* If the `prevNode` has trailing comments, it inserts a blank line after the
|
278
269
|
* trailing comments.
|
279
|
-
*
|
280
270
|
* @param {RuleContext} context The rule context to report.
|
281
271
|
* @param {ASTNode} prevNode The previous node to check.
|
282
272
|
* @param {ASTNode} nextNode The next node to check.
|
@@ -318,7 +308,6 @@ function verifyForAlways(context, prevNode, nextNode, paddingLines) {
|
|
318
308
|
*
|
319
309
|
* // comment.
|
320
310
|
* bar();
|
321
|
-
*
|
322
311
|
* @param {Token} token The token to check.
|
323
312
|
* @returns {boolean} `true` if the token is not a trailing comment.
|
324
313
|
* @private
|
@@ -511,7 +500,6 @@ module.exports = {
|
|
511
500
|
|
512
501
|
/**
|
513
502
|
* Checks whether the given node matches the given type.
|
514
|
-
*
|
515
503
|
* @param {ASTNode} node The statement node to check.
|
516
504
|
* @param {string|string[]} type The statement type to check.
|
517
505
|
* @returns {boolean} `true` if the statement node matched the type.
|
@@ -531,7 +519,6 @@ module.exports = {
|
|
531
519
|
|
532
520
|
/**
|
533
521
|
* Finds the last matched configure from configureList.
|
534
|
-
*
|
535
522
|
* @param {ASTNode} prevNode The previous statement to match.
|
536
523
|
* @param {ASTNode} nextNode The current statement to match.
|
537
524
|
* @returns {Object} The tester of the last matched configure.
|
@@ -554,7 +541,6 @@ module.exports = {
|
|
554
541
|
/**
|
555
542
|
* Gets padding line sequences between the given 2 statements.
|
556
543
|
* Comments are separators of the padding line sequences.
|
557
|
-
*
|
558
544
|
* @param {ASTNode} prevNode The previous statement to count.
|
559
545
|
* @param {ASTNode} nextNode The current statement to count.
|
560
546
|
* @returns {Array<Token[]>} The array of token pairs.
|
@@ -584,7 +570,6 @@ module.exports = {
|
|
584
570
|
|
585
571
|
/**
|
586
572
|
* Verify padding lines between the given node and the previous node.
|
587
|
-
*
|
588
573
|
* @param {ASTNode} node The node to verify.
|
589
574
|
* @returns {void}
|
590
575
|
* @private
|
@@ -616,7 +601,6 @@ module.exports = {
|
|
616
601
|
/**
|
617
602
|
* Verify padding lines between the given node and the previous node.
|
618
603
|
* Then process to enter to new scope.
|
619
|
-
*
|
620
604
|
* @param {ASTNode} node The node to verify.
|
621
605
|
* @returns {void}
|
622
606
|
* @private
|
@@ -11,7 +11,7 @@
|
|
11
11
|
|
12
12
|
/**
|
13
13
|
* Checks whether or not a given variable is a function name.
|
14
|
-
* @param {eslint-scope.Variable} variable
|
14
|
+
* @param {eslint-scope.Variable} variable A variable to check.
|
15
15
|
* @returns {boolean} `true` if the variable is a function name.
|
16
16
|
*/
|
17
17
|
function isFunctionName(variable) {
|
@@ -20,9 +20,9 @@ function isFunctionName(variable) {
|
|
20
20
|
|
21
21
|
/**
|
22
22
|
* Checks whether or not a given MetaProperty node equals to a given value.
|
23
|
-
* @param {ASTNode} node
|
24
|
-
* @param {string} metaName
|
25
|
-
* @param {string} propertyName
|
23
|
+
* @param {ASTNode} node A MetaProperty node to check.
|
24
|
+
* @param {string} metaName The name of `MetaProperty.meta`.
|
25
|
+
* @param {string} propertyName The name of `MetaProperty.property`.
|
26
26
|
* @returns {boolean} `true` if the node is the specific value.
|
27
27
|
*/
|
28
28
|
function checkMetaProperty(node, metaName, propertyName) {
|
@@ -31,7 +31,7 @@ function checkMetaProperty(node, metaName, propertyName) {
|
|
31
31
|
|
32
32
|
/**
|
33
33
|
* Gets the variable object of `arguments` which is defined implicitly.
|
34
|
-
* @param {eslint-scope.Scope} scope
|
34
|
+
* @param {eslint-scope.Scope} scope A scope to get.
|
35
35
|
* @returns {eslint-scope.Variable} The found variable object.
|
36
36
|
*/
|
37
37
|
function getVariableOfArguments(scope) {
|
@@ -57,7 +57,7 @@ function getVariableOfArguments(scope) {
|
|
57
57
|
|
58
58
|
/**
|
59
59
|
* Checkes whether or not a given node is a callback.
|
60
|
-
* @param {ASTNode} node
|
60
|
+
* @param {ASTNode} node A node to check.
|
61
61
|
* @returns {Object}
|
62
62
|
* {boolean} retv.isCallback - `true` if the node is a callback.
|
63
63
|
* {boolean} retv.isLexicalThis - `true` if the node is with `.bind(this)`.
|
@@ -17,8 +17,7 @@ const DESTRUCTURING_HOST_TYPE = /^(?:VariableDeclarator|AssignmentExpression)$/u
|
|
17
17
|
|
18
18
|
/**
|
19
19
|
* Checks whether a given node is located at `ForStatement.init` or not.
|
20
|
-
*
|
21
|
-
* @param {ASTNode} node - A node to check.
|
20
|
+
* @param {ASTNode} node A node to check.
|
22
21
|
* @returns {boolean} `true` if the node is located at `ForStatement.init`.
|
23
22
|
*/
|
24
23
|
function isInitOfForStatement(node) {
|
@@ -27,8 +26,7 @@ function isInitOfForStatement(node) {
|
|
27
26
|
|
28
27
|
/**
|
29
28
|
* Checks whether a given Identifier node becomes a VariableDeclaration or not.
|
30
|
-
*
|
31
|
-
* @param {ASTNode} identifier - An Identifier node to check.
|
29
|
+
* @param {ASTNode} identifier An Identifier node to check.
|
32
30
|
* @returns {boolean} `true` if the node can become a VariableDeclaration.
|
33
31
|
*/
|
34
32
|
function canBecomeVariableDeclaration(identifier) {
|
@@ -51,9 +49,8 @@ function canBecomeVariableDeclaration(identifier) {
|
|
51
49
|
/**
|
52
50
|
* Checks if an property or element is from outer scope or function parameters
|
53
51
|
* in destructing pattern.
|
54
|
-
*
|
55
|
-
* @param {
|
56
|
-
* @param {eslint-scope.Scope} initScope - A scope to start find.
|
52
|
+
* @param {string} name A variable name to be checked.
|
53
|
+
* @param {eslint-scope.Scope} initScope A scope to start find.
|
57
54
|
* @returns {boolean} Indicates if the variable is from outer scope or function parameters.
|
58
55
|
*/
|
59
56
|
function isOuterVariableInDestructing(name, initScope) {
|
@@ -76,8 +73,7 @@ function isOuterVariableInDestructing(name, initScope) {
|
|
76
73
|
* belongs to.
|
77
74
|
* This is used to detect a mix of reassigned and never reassigned in a
|
78
75
|
* destructuring.
|
79
|
-
*
|
80
|
-
* @param {eslint-scope.Reference} reference - A reference to get.
|
76
|
+
* @param {eslint-scope.Reference} reference A reference to get.
|
81
77
|
* @returns {ASTNode|null} A VariableDeclarator/AssignmentExpression node or
|
82
78
|
* null.
|
83
79
|
*/
|
@@ -162,9 +158,8 @@ function hasMemberExpressionAssignment(node) {
|
|
162
158
|
* `/*exported foo` directive comment makes such variables. This rule does not
|
163
159
|
* warn such variables because this rule cannot distinguish whether the
|
164
160
|
* exported variables are reassigned or not.
|
165
|
-
*
|
166
|
-
* @param {
|
167
|
-
* @param {boolean} ignoreReadBeforeAssign -
|
161
|
+
* @param {eslint-scope.Variable} variable A variable to get.
|
162
|
+
* @param {boolean} ignoreReadBeforeAssign
|
168
163
|
* The value of `ignoreReadBeforeAssign` option.
|
169
164
|
* @returns {ASTNode|null}
|
170
165
|
* An Identifier node if the variable should change to const.
|
@@ -262,9 +257,8 @@ function getIdentifierIfShouldBeConst(variable, ignoreReadBeforeAssign) {
|
|
262
257
|
* reference of given variables belongs to.
|
263
258
|
* This is used to detect a mix of reassigned and never reassigned in a
|
264
259
|
* destructuring.
|
265
|
-
*
|
266
|
-
* @param {
|
267
|
-
* @param {boolean} ignoreReadBeforeAssign -
|
260
|
+
* @param {eslint-scope.Variable[]} variables Variables to group by destructuring.
|
261
|
+
* @param {boolean} ignoreReadBeforeAssign
|
268
262
|
* The value of `ignoreReadBeforeAssign` option.
|
269
263
|
* @returns {Map<ASTNode, ASTNode[]>} Grouped identifier nodes.
|
270
264
|
*/
|
@@ -308,10 +302,9 @@ function groupByDestructuring(variables, ignoreReadBeforeAssign) {
|
|
308
302
|
|
309
303
|
/**
|
310
304
|
* Finds the nearest parent of node with a given type.
|
311
|
-
*
|
312
|
-
* @param {
|
313
|
-
* @param {
|
314
|
-
* @param {Function} shouldStop – a predicate that returns true if the traversal should stop, and false otherwise.
|
305
|
+
* @param {ASTNode} node The node to search from.
|
306
|
+
* @param {string} type The type field of the parent node.
|
307
|
+
* @param {Function} shouldStop A predicate that returns true if the traversal should stop, and false otherwise.
|
315
308
|
* @returns {ASTNode} The closest ancestor with the specified type; null if no such ancestor exists.
|
316
309
|
*/
|
317
310
|
function findUp(node, type, shouldStop) {
|
@@ -374,8 +367,7 @@ module.exports = {
|
|
374
367
|
* nullable. In simple declaration or assignment cases, the length of
|
375
368
|
* the array is 1. In destructuring cases, the length of the array can
|
376
369
|
* be 2 or more.
|
377
|
-
*
|
378
|
-
* @param {(eslint-scope.Reference|null)[]} nodes -
|
370
|
+
* @param {(eslint-scope.Reference|null)[]} nodes
|
379
371
|
* References which are grouped by destructuring to report.
|
380
372
|
* @returns {void}
|
381
373
|
*/
|