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
@@ -14,7 +14,7 @@ const astUtils = require("./utils/ast-utils.js");
|
|
14
14
|
|
15
15
|
/**
|
16
16
|
* Checks whether or not a node is a conditional expression.
|
17
|
-
* @param {ASTNode} node
|
17
|
+
* @param {ASTNode} node node to test
|
18
18
|
* @returns {boolean} `true` if the node is a conditional expression.
|
19
19
|
*/
|
20
20
|
function isConditional(node) {
|
@@ -59,7 +59,7 @@ module.exports = {
|
|
59
59
|
|
60
60
|
/**
|
61
61
|
* Reports if an arrow function contains an ambiguous conditional.
|
62
|
-
* @param {ASTNode} node
|
62
|
+
* @param {ASTNode} node A node to check and report.
|
63
63
|
* @returns {void}
|
64
64
|
*/
|
65
65
|
function checkArrowFunc(node) {
|
package/lib/rules/no-console.js
CHANGED
@@ -54,8 +54,7 @@ module.exports = {
|
|
54
54
|
|
55
55
|
/**
|
56
56
|
* Checks whether the given reference is 'console' or not.
|
57
|
-
*
|
58
|
-
* @param {eslint-scope.Reference} reference - The reference to check.
|
57
|
+
* @param {eslint-scope.Reference} reference The reference to check.
|
59
58
|
* @returns {boolean} `true` if the reference is 'console'.
|
60
59
|
*/
|
61
60
|
function isConsole(reference) {
|
@@ -67,8 +66,7 @@ module.exports = {
|
|
67
66
|
/**
|
68
67
|
* Checks whether the property name of the given MemberExpression node
|
69
68
|
* is allowed by options or not.
|
70
|
-
*
|
71
|
-
* @param {ASTNode} node - The MemberExpression node to check.
|
69
|
+
* @param {ASTNode} node The MemberExpression node to check.
|
72
70
|
* @returns {boolean} `true` if the property name of the node is allowed.
|
73
71
|
*/
|
74
72
|
function isAllowed(node) {
|
@@ -80,8 +78,7 @@ module.exports = {
|
|
80
78
|
/**
|
81
79
|
* Checks whether the given reference is a member access which is not
|
82
80
|
* allowed by options or not.
|
83
|
-
*
|
84
|
-
* @param {eslint-scope.Reference} reference - The reference to check.
|
81
|
+
* @param {eslint-scope.Reference} reference The reference to check.
|
85
82
|
* @returns {boolean} `true` if the reference is a member access which
|
86
83
|
* is not allowed by options.
|
87
84
|
*/
|
@@ -98,8 +95,7 @@ module.exports = {
|
|
98
95
|
|
99
96
|
/**
|
100
97
|
* Reports the given reference as a violation.
|
101
|
-
*
|
102
|
-
* @param {eslint-scope.Reference} reference - The reference to report.
|
98
|
+
* @param {eslint-scope.Reference} reference The reference to report.
|
103
99
|
* @returns {void}
|
104
100
|
*/
|
105
101
|
function report(reference) {
|
@@ -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) {
|
@@ -35,7 +35,7 @@ module.exports = {
|
|
35
35
|
|
36
36
|
/**
|
37
37
|
* Checks whether or not a given definition is a parameter's.
|
38
|
-
* @param {eslint-scope.DefEntry} def
|
38
|
+
* @param {eslint-scope.DefEntry} def A definition to check.
|
39
39
|
* @returns {boolean} `true` if the definition is a parameter's.
|
40
40
|
*/
|
41
41
|
function isParameter(def) {
|
@@ -32,8 +32,8 @@ module.exports = {
|
|
32
32
|
|
33
33
|
/**
|
34
34
|
* Gets state of a given member name.
|
35
|
-
* @param {string} name
|
36
|
-
* @param {boolean} isStatic
|
35
|
+
* @param {string} name A name of a member.
|
36
|
+
* @param {boolean} isStatic A flag which specifies that is a static member.
|
37
37
|
* @returns {Object} A state of a given member name.
|
38
38
|
* - retv.init {boolean} A flag which shows the name is declared as normal member.
|
39
39
|
* - retv.get {boolean} A flag which shows the name is declared as getter.
|
@@ -55,8 +55,7 @@ module.exports = {
|
|
55
55
|
|
56
56
|
/**
|
57
57
|
* Gets the name text of a given node.
|
58
|
-
*
|
59
|
-
* @param {ASTNode} node - A node to get the name.
|
58
|
+
* @param {ASTNode} node A node to get the name.
|
60
59
|
* @returns {string} The name text of the node.
|
61
60
|
*/
|
62
61
|
function getName(node) {
|
@@ -23,9 +23,10 @@ const SET_KIND = /^(?:init|set)$/u;
|
|
23
23
|
*/
|
24
24
|
class ObjectInfo {
|
25
25
|
|
26
|
+
// eslint-disable-next-line jsdoc/require-description
|
26
27
|
/**
|
27
|
-
* @param {ObjectInfo|null} upper
|
28
|
-
* @param {ASTNode} node
|
28
|
+
* @param {ObjectInfo|null} upper The information of the outer object.
|
29
|
+
* @param {ASTNode} node The ObjectExpression node of this information.
|
29
30
|
*/
|
30
31
|
constructor(upper, node) {
|
31
32
|
this.upper = upper;
|
@@ -35,7 +36,7 @@ class ObjectInfo {
|
|
35
36
|
|
36
37
|
/**
|
37
38
|
* Gets the information of the given Property node.
|
38
|
-
* @param {ASTNode} node
|
39
|
+
* @param {ASTNode} node The Property node to get.
|
39
40
|
* @returns {{get: boolean, set: boolean}} The information of the property.
|
40
41
|
*/
|
41
42
|
getPropertyInfo(node) {
|
@@ -49,7 +50,7 @@ class ObjectInfo {
|
|
49
50
|
|
50
51
|
/**
|
51
52
|
* Checks whether the given property has been defined already or not.
|
52
|
-
* @param {ASTNode} node
|
53
|
+
* @param {ASTNode} node The Property node to check.
|
53
54
|
* @returns {boolean} `true` if the property has been defined.
|
54
55
|
*/
|
55
56
|
isPropertyDefined(node) {
|
@@ -63,7 +64,7 @@ class ObjectInfo {
|
|
63
64
|
|
64
65
|
/**
|
65
66
|
* Defines the given property.
|
66
|
-
* @param {ASTNode} node
|
67
|
+
* @param {ASTNode} node The Property node to define.
|
67
68
|
* @returns {void}
|
68
69
|
*/
|
69
70
|
defineProperty(node) {
|
@@ -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) {
|
@@ -47,7 +47,6 @@ module.exports = {
|
|
47
47
|
* Checks if a node is free of side effects.
|
48
48
|
*
|
49
49
|
* This check is stricter than it needs to be, in order to keep the implementation simple.
|
50
|
-
*
|
51
50
|
* @param {ASTNode} node A node to check.
|
52
51
|
* @returns {boolean} True if the node is known to be side-effect free, false otherwise.
|
53
52
|
*/
|
@@ -57,8 +56,7 @@ module.exports = {
|
|
57
56
|
|
58
57
|
/**
|
59
58
|
* Reports a given function node.
|
60
|
-
*
|
61
|
-
* @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
|
62
60
|
* an ArrowFunctionExpression.
|
63
61
|
* @returns {void}
|
64
62
|
*/
|
@@ -90,8 +88,7 @@ module.exports = {
|
|
90
88
|
* method.
|
91
89
|
*
|
92
90
|
* e.g. `(function() {}.bind(foo))`
|
93
|
-
*
|
94
|
-
* @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
|
95
92
|
* an ArrowFunctionExpression.
|
96
93
|
* @returns {boolean} `true` if the node is the callee of `.bind()` method.
|
97
94
|
*/
|
@@ -113,8 +110,7 @@ module.exports = {
|
|
113
110
|
|
114
111
|
/**
|
115
112
|
* Adds a scope information object to the stack.
|
116
|
-
*
|
117
|
-
* @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
|
118
114
|
* or a FunctionDeclaration node.
|
119
115
|
* @returns {void}
|
120
116
|
*/
|
@@ -130,8 +126,7 @@ module.exports = {
|
|
130
126
|
* Removes the scope information object from the top of the stack.
|
131
127
|
* At the same time, this reports the function node if the function has
|
132
128
|
* `.bind()` and the `this` keywords found.
|
133
|
-
*
|
134
|
-
* @param {ASTNode} node - A node to remove. This node is a
|
129
|
+
* @param {ASTNode} node A node to remove. This node is a
|
135
130
|
* FunctionExpression or a FunctionDeclaration node.
|
136
131
|
* @returns {void}
|
137
132
|
*/
|
@@ -146,8 +141,7 @@ module.exports = {
|
|
146
141
|
/**
|
147
142
|
* Reports a given arrow function if the function is callee of `.bind()`
|
148
143
|
* method.
|
149
|
-
*
|
150
|
-
* @param {ASTNode} node - A node to report. This node is an
|
144
|
+
* @param {ASTNode} node A node to report. This node is an
|
151
145
|
* ArrowFunctionExpression.
|
152
146
|
* @returns {void}
|
153
147
|
*/
|
@@ -159,7 +153,6 @@ module.exports = {
|
|
159
153
|
|
160
154
|
/**
|
161
155
|
* Set the mark as the `this` keyword was found in this scope.
|
162
|
-
*
|
163
156
|
* @returns {void}
|
164
157
|
*/
|
165
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
|
*/
|
@@ -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
|
*/
|
@@ -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
|
*/
|
@@ -217,7 +220,7 @@ module.exports = {
|
|
217
220
|
|
218
221
|
/**
|
219
222
|
* Determines if a node is or contains an assignment expression
|
220
|
-
* @param {ASTNode} node
|
223
|
+
* @param {ASTNode} node The node to be checked.
|
221
224
|
* @returns {boolean} True if the node is or contains an assignment expression.
|
222
225
|
* @private
|
223
226
|
*/
|
@@ -239,7 +242,7 @@ module.exports = {
|
|
239
242
|
|
240
243
|
/**
|
241
244
|
* Determines if a node is contained by or is itself a return statement and is allowed to have a parenthesised assignment
|
242
|
-
* @param {ASTNode} node
|
245
|
+
* @param {ASTNode} node The node to be checked.
|
243
246
|
* @returns {boolean} True if the assignment can be parenthesised.
|
244
247
|
* @private
|
245
248
|
*/
|
@@ -261,8 +264,8 @@ module.exports = {
|
|
261
264
|
/**
|
262
265
|
* Determines if a node following a [no LineTerminator here] restriction is
|
263
266
|
* surrounded by (potentially) invalid extra parentheses.
|
264
|
-
* @param {Token} token
|
265
|
-
* @param {ASTNode} node
|
267
|
+
* @param {Token} token The token preceding the [no LineTerminator here] restriction.
|
268
|
+
* @param {ASTNode} node The node to be checked.
|
266
269
|
* @returns {boolean} True if the node is incorrectly parenthesised.
|
267
270
|
* @private
|
268
271
|
*/
|
@@ -567,7 +570,6 @@ module.exports = {
|
|
567
570
|
/**
|
568
571
|
* Checks whether the syntax of the given ancestor of an 'in' expression inside a for-loop initializer
|
569
572
|
* is preventing the 'in' keyword from being interpreted as a part of an ill-formed for-in loop.
|
570
|
-
*
|
571
573
|
* @param {ASTNode} node Ancestor of an 'in' expression.
|
572
574
|
* @param {ASTNode} child Child of the node, ancestor of the same 'in' expression or the 'in' expression itself.
|
573
575
|
* @returns {boolean} True if the keyword 'in' would be interpreted as the 'in' operator, without any parenthesis.
|
@@ -599,7 +601,6 @@ module.exports = {
|
|
599
601
|
/**
|
600
602
|
* Starts a new reports buffering. Warnings will be stored in a buffer instead of being reported immediately.
|
601
603
|
* An additional logic that requires multiple nodes (e.g. a whole subtree) may dismiss some of the stored warnings.
|
602
|
-
*
|
603
604
|
* @returns {void}
|
604
605
|
*/
|
605
606
|
function startNewReportsBuffering() {
|
@@ -895,6 +896,7 @@ module.exports = {
|
|
895
896
|
}
|
896
897
|
|
897
898
|
if (nodeObjHasExcessParens &&
|
899
|
+
!IGNORE_NEW_IN_MEMBER_EXPR &&
|
898
900
|
node.object.type === "NewExpression" &&
|
899
901
|
isNewExpressionWithParens(node.object)) {
|
900
902
|
report(node.object);
|