eslint 6.5.1 → 6.7.2
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 +118 -0
- package/README.md +10 -9
- package/conf/config-schema.js +1 -0
- package/conf/default-cli-options.js +1 -1
- package/lib/cli-engine/cascading-config-array-factory.js +40 -14
- package/lib/cli-engine/cli-engine.js +49 -21
- package/lib/cli-engine/config-array/config-array.js +13 -4
- package/lib/cli-engine/config-array/config-dependency.js +2 -0
- package/lib/cli-engine/config-array/extracted-config.js +27 -0
- package/lib/cli-engine/config-array/ignore-pattern.js +231 -0
- package/lib/cli-engine/config-array/index.js +2 -0
- package/lib/cli-engine/config-array/override-tester.js +2 -0
- package/lib/cli-engine/config-array-factory.js +120 -2
- package/lib/cli-engine/file-enumerator.js +65 -34
- package/lib/cli-engine/formatters/html.js +1 -0
- package/lib/init/autoconfig.js +1 -11
- package/lib/init/config-file.js +0 -1
- package/lib/init/config-initializer.js +4 -4
- package/lib/init/config-rule.js +1 -5
- package/lib/init/npm-utils.js +0 -5
- package/lib/linter/code-path-analysis/code-path-analyzer.js +24 -38
- package/lib/linter/code-path-analysis/code-path-segment.js +17 -25
- package/lib/linter/code-path-analysis/code-path-state.js +40 -81
- package/lib/linter/code-path-analysis/code-path.js +10 -11
- package/lib/linter/code-path-analysis/debug-helpers.js +8 -12
- package/lib/linter/code-path-analysis/fork-context.js +23 -34
- package/lib/linter/code-path-analysis/id-generator.js +2 -2
- package/lib/linter/linter.js +121 -95
- package/lib/linter/node-event-generator.js +3 -2
- package/lib/linter/report-translator.js +73 -7
- package/lib/rule-tester/rule-tester.js +46 -14
- package/lib/rules/accessor-pairs.js +8 -8
- package/lib/rules/array-bracket-newline.js +12 -15
- package/lib/rules/array-bracket-spacing.js +12 -12
- package/lib/rules/array-callback-return.js +6 -11
- package/lib/rules/array-element-newline.js +5 -8
- package/lib/rules/arrow-parens.js +0 -1
- package/lib/rules/block-scoped-var.js +3 -3
- package/lib/rules/block-spacing.js +4 -4
- package/lib/rules/camelcase.js +19 -6
- package/lib/rules/capitalized-comments.js +0 -7
- package/lib/rules/class-methods-use-this.js +3 -3
- package/lib/rules/comma-dangle.js +20 -25
- package/lib/rules/comma-spacing.js +1 -1
- package/lib/rules/computed-property-spacing.js +14 -14
- package/lib/rules/consistent-return.js +4 -5
- package/lib/rules/consistent-this.js +5 -5
- package/lib/rules/constructor-super.js +14 -16
- package/lib/rules/curly.js +12 -9
- package/lib/rules/default-param-last.js +1 -0
- package/lib/rules/dot-location.js +11 -12
- package/lib/rules/func-names.js +6 -6
- package/lib/rules/function-call-argument-newline.js +8 -6
- package/lib/rules/generator-star-spacing.js +4 -9
- package/lib/rules/getter-return.js +4 -7
- package/lib/rules/grouped-accessor-pairs.js +224 -0
- package/lib/rules/indent.js +13 -2
- package/lib/rules/index.js +5 -0
- package/lib/rules/init-declarations.js +2 -2
- package/lib/rules/jsx-quotes.js +1 -1
- package/lib/rules/keyword-spacing.js +32 -56
- package/lib/rules/lines-around-directive.js +1 -1
- package/lib/rules/max-len.js +0 -5
- package/lib/rules/max-statements-per-line.js +3 -7
- package/lib/rules/multiline-comment-style.js +237 -106
- package/lib/rules/multiline-ternary.js +3 -3
- package/lib/rules/newline-after-var.js +6 -7
- package/lib/rules/newline-before-return.js +8 -9
- package/lib/rules/newline-per-chained-call.js +2 -4
- package/lib/rules/no-class-assign.js +2 -2
- package/lib/rules/no-compare-neg-zero.js +1 -2
- package/lib/rules/no-cond-assign.js +14 -4
- package/lib/rules/no-confusing-arrow.js +2 -2
- package/lib/rules/no-console.js +4 -8
- package/lib/rules/no-const-assign.js +1 -1
- package/lib/rules/no-constructor-return.js +62 -0
- package/lib/rules/no-dupe-args.js +1 -1
- package/lib/rules/no-dupe-class-members.js +3 -4
- package/lib/rules/no-dupe-else-if.js +122 -0
- package/lib/rules/no-dupe-keys.js +6 -5
- package/lib/rules/no-duplicate-imports.js +14 -18
- package/lib/rules/no-else-return.js +0 -8
- package/lib/rules/no-empty-function.js +2 -4
- package/lib/rules/no-eval.js +10 -18
- package/lib/rules/no-ex-assign.js +1 -1
- package/lib/rules/no-extra-bind.js +5 -12
- package/lib/rules/no-extra-boolean-cast.js +0 -2
- package/lib/rules/no-extra-label.js +4 -9
- package/lib/rules/no-extra-parens.js +17 -15
- package/lib/rules/no-extra-semi.js +5 -6
- package/lib/rules/no-fallthrough.js +6 -6
- package/lib/rules/no-func-assign.js +3 -3
- package/lib/rules/no-global-assign.js +4 -4
- package/lib/rules/no-implicit-coercion.js +10 -10
- package/lib/rules/no-implicit-globals.js +90 -8
- package/lib/rules/no-implied-eval.js +0 -1
- package/lib/rules/no-inline-comments.js +25 -11
- package/lib/rules/no-invalid-this.js +17 -5
- package/lib/rules/no-labels.js +3 -6
- package/lib/rules/no-lone-blocks.js +1 -1
- package/lib/rules/no-loop-func.js +6 -11
- package/lib/rules/no-magic-numbers.js +6 -6
- package/lib/rules/no-misleading-character-class.js +14 -7
- package/lib/rules/no-mixed-operators.js +13 -22
- package/lib/rules/no-mixed-requires.js +0 -1
- package/lib/rules/no-multi-spaces.js +1 -1
- package/lib/rules/no-native-reassign.js +4 -4
- package/lib/rules/no-octal-escape.js +1 -1
- package/lib/rules/no-param-reassign.js +28 -7
- package/lib/rules/no-redeclare.js +1 -1
- package/lib/rules/no-regex-spaces.js +0 -1
- package/lib/rules/no-restricted-imports.js +11 -11
- package/lib/rules/no-self-assign.js +12 -13
- package/lib/rules/no-sequences.js +3 -3
- package/lib/rules/no-setter-return.js +227 -0
- package/lib/rules/no-shadow.js +1 -4
- package/lib/rules/no-tabs.js +8 -2
- package/lib/rules/no-this-before-super.js +12 -13
- package/lib/rules/no-trailing-spaces.js +19 -7
- package/lib/rules/no-underscore-dangle.js +23 -4
- package/lib/rules/no-unexpected-multiline.js +8 -0
- package/lib/rules/no-unmodified-loop-condition.js +16 -29
- package/lib/rules/no-unneeded-ternary.js +3 -3
- package/lib/rules/no-unreachable.js +7 -7
- package/lib/rules/no-unsafe-finally.js +4 -7
- package/lib/rules/no-unsafe-negation.js +32 -9
- package/lib/rules/no-unused-expressions.js +11 -7
- package/lib/rules/no-unused-labels.js +3 -6
- package/lib/rules/no-unused-vars.js +22 -29
- package/lib/rules/no-use-before-define.js +10 -15
- package/lib/rules/no-useless-call.js +4 -4
- package/lib/rules/no-useless-computed-key.js +60 -33
- package/lib/rules/no-useless-concat.js +4 -4
- package/lib/rules/no-useless-constructor.js +14 -22
- package/lib/rules/no-useless-escape.js +29 -8
- package/lib/rules/no-useless-rename.js +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 +21 -22
- package/lib/rules/object-shorthand.js +1 -1
- package/lib/rules/one-var-declaration-per-line.js +2 -2
- package/lib/rules/operator-assignment.js +33 -3
- package/lib/rules/padded-blocks.js +1 -1
- package/lib/rules/padding-line-between-statements.js +0 -16
- package/lib/rules/prefer-arrow-callback.js +6 -6
- package/lib/rules/prefer-const.js +27 -28
- package/lib/rules/prefer-destructuring.js +1 -7
- package/lib/rules/prefer-exponentiation-operator.js +189 -0
- package/lib/rules/prefer-named-capture-group.js +0 -1
- package/lib/rules/prefer-numeric-literals.js +32 -4
- package/lib/rules/prefer-object-spread.js +7 -7
- package/lib/rules/prefer-rest-params.js +3 -6
- package/lib/rules/prefer-spread.js +4 -4
- package/lib/rules/prefer-template.js +5 -6
- package/lib/rules/quote-props.js +1 -1
- package/lib/rules/quotes.js +5 -6
- package/lib/rules/radix.js +5 -10
- package/lib/rules/require-await.js +10 -5
- package/lib/rules/require-yield.js +2 -2
- package/lib/rules/rest-spread-spacing.js +1 -1
- package/lib/rules/semi.js +6 -3
- package/lib/rules/sort-imports.js +3 -4
- package/lib/rules/sort-keys.js +1 -3
- package/lib/rules/space-before-blocks.js +1 -2
- package/lib/rules/space-in-parens.js +4 -4
- package/lib/rules/space-infix-ops.js +6 -6
- package/lib/rules/spaced-comment.js +20 -22
- package/lib/rules/strict.js +2 -4
- package/lib/rules/symbol-description.js +1 -2
- package/lib/rules/template-curly-spacing.js +2 -2
- package/lib/rules/use-isnan.js +40 -3
- package/lib/rules/utils/ast-utils.js +84 -85
- package/lib/rules/utils/fix-tracker.js +0 -6
- package/lib/rules/utils/lazy-loading-rule-map.js +0 -1
- package/lib/rules/vars-on-top.js +11 -11
- package/lib/shared/config-ops.js +2 -2
- package/lib/shared/runtime-info.js +8 -8
- package/lib/shared/traverser.js +2 -0
- package/lib/shared/types.js +9 -0
- package/lib/source-code/source-code.js +94 -17
- package/lib/source-code/token-store/backward-token-comment-cursor.js +5 -5
- package/lib/source-code/token-store/backward-token-cursor.js +5 -5
- package/lib/source-code/token-store/cursors.js +17 -19
- package/lib/source-code/token-store/decorative-cursor.js +1 -1
- package/lib/source-code/token-store/filter-cursor.js +2 -2
- package/lib/source-code/token-store/forward-token-comment-cursor.js +5 -5
- package/lib/source-code/token-store/forward-token-cursor.js +5 -5
- package/lib/source-code/token-store/index.js +86 -92
- package/lib/source-code/token-store/limit-cursor.js +2 -2
- package/lib/source-code/token-store/padded-token-cursor.js +7 -7
- package/lib/source-code/token-store/skip-cursor.js +2 -2
- package/lib/source-code/token-store/utils.js +9 -13
- package/package.json +9 -7
- package/lib/cli-engine/ignored-paths.js +0 -362
@@ -26,10 +26,23 @@ module.exports = {
|
|
26
26
|
url: "https://eslint.org/docs/rules/no-invalid-this"
|
27
27
|
},
|
28
28
|
|
29
|
-
schema: [
|
29
|
+
schema: [
|
30
|
+
{
|
31
|
+
type: "object",
|
32
|
+
properties: {
|
33
|
+
capIsConstructor: {
|
34
|
+
type: "boolean",
|
35
|
+
default: true
|
36
|
+
}
|
37
|
+
},
|
38
|
+
additionalProperties: false
|
39
|
+
}
|
40
|
+
]
|
30
41
|
},
|
31
42
|
|
32
43
|
create(context) {
|
44
|
+
const options = context.options[0] || {};
|
45
|
+
const capIsConstructor = options.capIsConstructor !== false;
|
33
46
|
const stack = [],
|
34
47
|
sourceCode = context.getSourceCode();
|
35
48
|
|
@@ -38,7 +51,6 @@ module.exports = {
|
|
38
51
|
*
|
39
52
|
* The return value has a flag that whether or not `this` keyword is valid.
|
40
53
|
* The flag is initialized when got at the first time.
|
41
|
-
*
|
42
54
|
* @returns {{valid: boolean}}
|
43
55
|
* an object which has a flag that whether or not `this` keyword is valid.
|
44
56
|
*/
|
@@ -49,7 +61,8 @@ module.exports = {
|
|
49
61
|
current.init = true;
|
50
62
|
current.valid = !astUtils.isDefaultThisBinding(
|
51
63
|
current.node,
|
52
|
-
sourceCode
|
64
|
+
sourceCode,
|
65
|
+
{ capIsConstructor }
|
53
66
|
);
|
54
67
|
}
|
55
68
|
return current;
|
@@ -61,8 +74,7 @@ module.exports = {
|
|
61
74
|
* The checking context is not initialized yet.
|
62
75
|
* Because most functions don't have `this` keyword.
|
63
76
|
* When `this` keyword was found, the checking context is initialized.
|
64
|
-
*
|
65
|
-
* @param {ASTNode} node - A function node that was entered.
|
77
|
+
* @param {ASTNode} node A function node that was entered.
|
66
78
|
* @returns {void}
|
67
79
|
*/
|
68
80
|
function enterFunction(node) {
|
package/lib/rules/no-labels.js
CHANGED
@@ -51,8 +51,7 @@ module.exports = {
|
|
51
51
|
|
52
52
|
/**
|
53
53
|
* Gets the kind of a given node.
|
54
|
-
*
|
55
|
-
* @param {ASTNode} node - A node to get.
|
54
|
+
* @param {ASTNode} node A node to get.
|
56
55
|
* @returns {string} The kind of the node.
|
57
56
|
*/
|
58
57
|
function getBodyKind(node) {
|
@@ -67,8 +66,7 @@ module.exports = {
|
|
67
66
|
|
68
67
|
/**
|
69
68
|
* Checks whether the label of a given kind is allowed or not.
|
70
|
-
*
|
71
|
-
* @param {string} kind - A kind to check.
|
69
|
+
* @param {string} kind A kind to check.
|
72
70
|
* @returns {boolean} `true` if the kind is allowed.
|
73
71
|
*/
|
74
72
|
function isAllowed(kind) {
|
@@ -81,8 +79,7 @@ module.exports = {
|
|
81
79
|
|
82
80
|
/**
|
83
81
|
* Checks whether a given name is a label of a loop or not.
|
84
|
-
*
|
85
|
-
* @param {string} label - A name of a label to check.
|
82
|
+
* @param {string} label A name of a label to check.
|
86
83
|
* @returns {boolean} `true` if the name is a label of a loop.
|
87
84
|
*/
|
88
85
|
function getKind(label) {
|
@@ -14,8 +14,7 @@
|
|
14
14
|
*
|
15
15
|
* We don't need to check nested functions, so this ignores those.
|
16
16
|
* `Scope.through` contains references of nested functions.
|
17
|
-
*
|
18
|
-
* @param {ASTNode} node - An AST node to get.
|
17
|
+
* @param {ASTNode} node An AST node to get.
|
19
18
|
* @returns {ASTNode|null} The containing loop node of the specified node, or
|
20
19
|
* `null`.
|
21
20
|
*/
|
@@ -63,9 +62,8 @@ function getContainingLoopNode(node) {
|
|
63
62
|
/**
|
64
63
|
* Gets the containing loop node of a given node.
|
65
64
|
* If the loop was nested, this returns the most outer loop.
|
66
|
-
*
|
67
|
-
* @param {ASTNode}
|
68
|
-
* @param {ASTNode|null} excludedNode - A node that the result node should not
|
65
|
+
* @param {ASTNode} node A node to get. This is a loop node.
|
66
|
+
* @param {ASTNode|null} excludedNode A node that the result node should not
|
69
67
|
* include.
|
70
68
|
* @returns {ASTNode} The most outer loop node.
|
71
69
|
*/
|
@@ -85,9 +83,8 @@ function getTopLoopNode(node, excludedNode) {
|
|
85
83
|
/**
|
86
84
|
* Checks whether a given reference which refers to an upper scope's variable is
|
87
85
|
* safe or not.
|
88
|
-
*
|
89
|
-
* @param {
|
90
|
-
* @param {eslint-scope.Reference} reference - A reference to check.
|
86
|
+
* @param {ASTNode} loopNode A containing loop node.
|
87
|
+
* @param {eslint-scope.Reference} reference A reference to check.
|
91
88
|
* @returns {boolean} `true` if the reference is safe or not.
|
92
89
|
*/
|
93
90
|
function isSafe(loopNode, reference) {
|
@@ -131,8 +128,7 @@ function isSafe(loopNode, reference) {
|
|
131
128
|
* It's safeafe if the reference matches one of the following condition.
|
132
129
|
* - is readonly.
|
133
130
|
* - doesn't exist inside a local function and after the border.
|
134
|
-
*
|
135
|
-
* @param {eslint-scope.Reference} upperRef - A reference to check.
|
131
|
+
* @param {eslint-scope.Reference} upperRef A reference to check.
|
136
132
|
* @returns {boolean} `true` if the reference is safe.
|
137
133
|
*/
|
138
134
|
function isSafeReference(upperRef) {
|
@@ -177,7 +173,6 @@ module.exports = {
|
|
177
173
|
*
|
178
174
|
* - has a loop node in ancestors.
|
179
175
|
* - has any references which refers to an unsafe variable.
|
180
|
-
*
|
181
176
|
* @param {ASTNode} node The AST node to check.
|
182
177
|
* @returns {boolean} Whether or not the node is within a loop.
|
183
178
|
*/
|
@@ -61,7 +61,7 @@ module.exports = {
|
|
61
61
|
|
62
62
|
/**
|
63
63
|
* Returns whether the node is number literal
|
64
|
-
* @param {Node} node
|
64
|
+
* @param {Node} node the node literal being evaluated
|
65
65
|
* @returns {boolean} true if the node is a number literal
|
66
66
|
*/
|
67
67
|
function isNumber(node) {
|
@@ -70,7 +70,7 @@ module.exports = {
|
|
70
70
|
|
71
71
|
/**
|
72
72
|
* Returns whether the number should be ignored
|
73
|
-
* @param {number} num
|
73
|
+
* @param {number} num the number
|
74
74
|
* @returns {boolean} true if the number should be ignored
|
75
75
|
*/
|
76
76
|
function shouldIgnoreNumber(num) {
|
@@ -79,8 +79,8 @@ module.exports = {
|
|
79
79
|
|
80
80
|
/**
|
81
81
|
* Returns whether the number should be ignored when used as a radix within parseInt() or Number.parseInt()
|
82
|
-
* @param {ASTNode} parent
|
83
|
-
* @param {ASTNode} node
|
82
|
+
* @param {ASTNode} parent the non-"UnaryExpression" parent
|
83
|
+
* @param {ASTNode} node the node literal being evaluated
|
84
84
|
* @returns {boolean} true if the number should be ignored
|
85
85
|
*/
|
86
86
|
function shouldIgnoreParseInt(parent, node) {
|
@@ -93,7 +93,7 @@ module.exports = {
|
|
93
93
|
|
94
94
|
/**
|
95
95
|
* Returns whether the number should be ignored when used to define a JSX prop
|
96
|
-
* @param {ASTNode} parent
|
96
|
+
* @param {ASTNode} parent the non-"UnaryExpression" parent
|
97
97
|
* @returns {boolean} true if the number should be ignored
|
98
98
|
*/
|
99
99
|
function shouldIgnoreJSXNumbers(parent) {
|
@@ -102,7 +102,7 @@ module.exports = {
|
|
102
102
|
|
103
103
|
/**
|
104
104
|
* Returns whether the number should be ignored when used as an array index with enabled 'ignoreArrayIndexes' option.
|
105
|
-
* @param {ASTNode} parent
|
105
|
+
* @param {ASTNode} parent the non-"UnaryExpression" parent.
|
106
106
|
* @returns {boolean} true if the number should be ignored
|
107
107
|
*/
|
108
108
|
function shouldIgnoreArrayIndexes(parent) {
|
@@ -16,7 +16,6 @@ const { isCombiningCharacter, isEmojiModifier, isRegionalIndicatorSymbol, isSurr
|
|
16
16
|
*
|
17
17
|
* CharacterClassRange syntax can steal a part of character sequence,
|
18
18
|
* so this function reverts CharacterClassRange syntax and restore the sequence.
|
19
|
-
*
|
20
19
|
* @param {regexpp.AST.CharacterClassElement[]} nodes The node list to iterate character sequences.
|
21
20
|
* @returns {IterableIterator<number[]>} The list of character sequences.
|
22
21
|
*/
|
@@ -131,12 +130,6 @@ module.exports = {
|
|
131
130
|
* @returns {void}
|
132
131
|
*/
|
133
132
|
function verify(node, pattern, flags) {
|
134
|
-
const patternNode = parser.parsePattern(
|
135
|
-
pattern,
|
136
|
-
0,
|
137
|
-
pattern.length,
|
138
|
-
flags.includes("u")
|
139
|
-
);
|
140
133
|
const has = {
|
141
134
|
surrogatePairWithoutUFlag: false,
|
142
135
|
combiningClass: false,
|
@@ -145,6 +138,20 @@ module.exports = {
|
|
145
138
|
regionalIndicatorSymbol: false,
|
146
139
|
zwj: false
|
147
140
|
};
|
141
|
+
let patternNode;
|
142
|
+
|
143
|
+
try {
|
144
|
+
patternNode = parser.parsePattern(
|
145
|
+
pattern,
|
146
|
+
0,
|
147
|
+
pattern.length,
|
148
|
+
flags.includes("u")
|
149
|
+
);
|
150
|
+
} catch (e) {
|
151
|
+
|
152
|
+
// Ignore regular expressions with syntax errors
|
153
|
+
return;
|
154
|
+
}
|
148
155
|
|
149
156
|
visitRegExpAST(patternNode, {
|
150
157
|
onCharacterClassEnter(ccNode) {
|
@@ -40,8 +40,7 @@ const TARGET_NODE_TYPE = /^(?:Binary|Logical|Conditional)Expression$/u;
|
|
40
40
|
|
41
41
|
/**
|
42
42
|
* Normalizes options.
|
43
|
-
*
|
44
|
-
* @param {Object|undefined} options - A options object to normalize.
|
43
|
+
* @param {Object|undefined} options A options object to normalize.
|
45
44
|
* @returns {Object} Normalized option object.
|
46
45
|
*/
|
47
46
|
function normalizeOptions(options = {}) {
|
@@ -57,10 +56,9 @@ function normalizeOptions(options = {}) {
|
|
57
56
|
|
58
57
|
/**
|
59
58
|
* Checks whether any group which includes both given operator exists or not.
|
60
|
-
*
|
61
|
-
* @param {
|
62
|
-
* @param {string}
|
63
|
-
* @param {string} right - Another operator.
|
59
|
+
* @param {Array.<string[]>} groups A list of groups to check.
|
60
|
+
* @param {string} left An operator.
|
61
|
+
* @param {string} right Another operator.
|
64
62
|
* @returns {boolean} `true` if such group existed.
|
65
63
|
*/
|
66
64
|
function includesBothInAGroup(groups, left, right) {
|
@@ -69,8 +67,7 @@ function includesBothInAGroup(groups, left, right) {
|
|
69
67
|
|
70
68
|
/**
|
71
69
|
* Checks whether the given node is a conditional expression and returns the test node else the left node.
|
72
|
-
*
|
73
|
-
* @param {ASTNode} node - A node which can be a BinaryExpression or a LogicalExpression node.
|
70
|
+
* @param {ASTNode} node A node which can be a BinaryExpression or a LogicalExpression node.
|
74
71
|
* This parent node can be BinaryExpression, LogicalExpression
|
75
72
|
* , or a ConditionalExpression node
|
76
73
|
* @returns {ASTNode} node the appropriate node(left or test).
|
@@ -124,8 +121,7 @@ module.exports = {
|
|
124
121
|
|
125
122
|
/**
|
126
123
|
* Checks whether a given node should be ignored by options or not.
|
127
|
-
*
|
128
|
-
* @param {ASTNode} node - A node to check. This is a BinaryExpression
|
124
|
+
* @param {ASTNode} node A node to check. This is a BinaryExpression
|
129
125
|
* node or a LogicalExpression node. This parent node is one of
|
130
126
|
* them, too.
|
131
127
|
* @returns {boolean} `true` if the node should be ignored.
|
@@ -146,8 +142,7 @@ module.exports = {
|
|
146
142
|
/**
|
147
143
|
* Checks whether the operator of a given node is mixed with parent
|
148
144
|
* node's operator or not.
|
149
|
-
*
|
150
|
-
* @param {ASTNode} node - A node to check. This is a BinaryExpression
|
145
|
+
* @param {ASTNode} node A node to check. This is a BinaryExpression
|
151
146
|
* node or a LogicalExpression node. This parent node is one of
|
152
147
|
* them, too.
|
153
148
|
* @returns {boolean} `true` if the node was mixed.
|
@@ -163,8 +158,7 @@ module.exports = {
|
|
163
158
|
/**
|
164
159
|
* Checks whether the operator of a given node is mixed with a
|
165
160
|
* conditional expression.
|
166
|
-
*
|
167
|
-
* @param {ASTNode} node - A node to check. This is a conditional
|
161
|
+
* @param {ASTNode} node A node to check. This is a conditional
|
168
162
|
* expression node
|
169
163
|
* @returns {boolean} `true` if the node was mixed.
|
170
164
|
*/
|
@@ -174,8 +168,7 @@ module.exports = {
|
|
174
168
|
|
175
169
|
/**
|
176
170
|
* Gets the operator token of a given node.
|
177
|
-
*
|
178
|
-
* @param {ASTNode} node - A node to check. This is a BinaryExpression
|
171
|
+
* @param {ASTNode} node A node to check. This is a BinaryExpression
|
179
172
|
* node or a LogicalExpression node.
|
180
173
|
* @returns {Token} The operator token of the node.
|
181
174
|
*/
|
@@ -186,8 +179,7 @@ module.exports = {
|
|
186
179
|
/**
|
187
180
|
* Reports both the operator of a given node and the operator of the
|
188
181
|
* parent node.
|
189
|
-
*
|
190
|
-
* @param {ASTNode} node - A node to check. This is a BinaryExpression
|
182
|
+
* @param {ASTNode} node A node to check. This is a BinaryExpression
|
191
183
|
* node or a LogicalExpression node. This parent node is one of
|
192
184
|
* them, too.
|
193
185
|
* @returns {void}
|
@@ -205,13 +197,13 @@ module.exports = {
|
|
205
197
|
|
206
198
|
context.report({
|
207
199
|
node: left,
|
208
|
-
loc: getOperatorToken(left).loc
|
200
|
+
loc: getOperatorToken(left).loc,
|
209
201
|
message,
|
210
202
|
data
|
211
203
|
});
|
212
204
|
context.report({
|
213
205
|
node: right,
|
214
|
-
loc: getOperatorToken(right).loc
|
206
|
+
loc: getOperatorToken(right).loc,
|
215
207
|
message,
|
216
208
|
data
|
217
209
|
});
|
@@ -220,8 +212,7 @@ module.exports = {
|
|
220
212
|
/**
|
221
213
|
* Checks between the operator of this node and the operator of the
|
222
214
|
* parent node.
|
223
|
-
*
|
224
|
-
* @param {ASTNode} node - A node to check.
|
215
|
+
* @param {ASTNode} node A node to check.
|
225
216
|
* @returns {void}
|
226
217
|
*/
|
227
218
|
function check(node) {
|
@@ -121,7 +121,7 @@ module.exports = {
|
|
121
121
|
|
122
122
|
context.report({
|
123
123
|
node: rightToken,
|
124
|
-
loc: rightToken.loc.start,
|
124
|
+
loc: { start: leftToken.loc.end, end: rightToken.loc.start },
|
125
125
|
message: "Multiple spaces found before '{{displayValue}}'.",
|
126
126
|
data: { displayValue },
|
127
127
|
fix: fixer => fixer.replaceTextRange([leftToken.range[1], rightToken.range[0]], " ")
|
@@ -46,9 +46,9 @@ module.exports = {
|
|
46
46
|
|
47
47
|
/**
|
48
48
|
* Reports write references.
|
49
|
-
* @param {Reference} reference
|
50
|
-
* @param {int} index
|
51
|
-
* @param {Reference[]} references
|
49
|
+
* @param {Reference} reference A reference to check.
|
50
|
+
* @param {int} index The index of the reference in the references.
|
51
|
+
* @param {Reference[]} references The array that the reference belongs to.
|
52
52
|
* @returns {void}
|
53
53
|
*/
|
54
54
|
function checkReference(reference, index, references) {
|
@@ -73,7 +73,7 @@ module.exports = {
|
|
73
73
|
|
74
74
|
/**
|
75
75
|
* Reports write references if a given variable is read-only builtin.
|
76
|
-
* @param {Variable} variable
|
76
|
+
* @param {Variable} variable A variable to check.
|
77
77
|
* @returns {void}
|
78
78
|
*/
|
79
79
|
function checkVariable(variable) {
|
@@ -38,7 +38,7 @@ module.exports = {
|
|
38
38
|
|
39
39
|
// \0 represents a valid NULL character if it isn't followed by a digit.
|
40
40
|
const match = node.raw.match(
|
41
|
-
/^(?:[^\\]|\\.)*?\\([0-3][0-7]{1,2}|[4-7][0-7]|[1-7])/
|
41
|
+
/^(?:[^\\]|\\.)*?\\([0-3][0-7]{1,2}|[4-7][0-7]|0(?=[89])|[1-7])/su
|
42
42
|
);
|
43
43
|
|
44
44
|
if (match) {
|
@@ -45,6 +45,13 @@ module.exports = {
|
|
45
45
|
type: "string"
|
46
46
|
},
|
47
47
|
uniqueItems: true
|
48
|
+
},
|
49
|
+
ignorePropertyModificationsForRegex: {
|
50
|
+
type: "array",
|
51
|
+
items: {
|
52
|
+
type: "string"
|
53
|
+
},
|
54
|
+
uniqueItems: true
|
48
55
|
}
|
49
56
|
},
|
50
57
|
additionalProperties: false
|
@@ -57,10 +64,11 @@ module.exports = {
|
|
57
64
|
create(context) {
|
58
65
|
const props = context.options[0] && context.options[0].props;
|
59
66
|
const ignoredPropertyAssignmentsFor = context.options[0] && context.options[0].ignorePropertyModificationsFor || [];
|
67
|
+
const ignoredPropertyAssignmentsForRegex = context.options[0] && context.options[0].ignorePropertyModificationsForRegex || [];
|
60
68
|
|
61
69
|
/**
|
62
70
|
* Checks whether or not the reference modifies properties of its variable.
|
63
|
-
* @param {Reference} reference
|
71
|
+
* @param {Reference} reference A reference to check.
|
64
72
|
* @returns {boolean} Whether or not the reference modifies properties of its variable.
|
65
73
|
*/
|
66
74
|
function isModifyingProp(reference) {
|
@@ -136,11 +144,24 @@ module.exports = {
|
|
136
144
|
return false;
|
137
145
|
}
|
138
146
|
|
147
|
+
/**
|
148
|
+
* Tests that an identifier name matches any of the ignored property assignments.
|
149
|
+
* First we test strings in ignoredPropertyAssignmentsFor.
|
150
|
+
* Then we instantiate and test RegExp objects from ignoredPropertyAssignmentsForRegex strings.
|
151
|
+
* @param {string} identifierName A string that describes the name of an identifier to
|
152
|
+
* ignore property assignments for.
|
153
|
+
* @returns {boolean} Whether the string matches an ignored property assignment regular expression or not.
|
154
|
+
*/
|
155
|
+
function isIgnoredPropertyAssignment(identifierName) {
|
156
|
+
return ignoredPropertyAssignmentsFor.includes(identifierName) ||
|
157
|
+
ignoredPropertyAssignmentsForRegex.some(ignored => new RegExp(ignored, "u").test(identifierName));
|
158
|
+
}
|
159
|
+
|
139
160
|
/**
|
140
161
|
* Reports a reference if is non initializer and writable.
|
141
|
-
* @param {Reference} reference
|
142
|
-
* @param {int} index
|
143
|
-
* @param {Reference[]} references
|
162
|
+
* @param {Reference} reference A reference to check.
|
163
|
+
* @param {int} index The index of the reference in the references.
|
164
|
+
* @param {Reference[]} references The array that the reference belongs to.
|
144
165
|
* @returns {void}
|
145
166
|
*/
|
146
167
|
function checkReference(reference, index, references) {
|
@@ -157,7 +178,7 @@ module.exports = {
|
|
157
178
|
) {
|
158
179
|
if (reference.isWrite()) {
|
159
180
|
context.report({ node: identifier, message: "Assignment to function parameter '{{name}}'.", data: { name: identifier.name } });
|
160
|
-
} else if (props && isModifyingProp(reference) &&
|
181
|
+
} else if (props && isModifyingProp(reference) && !isIgnoredPropertyAssignment(identifier.name)) {
|
161
182
|
context.report({ node: identifier, message: "Assignment to property of function parameter '{{name}}'.", data: { name: identifier.name } });
|
162
183
|
}
|
163
184
|
}
|
@@ -165,7 +186,7 @@ module.exports = {
|
|
165
186
|
|
166
187
|
/**
|
167
188
|
* Finds and reports references that are non initializer and writable.
|
168
|
-
* @param {Variable} variable
|
189
|
+
* @param {Variable} variable A variable to check.
|
169
190
|
* @returns {void}
|
170
191
|
*/
|
171
192
|
function checkVariable(variable) {
|
@@ -176,7 +197,7 @@ module.exports = {
|
|
176
197
|
|
177
198
|
/**
|
178
199
|
* Checks parameters of a given function node.
|
179
|
-
* @param {ASTNode} node
|
200
|
+
* @param {ASTNode} node A function node to check.
|
180
201
|
* @returns {void}
|
181
202
|
*/
|
182
203
|
function checkForFunction(node) {
|
@@ -52,7 +52,6 @@ module.exports = {
|
|
52
52
|
|
53
53
|
/**
|
54
54
|
* Validate regular expression
|
55
|
-
*
|
56
55
|
* @param {ASTNode} nodeToReport Node to report.
|
57
56
|
* @param {string} pattern Regular expression pattern to validate.
|
58
57
|
* @param {string} rawPattern Raw representation of the pattern in the source code.
|
@@ -116,7 +116,7 @@ module.exports = {
|
|
116
116
|
|
117
117
|
/**
|
118
118
|
* Checks to see if "*" is being used to import everything.
|
119
|
-
* @param {Set.<string>} importNames
|
119
|
+
* @param {Set.<string>} importNames Set of import names that are being imported
|
120
120
|
* @returns {boolean} whether everything is imported or not
|
121
121
|
*/
|
122
122
|
function isEverythingImported(importNames) {
|
@@ -145,7 +145,7 @@ module.exports = {
|
|
145
145
|
|
146
146
|
/**
|
147
147
|
* Report a restricted path specifically for patterns.
|
148
|
-
* @param {node} node
|
148
|
+
* @param {node} node representing the restricted path reference
|
149
149
|
* @returns {void}
|
150
150
|
* @private
|
151
151
|
*/
|
@@ -163,8 +163,8 @@ module.exports = {
|
|
163
163
|
|
164
164
|
/**
|
165
165
|
* Report a restricted path specifically when using the '*' import.
|
166
|
-
* @param {string} importSource
|
167
|
-
* @param {node} node
|
166
|
+
* @param {string} importSource path of the import
|
167
|
+
* @param {node} node representing the restricted path reference
|
168
168
|
* @returns {void}
|
169
169
|
* @private
|
170
170
|
*/
|
@@ -185,8 +185,8 @@ module.exports = {
|
|
185
185
|
|
186
186
|
/**
|
187
187
|
* Check if the given importSource is restricted because '*' is being imported.
|
188
|
-
* @param {string} importSource
|
189
|
-
* @param {Set.<string>} importNames
|
188
|
+
* @param {string} importSource path of the import
|
189
|
+
* @param {Set.<string>} importNames Set of import names that are being imported
|
190
190
|
* @returns {boolean} whether the path is restricted
|
191
191
|
* @private
|
192
192
|
*/
|
@@ -198,8 +198,8 @@ module.exports = {
|
|
198
198
|
|
199
199
|
/**
|
200
200
|
* Check if the given importNames are restricted given a list of restrictedImportNames.
|
201
|
-
* @param {Set.<string>} importNames
|
202
|
-
* @param {string[]} restrictedImportNames
|
201
|
+
* @param {Set.<string>} importNames Set of import names that are being imported
|
202
|
+
* @param {string[]} restrictedImportNames array of import names that are restricted for this import
|
203
203
|
* @returns {boolean} whether the objectName is restricted
|
204
204
|
* @private
|
205
205
|
*/
|
@@ -211,8 +211,8 @@ module.exports = {
|
|
211
211
|
|
212
212
|
/**
|
213
213
|
* Check if the given importSource is a restricted path.
|
214
|
-
* @param {string} importSource
|
215
|
-
* @param {Set.<string>} importNames
|
214
|
+
* @param {string} importSource path of the import
|
215
|
+
* @param {Set.<string>} importNames Set of import names that are being imported
|
216
216
|
* @returns {boolean} whether the variable is a restricted path or not
|
217
217
|
* @private
|
218
218
|
*/
|
@@ -232,7 +232,7 @@ module.exports = {
|
|
232
232
|
|
233
233
|
/**
|
234
234
|
* Check if the given importSource is restricted by a pattern.
|
235
|
-
* @param {string} importSource
|
235
|
+
* @param {string} importSource path of the import
|
236
236
|
* @returns {boolean} whether the variable is a restricted pattern or not
|
237
237
|
* @private
|
238
238
|
*/
|
@@ -20,9 +20,8 @@ const SPACES = /\s+/gu;
|
|
20
20
|
/**
|
21
21
|
* Checks whether the property of 2 given member expression nodes are the same
|
22
22
|
* property or not.
|
23
|
-
*
|
24
|
-
* @param {ASTNode}
|
25
|
-
* @param {ASTNode} right - Another member expression node to check.
|
23
|
+
* @param {ASTNode} left A member expression node to check.
|
24
|
+
* @param {ASTNode} right Another member expression node to check.
|
26
25
|
* @returns {boolean} `true` if the member expressions have the same property.
|
27
26
|
*/
|
28
27
|
function isSameProperty(left, right) {
|
@@ -43,9 +42,8 @@ function isSameProperty(left, right) {
|
|
43
42
|
/**
|
44
43
|
* Checks whether 2 given member expression nodes are the reference to the same
|
45
44
|
* property or not.
|
46
|
-
*
|
47
|
-
* @param {ASTNode}
|
48
|
-
* @param {ASTNode} right - Another member expression node to check.
|
45
|
+
* @param {ASTNode} left A member expression node to check.
|
46
|
+
* @param {ASTNode} right Another member expression node to check.
|
49
47
|
* @returns {boolean} `true` if the member expressions are the reference to the
|
50
48
|
* same property or not.
|
51
49
|
*/
|
@@ -63,18 +61,20 @@ function isSameMember(left, right) {
|
|
63
61
|
if (lobj.type === "MemberExpression") {
|
64
62
|
return isSameMember(lobj, robj);
|
65
63
|
}
|
64
|
+
if (lobj.type === "ThisExpression") {
|
65
|
+
return true;
|
66
|
+
}
|
66
67
|
return lobj.type === "Identifier" && lobj.name === robj.name;
|
67
68
|
}
|
68
69
|
|
69
70
|
/**
|
70
71
|
* Traverses 2 Pattern nodes in parallel, then reports self-assignments.
|
71
|
-
*
|
72
|
-
* @param {ASTNode|null} left - A left node to traverse. This is a Pattern or
|
72
|
+
* @param {ASTNode|null} left A left node to traverse. This is a Pattern or
|
73
73
|
* a Property.
|
74
|
-
* @param {ASTNode|null} right
|
74
|
+
* @param {ASTNode|null} right A right node to traverse. This is a Pattern or
|
75
75
|
* a Property.
|
76
|
-
* @param {boolean} props
|
77
|
-
* @param {Function} report
|
76
|
+
* @param {boolean} props The flag to check member expressions as well.
|
77
|
+
* @param {Function} report A callback function to report.
|
78
78
|
* @returns {void}
|
79
79
|
*/
|
80
80
|
function eachSelfAssignment(left, right, props, report) {
|
@@ -205,8 +205,7 @@ module.exports = {
|
|
205
205
|
|
206
206
|
/**
|
207
207
|
* Reports a given node as self assignments.
|
208
|
-
*
|
209
|
-
* @param {ASTNode} node - A node to report. This is an Identifier node.
|
208
|
+
* @param {ASTNode} node A node to report. This is an Identifier node.
|
210
209
|
* @returns {void}
|
211
210
|
*/
|
212
211
|
function report(node) {
|
@@ -54,7 +54,7 @@ module.exports = {
|
|
54
54
|
/**
|
55
55
|
* Determines whether a node is required by the grammar to be wrapped in
|
56
56
|
* parens, e.g. the test of an if statement.
|
57
|
-
* @param {ASTNode} node
|
57
|
+
* @param {ASTNode} node The AST node
|
58
58
|
* @returns {boolean} True if parens around node belong to parent node.
|
59
59
|
*/
|
60
60
|
function requiresExtraParens(node) {
|
@@ -64,7 +64,7 @@ module.exports = {
|
|
64
64
|
|
65
65
|
/**
|
66
66
|
* Check if a node is wrapped in parens.
|
67
|
-
* @param {ASTNode} node
|
67
|
+
* @param {ASTNode} node The AST node
|
68
68
|
* @returns {boolean} True if the node has a paren on each side.
|
69
69
|
*/
|
70
70
|
function isParenthesised(node) {
|
@@ -73,7 +73,7 @@ module.exports = {
|
|
73
73
|
|
74
74
|
/**
|
75
75
|
* Check if a node is wrapped in two levels of parens.
|
76
|
-
* @param {ASTNode} node
|
76
|
+
* @param {ASTNode} node The AST node
|
77
77
|
* @returns {boolean} True if two parens surround the node on each side.
|
78
78
|
*/
|
79
79
|
function isParenthesisedTwice(node) {
|