eslint 6.3.0 → 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 +126 -0
- package/README.md +11 -10
- package/bin/eslint.js +38 -12
- package/lib/cli-engine/cascading-config-array-factory.js +2 -1
- package/lib/cli-engine/cli-engine.js +11 -11
- 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 +4 -2
- 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 +4 -3
- package/lib/cli-engine/lint-result-cache.js +0 -1
- package/lib/cli.js +13 -12
- 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 +3 -7
- package/lib/init/npm-utils.js +1 -6
- 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 +9 -13
- 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 -96
- package/lib/linter/node-event-generator.js +3 -2
- package/lib/options.js +6 -0
- package/lib/rule-tester/rule-tester.js +7 -10
- package/lib/rules/accessor-pairs.js +59 -19
- 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 +2 -9
- 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 +28 -11
- 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 +62 -0
- package/lib/rules/dot-location.js +11 -12
- package/lib/rules/eqeqeq.js +7 -19
- 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-legacy.js +1 -1
- package/lib/rules/indent.js +46 -8
- package/lib/rules/index.js +3 -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-ternary.js +3 -3
- package/lib/rules/new-parens.js +5 -1
- 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 +12 -13
- package/lib/rules/no-extra-boolean-cast.js +1 -3
- package/lib/rules/no-extra-label.js +13 -10
- package/lib/rules/no-extra-parens.js +32 -17
- 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-import-assign.js +238 -0
- package/lib/rules/no-invalid-this.js +1 -3
- package/lib/rules/no-labels.js +3 -6
- package/lib/rules/no-lone-blocks.js +7 -2
- 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-obj-calls.js +29 -9
- package/lib/rules/no-octal-escape.js +14 -8
- package/lib/rules/no-param-reassign.js +28 -7
- package/lib/rules/no-redeclare.js +1 -1
- package/lib/rules/no-regex-spaces.js +105 -45
- package/lib/rules/no-restricted-imports.js +11 -11
- package/lib/rules/no-self-assign.js +18 -18
- package/lib/rules/no-sequences.js +5 -5
- 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-undef-init.js +7 -1
- 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 +34 -19
- 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 +32 -20
- package/lib/rules/no-useless-return.js +11 -17
- 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 +14 -15
- package/lib/rules/object-shorthand.js +36 -10
- 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 +3 -16
- package/lib/rules/prefer-numeric-literals.js +35 -3
- package/lib/rules/prefer-object-spread.js +7 -7
- package/lib/rules/prefer-regex-literals.js +125 -0
- 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 +11 -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-before-function-paren.js +12 -1
- package/lib/rules/space-in-parens.js +81 -75
- 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 +104 -6
- 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/logging.js +2 -0
- package/lib/shared/runtime-info.js +163 -0
- package/lib/shared/traverser.js +2 -0
- package/lib/source-code/source-code.js +11 -12
- 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 +8 -5
@@ -10,8 +10,7 @@
|
|
10
10
|
|
11
11
|
/**
|
12
12
|
* Returns the name of the module imported or re-exported.
|
13
|
-
*
|
14
|
-
* @param {ASTNode} node - A node to get.
|
13
|
+
* @param {ASTNode} node A node to get.
|
15
14
|
* @returns {string} the name of the module, or empty string if no name.
|
16
15
|
*/
|
17
16
|
function getValue(node) {
|
@@ -24,12 +23,11 @@ function getValue(node) {
|
|
24
23
|
|
25
24
|
/**
|
26
25
|
* Checks if the name of the import or export exists in the given array, and reports if so.
|
27
|
-
*
|
28
|
-
* @param {
|
29
|
-
* @param {
|
30
|
-
* @param {string}
|
31
|
-
* @param {string
|
32
|
-
* @param {string} messageId - A messageId to be reported after the name of the module
|
26
|
+
* @param {RuleContext} context The ESLint rule context object.
|
27
|
+
* @param {ASTNode} node A node to get.
|
28
|
+
* @param {string} value The name of the imported or exported module.
|
29
|
+
* @param {string[]} array The array containing other imports or exports in the file.
|
30
|
+
* @param {string} messageId A messageId to be reported after the name of the module
|
33
31
|
*
|
34
32
|
* @returns {void} No return value
|
35
33
|
*/
|
@@ -47,16 +45,15 @@ function checkAndReport(context, node, value, array, messageId) {
|
|
47
45
|
|
48
46
|
/**
|
49
47
|
* @callback nodeCallback
|
50
|
-
* @param {ASTNode} node
|
48
|
+
* @param {ASTNode} node A node to handle.
|
51
49
|
*/
|
52
50
|
|
53
51
|
/**
|
54
52
|
* Returns a function handling the imports of a given file
|
55
|
-
*
|
56
|
-
* @param {
|
57
|
-
* @param {
|
58
|
-
* @param {string[]}
|
59
|
-
* @param {string[]} exportsInFile - The array containing other exports in the file.
|
53
|
+
* @param {RuleContext} context The ESLint rule context object.
|
54
|
+
* @param {boolean} includeExports Whether or not to check for exports in addition to imports.
|
55
|
+
* @param {string[]} importsInFile The array containing other imports in the file.
|
56
|
+
* @param {string[]} exportsInFile The array containing other exports in the file.
|
60
57
|
*
|
61
58
|
* @returns {nodeCallback} A function passed to ESLint to handle the statement.
|
62
59
|
*/
|
@@ -78,10 +75,9 @@ function handleImports(context, includeExports, importsInFile, exportsInFile) {
|
|
78
75
|
|
79
76
|
/**
|
80
77
|
* Returns a function handling the exports of a given file
|
81
|
-
*
|
82
|
-
* @param {
|
83
|
-
* @param {string[]}
|
84
|
-
* @param {string[]} exportsInFile - The array containing other exports in the file.
|
78
|
+
* @param {RuleContext} context The ESLint rule context object.
|
79
|
+
* @param {string[]} importsInFile The array containing other imports in the file.
|
80
|
+
* @param {string[]} exportsInFile The array containing other exports in the file.
|
85
81
|
*
|
86
82
|
* @returns {nodeCallback} A function passed to ESLint to handle the statement.
|
87
83
|
*/
|
@@ -58,7 +58,6 @@ module.exports = {
|
|
58
58
|
*
|
59
59
|
* This is not a generic function. In particular, it is assumed that the scope is a function scope or
|
60
60
|
* a function's inner scope, and that the names can be valid identifiers in the given scope.
|
61
|
-
*
|
62
61
|
* @param {string[]} names Array of variable names.
|
63
62
|
* @param {eslint-scope.Scope} scope Function scope or a function's inner scope.
|
64
63
|
* @returns {boolean} True if all names can be safely declared, false otherwise.
|
@@ -134,7 +133,6 @@ module.exports = {
|
|
134
133
|
|
135
134
|
/**
|
136
135
|
* Checks whether the removal of `else` and its braces is safe from variable name collisions.
|
137
|
-
*
|
138
136
|
* @param {Node} node The 'else' node.
|
139
137
|
* @param {eslint-scope.Scope} scope The scope in which the node and the whole 'if' statement is.
|
140
138
|
* @returns {boolean} True if it is safe, false otherwise.
|
@@ -171,7 +169,6 @@ module.exports = {
|
|
171
169
|
|
172
170
|
/**
|
173
171
|
* Display the context report if rule is violated
|
174
|
-
*
|
175
172
|
* @param {Node} node The 'else' node
|
176
173
|
* @returns {void}
|
177
174
|
*/
|
@@ -255,7 +252,6 @@ module.exports = {
|
|
255
252
|
|
256
253
|
/**
|
257
254
|
* Check to see if the node is a ReturnStatement
|
258
|
-
*
|
259
255
|
* @param {Node} node The node being evaluated
|
260
256
|
* @returns {boolean} True if node is a return
|
261
257
|
*/
|
@@ -267,7 +263,6 @@ module.exports = {
|
|
267
263
|
* Naive return checking, does not iterate through the whole
|
268
264
|
* BlockStatement because we make the assumption that the ReturnStatement
|
269
265
|
* will be the last node in the body of the BlockStatement.
|
270
|
-
*
|
271
266
|
* @param {Node} node The consequent/alternate node
|
272
267
|
* @returns {boolean} True if it has a return
|
273
268
|
*/
|
@@ -284,7 +279,6 @@ module.exports = {
|
|
284
279
|
/**
|
285
280
|
* Check to see if the node is valid for evaluation,
|
286
281
|
* meaning it has an else.
|
287
|
-
*
|
288
282
|
* @param {Node} node The node being evaluated
|
289
283
|
* @returns {boolean} True if the node is valid
|
290
284
|
*/
|
@@ -296,7 +290,6 @@ module.exports = {
|
|
296
290
|
* If the consequent is an IfStatement, check to see if it has an else
|
297
291
|
* and both its consequent and alternate path return, meaning this is
|
298
292
|
* a nested case of rule violation. If-Else not considered currently.
|
299
|
-
*
|
300
293
|
* @param {Node} node The consequent node
|
301
294
|
* @returns {boolean} True if this is a nested rule violation
|
302
295
|
*/
|
@@ -309,7 +302,6 @@ module.exports = {
|
|
309
302
|
* Check the consequent/body node to make sure it is not
|
310
303
|
* a ReturnStatement or an IfStatement that returns on both
|
311
304
|
* code paths.
|
312
|
-
*
|
313
305
|
* @param {Node} node The consequent or body node
|
314
306
|
* @returns {boolean} `true` if it is a Return/If node that always returns.
|
315
307
|
*/
|
@@ -28,8 +28,7 @@ const ALLOW_OPTIONS = Object.freeze([
|
|
28
28
|
|
29
29
|
/**
|
30
30
|
* Gets the kind of a given function node.
|
31
|
-
*
|
32
|
-
* @param {ASTNode} node - A function node to get. This is one of
|
31
|
+
* @param {ASTNode} node A function node to get. This is one of
|
33
32
|
* an ArrowFunctionExpression, a FunctionDeclaration, or a
|
34
33
|
* FunctionExpression.
|
35
34
|
* @returns {string} The kind of the function. This is one of "functions",
|
@@ -130,8 +129,7 @@ module.exports = {
|
|
130
129
|
* - Not allowed by options.
|
131
130
|
* - The body is empty.
|
132
131
|
* - The body doesn't have any comments.
|
133
|
-
*
|
134
|
-
* @param {ASTNode} node - A function node to report. This is one of
|
132
|
+
* @param {ASTNode} node A function node to report. This is one of
|
135
133
|
* an ArrowFunctionExpression, a FunctionDeclaration, or a
|
136
134
|
* FunctionExpression.
|
137
135
|
* @returns {void}
|
package/lib/rules/no-eval.js
CHANGED
@@ -22,9 +22,8 @@ const candidatesOfGlobalObject = Object.freeze([
|
|
22
22
|
|
23
23
|
/**
|
24
24
|
* Checks a given node is a Identifier node of the specified name.
|
25
|
-
*
|
26
|
-
* @param {
|
27
|
-
* @param {string} name - A name to check.
|
25
|
+
* @param {ASTNode} node A node to check.
|
26
|
+
* @param {string} name A name to check.
|
28
27
|
* @returns {boolean} `true` if the node is a Identifier node of the name.
|
29
28
|
*/
|
30
29
|
function isIdentifier(node, name) {
|
@@ -33,9 +32,8 @@ function isIdentifier(node, name) {
|
|
33
32
|
|
34
33
|
/**
|
35
34
|
* Checks a given node is a Literal node of the specified string value.
|
36
|
-
*
|
37
|
-
* @param {
|
38
|
-
* @param {string} name - A name to check.
|
35
|
+
* @param {ASTNode} node A node to check.
|
36
|
+
* @param {string} name A name to check.
|
39
37
|
* @returns {boolean} `true` if the node is a Literal node of the name.
|
40
38
|
*/
|
41
39
|
function isConstant(node, name) {
|
@@ -57,9 +55,8 @@ function isConstant(node, name) {
|
|
57
55
|
/**
|
58
56
|
* Checks a given node is a MemberExpression node which has the specified name's
|
59
57
|
* property.
|
60
|
-
*
|
61
|
-
* @param {
|
62
|
-
* @param {string} name - A name to check.
|
58
|
+
* @param {ASTNode} node A node to check.
|
59
|
+
* @param {string} name A name to check.
|
63
60
|
* @returns {boolean} `true` if the node is a MemberExpression node which has
|
64
61
|
* the specified name's property
|
65
62
|
*/
|
@@ -113,8 +110,7 @@ module.exports = {
|
|
113
110
|
*
|
114
111
|
* This is used in order to check whether or not `this` binding is a
|
115
112
|
* reference to the global object.
|
116
|
-
*
|
117
|
-
* @param {ASTNode} node - A node of the scope. This is one of Program,
|
113
|
+
* @param {ASTNode} node A node of the scope. This is one of Program,
|
118
114
|
* FunctionDeclaration, FunctionExpression, and ArrowFunctionExpression.
|
119
115
|
* @returns {void}
|
120
116
|
*/
|
@@ -132,7 +128,6 @@ module.exports = {
|
|
132
128
|
|
133
129
|
/**
|
134
130
|
* Pops a variable scope from the stack.
|
135
|
-
*
|
136
131
|
* @returns {void}
|
137
132
|
*/
|
138
133
|
function exitVarScope() {
|
@@ -148,8 +143,7 @@ module.exports = {
|
|
148
143
|
* The location of the report is always `eval` `Identifier` (or possibly
|
149
144
|
* `Literal`). The type of the report is `CallExpression` if the parent is
|
150
145
|
* `CallExpression`. Otherwise, it's the given node type.
|
151
|
-
*
|
152
|
-
* @param {ASTNode} node - A node to report.
|
146
|
+
* @param {ASTNode} node A node to report.
|
153
147
|
* @returns {void}
|
154
148
|
*/
|
155
149
|
function report(node) {
|
@@ -171,8 +165,7 @@ module.exports = {
|
|
171
165
|
|
172
166
|
/**
|
173
167
|
* Reports accesses of `eval` via the global object.
|
174
|
-
*
|
175
|
-
* @param {eslint-scope.Scope} globalScope - The global scope.
|
168
|
+
* @param {eslint-scope.Scope} globalScope The global scope.
|
176
169
|
* @returns {void}
|
177
170
|
*/
|
178
171
|
function reportAccessingEvalViaGlobalObject(globalScope) {
|
@@ -205,8 +198,7 @@ module.exports = {
|
|
205
198
|
|
206
199
|
/**
|
207
200
|
* Reports all accesses of `eval` (excludes direct calls to eval).
|
208
|
-
*
|
209
|
-
* @param {eslint-scope.Scope} globalScope - The global scope.
|
201
|
+
* @param {eslint-scope.Scope} globalScope The global scope.
|
210
202
|
* @returns {void}
|
211
203
|
*/
|
212
204
|
function reportAccessingEval(globalScope) {
|
@@ -33,7 +33,7 @@ module.exports = {
|
|
33
33
|
|
34
34
|
/**
|
35
35
|
* Finds and reports references that are non initializer and writable.
|
36
|
-
* @param {Variable} variable
|
36
|
+
* @param {Variable} variable A variable to check.
|
37
37
|
* @returns {void}
|
38
38
|
*/
|
39
39
|
function checkVariable(variable) {
|
@@ -40,13 +40,13 @@ module.exports = {
|
|
40
40
|
},
|
41
41
|
|
42
42
|
create(context) {
|
43
|
+
const sourceCode = context.getSourceCode();
|
43
44
|
let scopeInfo = null;
|
44
45
|
|
45
46
|
/**
|
46
47
|
* Checks if a node is free of side effects.
|
47
48
|
*
|
48
49
|
* This check is stricter than it needs to be, in order to keep the implementation simple.
|
49
|
-
*
|
50
50
|
* @param {ASTNode} node A node to check.
|
51
51
|
* @returns {boolean} True if the node is known to be side-effect free, false otherwise.
|
52
52
|
*/
|
@@ -56,8 +56,7 @@ module.exports = {
|
|
56
56
|
|
57
57
|
/**
|
58
58
|
* Reports a given function node.
|
59
|
-
*
|
60
|
-
* @param {ASTNode} node - A node to report. This is a FunctionExpression or
|
59
|
+
* @param {ASTNode} node A node to report. This is a FunctionExpression or
|
61
60
|
* an ArrowFunctionExpression.
|
62
61
|
* @returns {void}
|
63
62
|
*/
|
@@ -71,8 +70,13 @@ module.exports = {
|
|
71
70
|
return null;
|
72
71
|
}
|
73
72
|
|
74
|
-
const firstTokenToRemove =
|
73
|
+
const firstTokenToRemove = sourceCode
|
75
74
|
.getFirstTokenBetween(node.parent.object, node.parent.property, astUtils.isNotClosingParenToken);
|
75
|
+
const lastTokenToRemove = sourceCode.getLastToken(node.parent.parent);
|
76
|
+
|
77
|
+
if (sourceCode.commentsExistBetween(firstTokenToRemove, lastTokenToRemove)) {
|
78
|
+
return null;
|
79
|
+
}
|
76
80
|
|
77
81
|
return fixer.removeRange([firstTokenToRemove.range[0], node.parent.parent.range[1]]);
|
78
82
|
}
|
@@ -84,8 +88,7 @@ module.exports = {
|
|
84
88
|
* method.
|
85
89
|
*
|
86
90
|
* e.g. `(function() {}.bind(foo))`
|
87
|
-
*
|
88
|
-
* @param {ASTNode} node - A node to report. This is a FunctionExpression or
|
91
|
+
* @param {ASTNode} node A node to report. This is a FunctionExpression or
|
89
92
|
* an ArrowFunctionExpression.
|
90
93
|
* @returns {boolean} `true` if the node is the callee of `.bind()` method.
|
91
94
|
*/
|
@@ -107,8 +110,7 @@ module.exports = {
|
|
107
110
|
|
108
111
|
/**
|
109
112
|
* Adds a scope information object to the stack.
|
110
|
-
*
|
111
|
-
* @param {ASTNode} node - A node to add. This node is a FunctionExpression
|
113
|
+
* @param {ASTNode} node A node to add. This node is a FunctionExpression
|
112
114
|
* or a FunctionDeclaration node.
|
113
115
|
* @returns {void}
|
114
116
|
*/
|
@@ -124,8 +126,7 @@ module.exports = {
|
|
124
126
|
* Removes the scope information object from the top of the stack.
|
125
127
|
* At the same time, this reports the function node if the function has
|
126
128
|
* `.bind()` and the `this` keywords found.
|
127
|
-
*
|
128
|
-
* @param {ASTNode} node - A node to remove. This node is a
|
129
|
+
* @param {ASTNode} node A node to remove. This node is a
|
129
130
|
* FunctionExpression or a FunctionDeclaration node.
|
130
131
|
* @returns {void}
|
131
132
|
*/
|
@@ -140,8 +141,7 @@ module.exports = {
|
|
140
141
|
/**
|
141
142
|
* Reports a given arrow function if the function is callee of `.bind()`
|
142
143
|
* method.
|
143
|
-
*
|
144
|
-
* @param {ASTNode} node - A node to report. This node is an
|
144
|
+
* @param {ASTNode} node A node to report. This node is an
|
145
145
|
* ArrowFunctionExpression.
|
146
146
|
* @returns {void}
|
147
147
|
*/
|
@@ -153,7 +153,6 @@ module.exports = {
|
|
153
153
|
|
154
154
|
/**
|
155
155
|
* Set the mark as the `this` keyword was found in this scope.
|
156
|
-
*
|
157
156
|
* @returns {void}
|
158
157
|
*/
|
159
158
|
function markAsThisFound() {
|
@@ -49,7 +49,6 @@ module.exports = {
|
|
49
49
|
|
50
50
|
/**
|
51
51
|
* Check if a node is in a context where its value would be coerced to a boolean at runtime.
|
52
|
-
*
|
53
52
|
* @param {ASTNode} node The node
|
54
53
|
* @param {ASTNode} parent Its parent
|
55
54
|
* @returns {boolean} If it is in a boolean context
|
@@ -67,7 +66,6 @@ module.exports = {
|
|
67
66
|
|
68
67
|
/**
|
69
68
|
* Check if a node has comments inside.
|
70
|
-
*
|
71
69
|
* @param {ASTNode} node The node to check.
|
72
70
|
* @returns {boolean} `true` if it has comments inside.
|
73
71
|
*/
|
@@ -96,7 +94,7 @@ module.exports = {
|
|
96
94
|
grandparent.callee.name === "Boolean")
|
97
95
|
) {
|
98
96
|
context.report({
|
99
|
-
node,
|
97
|
+
node: parent,
|
100
98
|
messageId: "unexpectedNegation",
|
101
99
|
fix: fixer => {
|
102
100
|
if (hasCommentsInside(parent)) {
|
@@ -40,8 +40,7 @@ module.exports = {
|
|
40
40
|
|
41
41
|
/**
|
42
42
|
* Creates a new scope with a breakable statement.
|
43
|
-
*
|
44
|
-
* @param {ASTNode} node - A node to create. This is a BreakableStatement.
|
43
|
+
* @param {ASTNode} node A node to create. This is a BreakableStatement.
|
45
44
|
* @returns {void}
|
46
45
|
*/
|
47
46
|
function enterBreakableStatement(node) {
|
@@ -54,7 +53,6 @@ module.exports = {
|
|
54
53
|
|
55
54
|
/**
|
56
55
|
* Removes the top scope of the stack.
|
57
|
-
*
|
58
56
|
* @returns {void}
|
59
57
|
*/
|
60
58
|
function exitBreakableStatement() {
|
@@ -66,8 +64,7 @@ module.exports = {
|
|
66
64
|
*
|
67
65
|
* This ignores it if the body is a breakable statement.
|
68
66
|
* In this case it's handled in the `enterBreakableStatement` function.
|
69
|
-
*
|
70
|
-
* @param {ASTNode} node - A node to create. This is a LabeledStatement.
|
67
|
+
* @param {ASTNode} node A node to create. This is a LabeledStatement.
|
71
68
|
* @returns {void}
|
72
69
|
*/
|
73
70
|
function enterLabeledStatement(node) {
|
@@ -85,8 +82,7 @@ module.exports = {
|
|
85
82
|
*
|
86
83
|
* This ignores it if the body is a breakable statement.
|
87
84
|
* In this case it's handled in the `exitBreakableStatement` function.
|
88
|
-
*
|
89
|
-
* @param {ASTNode} node - A node. This is a LabeledStatement.
|
85
|
+
* @param {ASTNode} node A node. This is a LabeledStatement.
|
90
86
|
* @returns {void}
|
91
87
|
*/
|
92
88
|
function exitLabeledStatement(node) {
|
@@ -97,8 +93,7 @@ module.exports = {
|
|
97
93
|
|
98
94
|
/**
|
99
95
|
* Reports a given control node if it's unnecessary.
|
100
|
-
*
|
101
|
-
* @param {ASTNode} node - A node. This is a BreakStatement or a
|
96
|
+
* @param {ASTNode} node A node. This is a BreakStatement or a
|
102
97
|
* ContinueStatement.
|
103
98
|
* @returns {void}
|
104
99
|
*/
|
@@ -116,7 +111,15 @@ module.exports = {
|
|
116
111
|
node: labelNode,
|
117
112
|
messageId: "unexpected",
|
118
113
|
data: labelNode,
|
119
|
-
fix
|
114
|
+
fix(fixer) {
|
115
|
+
const breakOrContinueToken = sourceCode.getFirstToken(node);
|
116
|
+
|
117
|
+
if (sourceCode.commentsExistBetween(breakOrContinueToken, labelNode)) {
|
118
|
+
return null;
|
119
|
+
}
|
120
|
+
|
121
|
+
return fixer.removeRange([breakOrContinueToken.range[1], labelNode.range[1]]);
|
122
|
+
}
|
120
123
|
});
|
121
124
|
}
|
122
125
|
return;
|
@@ -50,7 +50,8 @@ module.exports = {
|
|
50
50
|
returnAssign: { type: "boolean" },
|
51
51
|
ignoreJSX: { enum: ["none", "all", "single-line", "multi-line"] },
|
52
52
|
enforceForArrowConditionals: { type: "boolean" },
|
53
|
-
enforceForSequenceExpressions: { type: "boolean" }
|
53
|
+
enforceForSequenceExpressions: { type: "boolean" },
|
54
|
+
enforceForNewInMemberExpressions: { type: "boolean" }
|
54
55
|
},
|
55
56
|
additionalProperties: false
|
56
57
|
}
|
@@ -80,6 +81,8 @@ module.exports = {
|
|
80
81
|
context.options[1].enforceForArrowConditionals === false;
|
81
82
|
const IGNORE_SEQUENCE_EXPRESSIONS = ALL_NODES && context.options[1] &&
|
82
83
|
context.options[1].enforceForSequenceExpressions === false;
|
84
|
+
const IGNORE_NEW_IN_MEMBER_EXPR = ALL_NODES && context.options[1] &&
|
85
|
+
context.options[1].enforceForNewInMemberExpressions === false;
|
83
86
|
|
84
87
|
const PRECEDENCE_OF_ASSIGNMENT_EXPR = precedence({ type: "AssignmentExpression" });
|
85
88
|
const PRECEDENCE_OF_UPDATE_EXPR = precedence({ type: "UpdateExpression" });
|
@@ -88,7 +91,7 @@ module.exports = {
|
|
88
91
|
|
89
92
|
/**
|
90
93
|
* Determines if this rule should be enforced for a node given the current configuration.
|
91
|
-
* @param {ASTNode} node
|
94
|
+
* @param {ASTNode} node The node to be checked.
|
92
95
|
* @returns {boolean} True if the rule should be enforced for this node.
|
93
96
|
* @private
|
94
97
|
*/
|
@@ -127,7 +130,7 @@ module.exports = {
|
|
127
130
|
|
128
131
|
/**
|
129
132
|
* Determines if a node is surrounded by parentheses.
|
130
|
-
* @param {ASTNode} node
|
133
|
+
* @param {ASTNode} node The node to be checked.
|
131
134
|
* @returns {boolean} True if the node is parenthesised.
|
132
135
|
* @private
|
133
136
|
*/
|
@@ -137,7 +140,7 @@ module.exports = {
|
|
137
140
|
|
138
141
|
/**
|
139
142
|
* Determines if a node is surrounded by parentheses twice.
|
140
|
-
* @param {ASTNode} node
|
143
|
+
* @param {ASTNode} node The node to be checked.
|
141
144
|
* @returns {boolean} True if the node is doubly parenthesised.
|
142
145
|
* @private
|
143
146
|
*/
|
@@ -147,7 +150,7 @@ module.exports = {
|
|
147
150
|
|
148
151
|
/**
|
149
152
|
* Determines if a node is surrounded by (potentially) invalid parentheses.
|
150
|
-
* @param {ASTNode} node
|
153
|
+
* @param {ASTNode} node The node to be checked.
|
151
154
|
* @returns {boolean} True if the node is incorrectly parenthesised.
|
152
155
|
* @private
|
153
156
|
*/
|
@@ -158,7 +161,7 @@ module.exports = {
|
|
158
161
|
/**
|
159
162
|
* Determines if a node that is expected to be parenthesised is surrounded by
|
160
163
|
* (potentially) invalid extra parentheses.
|
161
|
-
* @param {ASTNode} node
|
164
|
+
* @param {ASTNode} node The node to be checked.
|
162
165
|
* @returns {boolean} True if the node is has an unexpected extra pair of parentheses.
|
163
166
|
* @private
|
164
167
|
*/
|
@@ -168,7 +171,7 @@ module.exports = {
|
|
168
171
|
|
169
172
|
/**
|
170
173
|
* Determines if a node test expression is allowed to have a parenthesised assignment
|
171
|
-
* @param {ASTNode} node
|
174
|
+
* @param {ASTNode} node The node to be checked.
|
172
175
|
* @returns {boolean} True if the assignment can be parenthesised.
|
173
176
|
* @private
|
174
177
|
*/
|
@@ -178,7 +181,7 @@ module.exports = {
|
|
178
181
|
|
179
182
|
/**
|
180
183
|
* Determines if a node is in a return statement
|
181
|
-
* @param {ASTNode} node
|
184
|
+
* @param {ASTNode} node The node to be checked.
|
182
185
|
* @returns {boolean} True if the node is in a return statement.
|
183
186
|
* @private
|
184
187
|
*/
|
@@ -197,7 +200,7 @@ module.exports = {
|
|
197
200
|
|
198
201
|
/**
|
199
202
|
* Determines if a constructor function is newed-up with parens
|
200
|
-
* @param {ASTNode} newExpression
|
203
|
+
* @param {ASTNode} newExpression The NewExpression node to be checked.
|
201
204
|
* @returns {boolean} True if the constructor is called with parens.
|
202
205
|
* @private
|
203
206
|
*/
|
@@ -205,12 +208,19 @@ module.exports = {
|
|
205
208
|
const lastToken = sourceCode.getLastToken(newExpression);
|
206
209
|
const penultimateToken = sourceCode.getTokenBefore(lastToken);
|
207
210
|
|
208
|
-
return newExpression.arguments.length > 0 ||
|
211
|
+
return newExpression.arguments.length > 0 ||
|
212
|
+
(
|
213
|
+
|
214
|
+
// The expression should end with its own parens, e.g., new new foo() is not a new expression with parens
|
215
|
+
astUtils.isOpeningParenToken(penultimateToken) &&
|
216
|
+
astUtils.isClosingParenToken(lastToken) &&
|
217
|
+
newExpression.callee.range[1] < newExpression.range[1]
|
218
|
+
);
|
209
219
|
}
|
210
220
|
|
211
221
|
/**
|
212
222
|
* Determines if a node is or contains an assignment expression
|
213
|
-
* @param {ASTNode} node
|
223
|
+
* @param {ASTNode} node The node to be checked.
|
214
224
|
* @returns {boolean} True if the node is or contains an assignment expression.
|
215
225
|
* @private
|
216
226
|
*/
|
@@ -232,7 +242,7 @@ module.exports = {
|
|
232
242
|
|
233
243
|
/**
|
234
244
|
* Determines if a node is contained by or is itself a return statement and is allowed to have a parenthesised assignment
|
235
|
-
* @param {ASTNode} node
|
245
|
+
* @param {ASTNode} node The node to be checked.
|
236
246
|
* @returns {boolean} True if the assignment can be parenthesised.
|
237
247
|
* @private
|
238
248
|
*/
|
@@ -254,8 +264,8 @@ module.exports = {
|
|
254
264
|
/**
|
255
265
|
* Determines if a node following a [no LineTerminator here] restriction is
|
256
266
|
* surrounded by (potentially) invalid extra parentheses.
|
257
|
-
* @param {Token} token
|
258
|
-
* @param {ASTNode} node
|
267
|
+
* @param {Token} token The token preceding the [no LineTerminator here] restriction.
|
268
|
+
* @param {ASTNode} node The node to be checked.
|
259
269
|
* @returns {boolean} True if the node is incorrectly parenthesised.
|
260
270
|
* @private
|
261
271
|
*/
|
@@ -338,7 +348,7 @@ module.exports = {
|
|
338
348
|
function finishReport() {
|
339
349
|
context.report({
|
340
350
|
node,
|
341
|
-
loc: leftParenToken.loc
|
351
|
+
loc: leftParenToken.loc,
|
342
352
|
messageId: "unexpected",
|
343
353
|
fix(fixer) {
|
344
354
|
const parenthesizedSource = sourceCode.text.slice(leftParenToken.range[1], rightParenToken.range[0]);
|
@@ -560,7 +570,6 @@ module.exports = {
|
|
560
570
|
/**
|
561
571
|
* Checks whether the syntax of the given ancestor of an 'in' expression inside a for-loop initializer
|
562
572
|
* is preventing the 'in' keyword from being interpreted as a part of an ill-formed for-in loop.
|
563
|
-
*
|
564
573
|
* @param {ASTNode} node Ancestor of an 'in' expression.
|
565
574
|
* @param {ASTNode} child Child of the node, ancestor of the same 'in' expression or the 'in' expression itself.
|
566
575
|
* @returns {boolean} True if the keyword 'in' would be interpreted as the 'in' operator, without any parenthesis.
|
@@ -592,7 +601,6 @@ module.exports = {
|
|
592
601
|
/**
|
593
602
|
* Starts a new reports buffering. Warnings will be stored in a buffer instead of being reported immediately.
|
594
603
|
* An additional logic that requires multiple nodes (e.g. a whole subtree) may dismiss some of the stored warnings.
|
595
|
-
*
|
596
604
|
* @returns {void}
|
597
605
|
*/
|
598
606
|
function startNewReportsBuffering() {
|
@@ -887,6 +895,13 @@ module.exports = {
|
|
887
895
|
report(node.object);
|
888
896
|
}
|
889
897
|
|
898
|
+
if (nodeObjHasExcessParens &&
|
899
|
+
!IGNORE_NEW_IN_MEMBER_EXPR &&
|
900
|
+
node.object.type === "NewExpression" &&
|
901
|
+
isNewExpressionWithParens(node.object)) {
|
902
|
+
report(node.object);
|
903
|
+
}
|
904
|
+
|
890
905
|
if (node.computed && hasExcessParens(node.property)) {
|
891
906
|
report(node.property);
|
892
907
|
}
|
@@ -40,7 +40,7 @@ module.exports = {
|
|
40
40
|
|
41
41
|
/**
|
42
42
|
* Reports an unnecessary semicolon error.
|
43
|
-
* @param {Node|Token} nodeOrToken
|
43
|
+
* @param {Node|Token} nodeOrToken A node or a token to be reported.
|
44
44
|
* @returns {void}
|
45
45
|
*/
|
46
46
|
function report(nodeOrToken) {
|
@@ -64,8 +64,7 @@ module.exports = {
|
|
64
64
|
/**
|
65
65
|
* Checks for a part of a class body.
|
66
66
|
* This checks tokens from a specified token to a next MethodDefinition or the end of class body.
|
67
|
-
*
|
68
|
-
* @param {Token} firstToken - The first token to check.
|
67
|
+
* @param {Token} firstToken The first token to check.
|
69
68
|
* @returns {void}
|
70
69
|
*/
|
71
70
|
function checkForPartOfClassBody(firstToken) {
|
@@ -83,7 +82,7 @@ module.exports = {
|
|
83
82
|
|
84
83
|
/**
|
85
84
|
* Reports this empty statement, except if the parent node is a loop.
|
86
|
-
* @param {Node} node
|
85
|
+
* @param {Node} node A EmptyStatement node to be reported.
|
87
86
|
* @returns {void}
|
88
87
|
*/
|
89
88
|
EmptyStatement(node) {
|
@@ -106,7 +105,7 @@ module.exports = {
|
|
106
105
|
|
107
106
|
/**
|
108
107
|
* Checks tokens from the head of this class body to the first MethodDefinition or the end of this class body.
|
109
|
-
* @param {Node} node
|
108
|
+
* @param {Node} node A ClassBody node to check.
|
110
109
|
* @returns {void}
|
111
110
|
*/
|
112
111
|
ClassBody(node) {
|
@@ -115,7 +114,7 @@ module.exports = {
|
|
115
114
|
|
116
115
|
/**
|
117
116
|
* Checks tokens from this MethodDefinition to the next MethodDefinition or the end of this class body.
|
118
|
-
* @param {Node} node
|
117
|
+
* @param {Node} node A MethodDefinition node of the start point.
|
119
118
|
* @returns {void}
|
120
119
|
*/
|
121
120
|
MethodDefinition(node) {
|
@@ -18,9 +18,9 @@ const DEFAULT_FALLTHROUGH_COMMENT = /falls?\s?through/iu;
|
|
18
18
|
|
19
19
|
/**
|
20
20
|
* Checks whether or not a given node has a fallthrough comment.
|
21
|
-
* @param {ASTNode} node
|
22
|
-
* @param {RuleContext} context
|
23
|
-
* @param {RegExp} fallthroughCommentPattern
|
21
|
+
* @param {ASTNode} node A SwitchCase node to get comments.
|
22
|
+
* @param {RuleContext} context A rule context which stores comments.
|
23
|
+
* @param {RegExp} fallthroughCommentPattern A pattern to match comment to.
|
24
24
|
* @returns {boolean} `true` if the node has a valid fallthrough comment.
|
25
25
|
*/
|
26
26
|
function hasFallthroughComment(node, context, fallthroughCommentPattern) {
|
@@ -32,7 +32,7 @@ function hasFallthroughComment(node, context, fallthroughCommentPattern) {
|
|
32
32
|
|
33
33
|
/**
|
34
34
|
* Checks whether or not a given code path segment is reachable.
|
35
|
-
* @param {CodePathSegment} segment
|
35
|
+
* @param {CodePathSegment} segment A CodePathSegment to check.
|
36
36
|
* @returns {boolean} `true` if the segment is reachable.
|
37
37
|
*/
|
38
38
|
function isReachable(segment) {
|
@@ -41,8 +41,8 @@ function isReachable(segment) {
|
|
41
41
|
|
42
42
|
/**
|
43
43
|
* Checks whether a node and a token are separated by blank lines
|
44
|
-
* @param {ASTNode} node
|
45
|
-
* @param {Token} token
|
44
|
+
* @param {ASTNode} node The node to check
|
45
|
+
* @param {Token} token The token to compare against
|
46
46
|
* @returns {boolean} `true` if there are blank lines between node and token
|
47
47
|
*/
|
48
48
|
function hasBlankLinesBetween(node, token) {
|