eslint 5.0.0 → 5.3.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 +78 -0
- package/README.md +1 -1
- package/conf/eslint-recommended.js +4 -0
- package/lib/cli-engine.js +37 -76
- package/lib/cli.js +1 -1
- package/lib/code-path-analysis/code-path-analyzer.js +2 -2
- package/lib/config/config-initializer.js +8 -8
- package/lib/config/config-validator.js +13 -6
- package/lib/config.js +1 -1
- package/lib/formatters/stylish.js +1 -1
- package/lib/ignored-paths.js +125 -37
- package/lib/linter.js +6 -7
- package/lib/rules/array-bracket-newline.js +1 -1
- package/lib/rules/array-bracket-spacing.js +1 -1
- package/lib/rules/array-callback-return.js +1 -1
- package/lib/rules/array-element-newline.js +1 -1
- package/lib/rules/arrow-body-style.js +1 -1
- package/lib/rules/arrow-parens.js +1 -1
- package/lib/rules/arrow-spacing.js +1 -1
- package/lib/rules/block-spacing.js +1 -1
- package/lib/rules/brace-style.js +1 -1
- package/lib/rules/capitalized-comments.js +1 -1
- package/lib/rules/comma-dangle.js +1 -1
- package/lib/rules/comma-spacing.js +1 -1
- package/lib/rules/comma-style.js +1 -1
- package/lib/rules/complexity.js +1 -1
- package/lib/rules/computed-property-spacing.js +1 -1
- package/lib/rules/consistent-return.js +1 -1
- package/lib/rules/curly.js +1 -1
- package/lib/rules/dot-location.js +1 -1
- package/lib/rules/dot-notation.js +1 -1
- package/lib/rules/eqeqeq.js +1 -1
- package/lib/rules/func-call-spacing.js +1 -1
- package/lib/rules/func-name-matching.js +1 -1
- package/lib/rules/func-names.js +1 -1
- package/lib/rules/function-paren-newline.js +1 -1
- package/lib/rules/getter-return.js +1 -1
- package/lib/rules/indent-legacy.js +1 -1
- package/lib/rules/indent.js +37 -5
- package/lib/rules/jsx-quotes.js +1 -1
- package/lib/rules/key-spacing.js +2 -2
- package/lib/rules/keyword-spacing.js +1 -1
- package/lib/rules/line-comment-position.js +2 -2
- package/lib/rules/linebreak-style.js +1 -1
- package/lib/rules/lines-around-comment.js +1 -1
- package/lib/rules/lines-around-directive.js +1 -1
- package/lib/rules/lines-between-class-members.js +1 -1
- package/lib/rules/max-len.js +1 -1
- package/lib/rules/max-lines-per-function.js +1 -1
- package/lib/rules/max-lines.js +1 -1
- package/lib/rules/max-params.js +1 -1
- package/lib/rules/max-statements-per-line.js +1 -1
- package/lib/rules/max-statements.js +1 -1
- package/lib/rules/multiline-comment-style.js +1 -1
- package/lib/rules/multiline-ternary.js +1 -1
- package/lib/rules/new-parens.js +1 -1
- package/lib/rules/newline-after-var.js +1 -1
- package/lib/rules/newline-per-chained-call.js +1 -1
- package/lib/rules/no-alert.js +1 -1
- package/lib/rules/no-async-promise-executor.js +33 -0
- package/lib/rules/no-catch-shadow.js +5 -2
- package/lib/rules/no-class-assign.js +1 -1
- package/lib/rules/no-cond-assign.js +1 -1
- package/lib/rules/no-confusing-arrow.js +1 -1
- package/lib/rules/no-console.js +1 -1
- package/lib/rules/no-const-assign.js +1 -1
- package/lib/rules/no-debugger.js +2 -10
- package/lib/rules/no-dupe-keys.js +1 -1
- package/lib/rules/no-else-return.js +1 -1
- package/lib/rules/no-empty-function.js +1 -1
- package/lib/rules/no-empty.js +1 -1
- package/lib/rules/no-eval.js +1 -1
- package/lib/rules/no-ex-assign.js +1 -1
- package/lib/rules/no-extend-native.js +1 -1
- package/lib/rules/no-extra-bind.js +1 -1
- package/lib/rules/no-extra-boolean-cast.js +1 -1
- package/lib/rules/no-extra-label.js +1 -1
- package/lib/rules/no-extra-parens.js +1 -1
- package/lib/rules/no-extra-semi.js +1 -1
- package/lib/rules/no-floating-decimal.js +1 -1
- package/lib/rules/no-func-assign.js +1 -1
- package/lib/rules/no-implicit-coercion.js +1 -1
- package/lib/rules/no-inline-comments.js +1 -1
- package/lib/rules/no-invalid-this.js +1 -1
- package/lib/rules/no-irregular-whitespace.js +1 -1
- package/lib/rules/no-label-var.js +1 -1
- package/lib/rules/no-labels.js +1 -1
- package/lib/rules/no-misleading-character-class.js +189 -0
- package/lib/rules/no-mixed-operators.js +1 -1
- package/lib/rules/no-multi-spaces.js +1 -1
- package/lib/rules/no-multi-str.js +1 -1
- package/lib/rules/no-regex-spaces.js +1 -1
- package/lib/rules/no-restricted-properties.js +1 -1
- package/lib/rules/no-return-assign.js +1 -1
- package/lib/rules/no-return-await.js +1 -1
- package/lib/rules/no-self-assign.js +1 -1
- package/lib/rules/no-sequences.js +1 -1
- package/lib/rules/no-shadow.js +1 -1
- package/lib/rules/no-this-before-super.js +1 -1
- package/lib/rules/no-throw-literal.js +1 -1
- package/lib/rules/no-trailing-spaces.js +1 -1
- package/lib/rules/no-undef-init.js +1 -1
- package/lib/rules/no-unexpected-multiline.js +1 -1
- package/lib/rules/no-unmodified-loop-condition.js +2 -3
- package/lib/rules/no-unneeded-ternary.js +1 -1
- package/lib/rules/no-unsafe-negation.js +1 -1
- package/lib/rules/no-unused-vars.js +1 -1
- package/lib/rules/no-useless-call.js +1 -1
- package/lib/rules/no-useless-computed-key.js +1 -1
- package/lib/rules/no-useless-concat.js +1 -1
- package/lib/rules/no-useless-escape.js +1 -1
- package/lib/rules/no-useless-return.js +2 -11
- package/lib/rules/no-var.js +1 -1
- package/lib/rules/no-warning-comments.js +1 -1
- package/lib/rules/no-whitespace-before-property.js +1 -1
- package/lib/rules/object-curly-newline.js +1 -1
- package/lib/rules/object-curly-spacing.js +1 -1
- package/lib/rules/object-shorthand.js +1 -1
- package/lib/rules/operator-assignment.js +1 -1
- package/lib/rules/operator-linebreak.js +1 -1
- package/lib/rules/padding-line-between-statements.js +2 -2
- package/lib/rules/prefer-const.js +3 -12
- package/lib/rules/prefer-object-spread.js +154 -197
- package/lib/rules/prefer-promise-reject-errors.js +1 -1
- package/lib/rules/prefer-spread.js +1 -1
- package/lib/rules/prefer-template.js +1 -1
- package/lib/rules/quotes.js +1 -1
- package/lib/rules/radix.js +1 -1
- package/lib/rules/require-atomic-updates.js +239 -0
- package/lib/rules/require-await.js +1 -1
- package/lib/rules/require-unicode-regexp.js +65 -0
- package/lib/rules/semi-spacing.js +1 -1
- package/lib/rules/semi-style.js +1 -1
- package/lib/rules/semi.js +1 -1
- package/lib/rules/sort-keys.js +2 -2
- package/lib/rules/space-before-blocks.js +1 -1
- package/lib/rules/space-before-function-paren.js +1 -1
- package/lib/rules/space-in-parens.js +1 -1
- package/lib/rules/space-unary-ops.js +1 -1
- package/lib/rules/spaced-comment.js +1 -1
- package/lib/rules/strict.js +1 -1
- package/lib/rules/switch-colon-spacing.js +1 -1
- package/lib/rules/symbol-description.js +1 -1
- package/lib/rules/template-curly-spacing.js +1 -1
- package/lib/rules/valid-jsdoc.js +1 -1
- package/lib/rules/wrap-iife.js +1 -1
- package/lib/rules/wrap-regex.js +8 -4
- package/lib/rules/yoda.js +1 -1
- package/lib/testers/rule-tester.js +3 -5
- package/lib/token-store/index.js +1 -1
- package/lib/{ast-utils.js → util/ast-utils.js} +0 -0
- package/lib/{file-finder.js → util/file-finder.js} +0 -0
- package/lib/util/fix-tracker.js +1 -1
- package/lib/util/{glob-util.js → glob-utils.js} +4 -4
- package/lib/util/lint-result-cache.js +146 -0
- package/lib/{logging.js → util/logging.js} +0 -0
- package/lib/util/naming.js +2 -2
- package/lib/util/node-event-generator.js +3 -3
- package/lib/util/{npm-util.js → npm-utils.js} +1 -1
- package/lib/util/{path-util.js → path-utils.js} +1 -1
- package/lib/util/{source-code-util.js → source-code-utils.js} +3 -3
- package/lib/util/source-code.js +1 -1
- package/lib/{timing.js → util/timing.js} +0 -0
- package/lib/util/unicode/index.js +11 -0
- package/lib/util/unicode/is-combining-character.js +13 -0
- package/lib/util/unicode/is-emoji-modifier.js +13 -0
- package/lib/util/unicode/is-regional-indicator-symbol.js +13 -0
- package/lib/util/unicode/is-surrogate-pair.js +14 -0
- package/package.json +6 -5
@@ -0,0 +1,239 @@
|
|
1
|
+
/**
|
2
|
+
* @fileoverview disallow assignments that can lead to race conditions due to usage of `await` or `yield`
|
3
|
+
* @author Teddy Katz
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
const astUtils = require("../util/ast-utils");
|
8
|
+
|
9
|
+
//------------------------------------------------------------------------------
|
10
|
+
// Rule Definition
|
11
|
+
//------------------------------------------------------------------------------
|
12
|
+
|
13
|
+
module.exports = {
|
14
|
+
meta: {
|
15
|
+
docs: {
|
16
|
+
description: "disallow assignments that can lead to race conditions due to usage of `await` or `yield`",
|
17
|
+
category: "Possible Errors",
|
18
|
+
recommended: false,
|
19
|
+
url: "https://eslint.org/docs/rules/require-atomic-updates"
|
20
|
+
},
|
21
|
+
fixable: null,
|
22
|
+
schema: [],
|
23
|
+
messages: {
|
24
|
+
nonAtomicUpdate: "Possible race condition: `{{value}}` might be reassigned based on an outdated value of `{{value}}`."
|
25
|
+
}
|
26
|
+
},
|
27
|
+
|
28
|
+
create(context) {
|
29
|
+
const sourceCode = context.getSourceCode();
|
30
|
+
const identifierToSurroundingFunctionMap = new WeakMap();
|
31
|
+
const expressionsByCodePathSegment = new Map();
|
32
|
+
|
33
|
+
//----------------------------------------------------------------------
|
34
|
+
// Helpers
|
35
|
+
//----------------------------------------------------------------------
|
36
|
+
|
37
|
+
const resolvedVariableCache = new WeakMap();
|
38
|
+
|
39
|
+
/**
|
40
|
+
* Gets the variable scope around this variable reference
|
41
|
+
* @param {ASTNode} identifier An `Identifier` AST node
|
42
|
+
* @returns {Scope|null} An escope Scope
|
43
|
+
*/
|
44
|
+
function getScope(identifier) {
|
45
|
+
for (let currentNode = identifier; currentNode; currentNode = currentNode.parent) {
|
46
|
+
const scope = sourceCode.scopeManager.acquire(currentNode, true);
|
47
|
+
|
48
|
+
if (scope) {
|
49
|
+
return scope;
|
50
|
+
}
|
51
|
+
}
|
52
|
+
return null;
|
53
|
+
}
|
54
|
+
|
55
|
+
/**
|
56
|
+
* Resolves a given identifier to a given scope
|
57
|
+
* @param {ASTNode} identifier An `Identifier` AST node
|
58
|
+
* @param {Scope} scope An escope Scope
|
59
|
+
* @returns {Variable|null} An escope Variable corresponding to the given identifier
|
60
|
+
*/
|
61
|
+
function resolveVariableInScope(identifier, scope) {
|
62
|
+
return scope.variables.find(variable => variable.name === identifier.name) ||
|
63
|
+
(scope.upper ? resolveVariableInScope(identifier, scope.upper) : null);
|
64
|
+
}
|
65
|
+
|
66
|
+
/**
|
67
|
+
* Resolves an identifier to a variable
|
68
|
+
* @param {ASTNode} identifier An identifier node
|
69
|
+
* @returns {Variable|null} The escope Variable that uses this identifier
|
70
|
+
*/
|
71
|
+
function resolveVariable(identifier) {
|
72
|
+
if (!resolvedVariableCache.has(identifier)) {
|
73
|
+
const surroundingScope = getScope(identifier);
|
74
|
+
|
75
|
+
if (surroundingScope) {
|
76
|
+
resolvedVariableCache.set(identifier, resolveVariableInScope(identifier, surroundingScope));
|
77
|
+
} else {
|
78
|
+
resolvedVariableCache.set(identifier, null);
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
return resolvedVariableCache.get(identifier);
|
83
|
+
}
|
84
|
+
|
85
|
+
/**
|
86
|
+
* Checks if an expression is a variable that can only be observed within the given function.
|
87
|
+
* @param {ASTNode} expression The expression to check
|
88
|
+
* @param {ASTNode} surroundingFunction The function node
|
89
|
+
* @returns {boolean} `true` if the expression is a variable which is local to the given function, and is never
|
90
|
+
* referenced in a closure.
|
91
|
+
*/
|
92
|
+
function isLocalVariableWithoutEscape(expression, surroundingFunction) {
|
93
|
+
if (expression.type !== "Identifier") {
|
94
|
+
return false;
|
95
|
+
}
|
96
|
+
|
97
|
+
const variable = resolveVariable(expression);
|
98
|
+
|
99
|
+
if (!variable) {
|
100
|
+
return false;
|
101
|
+
}
|
102
|
+
|
103
|
+
return variable.references.every(reference => identifierToSurroundingFunctionMap.get(reference.identifier) === surroundingFunction) &&
|
104
|
+
variable.defs.every(def => identifierToSurroundingFunctionMap.get(def.name) === surroundingFunction);
|
105
|
+
}
|
106
|
+
|
107
|
+
/**
|
108
|
+
* Reports an AssignmentExpression node that has a non-atomic update
|
109
|
+
* @param {ASTNode} assignmentExpression The assignment that is potentially unsafe
|
110
|
+
* @returns {void}
|
111
|
+
*/
|
112
|
+
function reportAssignment(assignmentExpression) {
|
113
|
+
context.report({
|
114
|
+
node: assignmentExpression,
|
115
|
+
messageId: "nonAtomicUpdate",
|
116
|
+
data: {
|
117
|
+
value: sourceCode.getText(assignmentExpression.left)
|
118
|
+
}
|
119
|
+
});
|
120
|
+
}
|
121
|
+
|
122
|
+
/**
|
123
|
+
* If the control flow graph of a function enters an assignment expression, then does the
|
124
|
+
* both of the following steps in order (possibly with other steps in between) before exiting the
|
125
|
+
* assignment expression, then the assignment might be using an outdated value.
|
126
|
+
* 1. Enters a read of the variable or property assigned in the expression (not necessary if operator assignment is used)
|
127
|
+
* 2. Exits an `await` or `yield` expression
|
128
|
+
*
|
129
|
+
* This function checks for the outdated values and reports them.
|
130
|
+
* @param {CodePathSegment} codePathSegment The current code path segment to traverse
|
131
|
+
* @param {ASTNode} surroundingFunction The function node containing the code path segment
|
132
|
+
* @returns {void}
|
133
|
+
*/
|
134
|
+
function findOutdatedReads(
|
135
|
+
codePathSegment,
|
136
|
+
surroundingFunction,
|
137
|
+
{
|
138
|
+
seenSegments = new Set(),
|
139
|
+
openAssignmentsWithoutReads = new Set(),
|
140
|
+
openAssignmentsWithReads = new Set()
|
141
|
+
} = {}
|
142
|
+
) {
|
143
|
+
if (seenSegments.has(codePathSegment)) {
|
144
|
+
|
145
|
+
// An AssignmentExpression can't contain loops, so it's not necessary to reenter them with new state.
|
146
|
+
return;
|
147
|
+
}
|
148
|
+
|
149
|
+
expressionsByCodePathSegment.get(codePathSegment).forEach(({ entering, node }) => {
|
150
|
+
if (node.type === "AssignmentExpression") {
|
151
|
+
if (entering) {
|
152
|
+
(node.operator === "=" ? openAssignmentsWithoutReads : openAssignmentsWithReads).add(node);
|
153
|
+
} else {
|
154
|
+
openAssignmentsWithoutReads.delete(node);
|
155
|
+
openAssignmentsWithReads.delete(node);
|
156
|
+
}
|
157
|
+
} else if (!entering && (node.type === "AwaitExpression" || node.type === "YieldExpression")) {
|
158
|
+
[...openAssignmentsWithReads]
|
159
|
+
.filter(assignment => !isLocalVariableWithoutEscape(assignment.left, surroundingFunction))
|
160
|
+
.forEach(reportAssignment);
|
161
|
+
|
162
|
+
openAssignmentsWithReads.clear();
|
163
|
+
} else if (!entering && (node.type === "Identifier" || node.type === "MemberExpression")) {
|
164
|
+
[...openAssignmentsWithoutReads]
|
165
|
+
.filter(assignment => (
|
166
|
+
assignment.left !== node &&
|
167
|
+
assignment.left.type === node.type &&
|
168
|
+
astUtils.equalTokens(assignment.left, node, sourceCode)
|
169
|
+
))
|
170
|
+
.forEach(assignment => {
|
171
|
+
openAssignmentsWithoutReads.delete(assignment);
|
172
|
+
openAssignmentsWithReads.add(assignment);
|
173
|
+
});
|
174
|
+
}
|
175
|
+
});
|
176
|
+
|
177
|
+
codePathSegment.nextSegments.forEach(nextSegment => {
|
178
|
+
findOutdatedReads(
|
179
|
+
nextSegment,
|
180
|
+
surroundingFunction,
|
181
|
+
{
|
182
|
+
seenSegments: new Set(seenSegments).add(codePathSegment),
|
183
|
+
openAssignmentsWithoutReads: new Set(openAssignmentsWithoutReads),
|
184
|
+
openAssignmentsWithReads: new Set(openAssignmentsWithReads)
|
185
|
+
}
|
186
|
+
);
|
187
|
+
});
|
188
|
+
}
|
189
|
+
|
190
|
+
//----------------------------------------------------------------------
|
191
|
+
// Public
|
192
|
+
//----------------------------------------------------------------------
|
193
|
+
|
194
|
+
const currentCodePathSegmentStack = [];
|
195
|
+
let currentCodePathSegment = null;
|
196
|
+
const functionStack = [];
|
197
|
+
|
198
|
+
return {
|
199
|
+
onCodePathStart() {
|
200
|
+
currentCodePathSegmentStack.push(currentCodePathSegment);
|
201
|
+
},
|
202
|
+
|
203
|
+
onCodePathEnd(codePath, node) {
|
204
|
+
currentCodePathSegment = currentCodePathSegmentStack.pop();
|
205
|
+
|
206
|
+
if (astUtils.isFunction(node) && (node.async || node.generator)) {
|
207
|
+
findOutdatedReads(codePath.initialSegment, node);
|
208
|
+
}
|
209
|
+
},
|
210
|
+
|
211
|
+
onCodePathSegmentStart(segment) {
|
212
|
+
currentCodePathSegment = segment;
|
213
|
+
expressionsByCodePathSegment.set(segment, []);
|
214
|
+
},
|
215
|
+
|
216
|
+
"AssignmentExpression, Identifier, MemberExpression, AwaitExpression, YieldExpression"(node) {
|
217
|
+
expressionsByCodePathSegment.get(currentCodePathSegment).push({ entering: true, node });
|
218
|
+
},
|
219
|
+
|
220
|
+
"AssignmentExpression, Identifier, MemberExpression, AwaitExpression, YieldExpression:exit"(node) {
|
221
|
+
expressionsByCodePathSegment.get(currentCodePathSegment).push({ entering: false, node });
|
222
|
+
},
|
223
|
+
|
224
|
+
":function"(node) {
|
225
|
+
functionStack.push(node);
|
226
|
+
},
|
227
|
+
|
228
|
+
":function:exit"() {
|
229
|
+
functionStack.pop();
|
230
|
+
},
|
231
|
+
|
232
|
+
Identifier(node) {
|
233
|
+
if (functionStack.length) {
|
234
|
+
identifierToSurroundingFunctionMap.set(node, functionStack[functionStack.length - 1]);
|
235
|
+
}
|
236
|
+
}
|
237
|
+
};
|
238
|
+
}
|
239
|
+
};
|
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("../ast-utils");
|
12
|
+
const astUtils = require("../util/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Helpers
|
@@ -0,0 +1,65 @@
|
|
1
|
+
/**
|
2
|
+
* @fileoverview Rule to enforce the use of `u` flag on RegExp.
|
3
|
+
* @author Toru Nagashima
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
//------------------------------------------------------------------------------
|
9
|
+
// Requirements
|
10
|
+
//------------------------------------------------------------------------------
|
11
|
+
|
12
|
+
const {
|
13
|
+
CALL,
|
14
|
+
CONSTRUCT,
|
15
|
+
ReferenceTracker,
|
16
|
+
getStringIfConstant
|
17
|
+
} = require("eslint-utils");
|
18
|
+
|
19
|
+
//------------------------------------------------------------------------------
|
20
|
+
// Rule Definition
|
21
|
+
//------------------------------------------------------------------------------
|
22
|
+
|
23
|
+
module.exports = {
|
24
|
+
meta: {
|
25
|
+
docs: {
|
26
|
+
description: "enforce the use of `u` flag on RegExp",
|
27
|
+
category: "Best Practices",
|
28
|
+
recommended: false,
|
29
|
+
url: "https://eslint.org/docs/rules/require-unicode-regexp"
|
30
|
+
},
|
31
|
+
messages: {
|
32
|
+
requireUFlag: "Use the 'u' flag."
|
33
|
+
},
|
34
|
+
schema: []
|
35
|
+
},
|
36
|
+
|
37
|
+
create(context) {
|
38
|
+
return {
|
39
|
+
"Literal[regex]"(node) {
|
40
|
+
const flags = node.regex.flags || "";
|
41
|
+
|
42
|
+
if (!flags.includes("u")) {
|
43
|
+
context.report({ node, messageId: "requireUFlag" });
|
44
|
+
}
|
45
|
+
},
|
46
|
+
|
47
|
+
Program() {
|
48
|
+
const scope = context.getScope();
|
49
|
+
const tracker = new ReferenceTracker(scope);
|
50
|
+
const trackMap = {
|
51
|
+
RegExp: { [CALL]: true, [CONSTRUCT]: true }
|
52
|
+
};
|
53
|
+
|
54
|
+
for (const { node } of tracker.iterateGlobalReferences(trackMap)) {
|
55
|
+
const flagsNode = node.arguments[1];
|
56
|
+
const flags = getStringIfConstant(flagsNode, scope);
|
57
|
+
|
58
|
+
if (!flagsNode || (typeof flags === "string" && !flags.includes("u"))) {
|
59
|
+
context.report({ node, messageId: "requireUFlag" });
|
60
|
+
}
|
61
|
+
}
|
62
|
+
}
|
63
|
+
};
|
64
|
+
}
|
65
|
+
};
|
package/lib/rules/semi-style.js
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("../ast-utils");
|
12
|
+
const astUtils = require("../util/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Rule Definition
|
package/lib/rules/semi.js
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
11
|
const FixTracker = require("../util/fix-tracker");
|
12
|
-
const astUtils = require("../ast-utils");
|
12
|
+
const astUtils = require("../util/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Rule Definition
|
package/lib/rules/sort-keys.js
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("../ast-utils"),
|
12
|
+
const astUtils = require("../util/ast-utils"),
|
13
13
|
naturalCompare = require("natural-compare");
|
14
14
|
|
15
15
|
//------------------------------------------------------------------------------
|
@@ -125,7 +125,7 @@ module.exports = {
|
|
125
125
|
},
|
126
126
|
|
127
127
|
Property(node) {
|
128
|
-
if (node.parent.type === "ObjectPattern") {
|
128
|
+
if (node.parent.type === "ObjectPattern" || node.parent.properties.some(n => n.type === "SpreadElement")) {
|
129
129
|
return;
|
130
130
|
}
|
131
131
|
|
@@ -8,7 +8,7 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const astUtils = require("../ast-utils");
|
11
|
+
const astUtils = require("../util/ast-utils");
|
12
12
|
|
13
13
|
//------------------------------------------------------------------------------
|
14
14
|
// Rule Definition
|
@@ -8,7 +8,7 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const astUtils = require("../ast-utils");
|
11
|
+
const astUtils = require("../util/ast-utils");
|
12
12
|
|
13
13
|
//------------------------------------------------------------------------------
|
14
14
|
// Rule Definition
|
package/lib/rules/strict.js
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("../ast-utils");
|
12
|
+
const astUtils = require("../util/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Helpers
|
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("../ast-utils");
|
12
|
+
const astUtils = require("../util/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Rule Definition
|
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("../ast-utils");
|
12
|
+
const astUtils = require("../util/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Rule Definition
|
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("../ast-utils");
|
12
|
+
const astUtils = require("../util/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Helpers
|
package/lib/rules/valid-jsdoc.js
CHANGED
@@ -408,7 +408,7 @@ module.exports = {
|
|
408
408
|
if (!isOverride && !hasReturns && !hasConstructor && !isInterface &&
|
409
409
|
node.parent.kind !== "get" && node.parent.kind !== "constructor" &&
|
410
410
|
node.parent.kind !== "set" && !isTypeClass(node)) {
|
411
|
-
if (requireReturn || functionData.returnPresent) {
|
411
|
+
if (requireReturn || (functionData.returnPresent && !node.async)) {
|
412
412
|
context.report({
|
413
413
|
node: jsdocNode,
|
414
414
|
message: "Missing JSDoc @{{returns}} for function.",
|
package/lib/rules/wrap-iife.js
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("../ast-utils");
|
12
|
+
const astUtils = require("../util/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Rule Definition
|
package/lib/rules/wrap-regex.js
CHANGED
@@ -20,7 +20,10 @@ module.exports = {
|
|
20
20
|
|
21
21
|
schema: [],
|
22
22
|
|
23
|
-
fixable: "code"
|
23
|
+
fixable: "code",
|
24
|
+
messages: {
|
25
|
+
requireParens: "Wrap the regexp literal in parens to disambiguate the slash."
|
26
|
+
}
|
24
27
|
},
|
25
28
|
|
26
29
|
create(context) {
|
@@ -33,15 +36,16 @@ module.exports = {
|
|
33
36
|
nodeType = token.type;
|
34
37
|
|
35
38
|
if (nodeType === "RegularExpression") {
|
36
|
-
const
|
39
|
+
const beforeToken = sourceCode.getTokenBefore(node);
|
40
|
+
const afterToken = sourceCode.getTokenAfter(node);
|
37
41
|
const ancestors = context.getAncestors();
|
38
42
|
const grandparent = ancestors[ancestors.length - 1];
|
39
43
|
|
40
44
|
if (grandparent.type === "MemberExpression" && grandparent.object === node &&
|
41
|
-
(
|
45
|
+
!(beforeToken && beforeToken.value === "(" && afterToken && afterToken.value === ")")) {
|
42
46
|
context.report({
|
43
47
|
node,
|
44
|
-
|
48
|
+
messageId: "requireParens",
|
45
49
|
fix: fixer => fixer.replaceText(node, `(${sourceCode.getText(node)})`)
|
46
50
|
});
|
47
51
|
}
|
package/lib/rules/yoda.js
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
// Requirements
|
9
9
|
//--------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const astUtils = require("../ast-utils");
|
11
|
+
const astUtils = require("../util/ast-utils");
|
12
12
|
|
13
13
|
//--------------------------------------------------------------------------
|
14
14
|
// Helpers
|
@@ -140,7 +140,7 @@ const IT = Symbol("it");
|
|
140
140
|
*/
|
141
141
|
function itDefaultHandler(text, method) {
|
142
142
|
try {
|
143
|
-
return method.
|
143
|
+
return method.call(this);
|
144
144
|
} catch (err) {
|
145
145
|
if (err instanceof assert.AssertionError) {
|
146
146
|
err.message += ` (${util.inspect(err.actual)} ${err.operator} ${util.inspect(err.expected)})`;
|
@@ -157,7 +157,7 @@ function itDefaultHandler(text, method) {
|
|
157
157
|
* @returns {any} Returned value of `method`.
|
158
158
|
*/
|
159
159
|
function describeDefaultHandler(text, method) {
|
160
|
-
return method.
|
160
|
+
return method.call(this);
|
161
161
|
}
|
162
162
|
|
163
163
|
class RuleTester {
|
@@ -396,9 +396,7 @@ class RuleTester {
|
|
396
396
|
* @private
|
397
397
|
*/
|
398
398
|
function assertASTDidntChange(beforeAST, afterAST) {
|
399
|
-
|
400
|
-
// Feature detect the Node.js implementation and use that if available.
|
401
|
-
if ((util.isDeepStrictEqual && !util.isDeepStrictEqual(beforeAST, afterAST)) || !lodash.isEqual(beforeAST, afterAST)) {
|
399
|
+
if (!lodash.isEqual(beforeAST, afterAST)) {
|
402
400
|
assert.fail(null, null, "Rule should not modify AST.");
|
403
401
|
}
|
404
402
|
}
|
package/lib/token-store/index.js
CHANGED
@@ -13,7 +13,7 @@ const cursors = require("./cursors");
|
|
13
13
|
const ForwardTokenCursor = require("./forward-token-cursor");
|
14
14
|
const PaddedTokenCursor = require("./padded-token-cursor");
|
15
15
|
const utils = require("./utils");
|
16
|
-
const astUtils = require("../ast-utils");
|
16
|
+
const astUtils = require("../util/ast-utils");
|
17
17
|
|
18
18
|
//------------------------------------------------------------------------------
|
19
19
|
// Helpers
|
File without changes
|
File without changes
|
package/lib/util/fix-tracker.js
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const astUtils = require("../ast-utils");
|
11
|
+
const astUtils = require("../util/ast-utils");
|
12
12
|
|
13
13
|
//------------------------------------------------------------------------------
|
14
14
|
// Public Interface
|
@@ -13,10 +13,10 @@ const lodash = require("lodash"),
|
|
13
13
|
path = require("path"),
|
14
14
|
GlobSync = require("./glob"),
|
15
15
|
|
16
|
-
|
16
|
+
pathUtils = require("./path-utils"),
|
17
17
|
IgnoredPaths = require("../ignored-paths");
|
18
18
|
|
19
|
-
const debug = require("debug")("eslint:glob-
|
19
|
+
const debug = require("debug")("eslint:glob-utils");
|
20
20
|
|
21
21
|
//------------------------------------------------------------------------------
|
22
22
|
// Helpers
|
@@ -77,7 +77,7 @@ function processPath(options) {
|
|
77
77
|
newPath = pathname.replace(/[/\\]$/, "") + suffix;
|
78
78
|
}
|
79
79
|
|
80
|
-
return
|
80
|
+
return pathUtils.convertPathToPosix(newPath);
|
81
81
|
};
|
82
82
|
}
|
83
83
|
|
@@ -194,7 +194,7 @@ function listFilesToProcess(globPatterns, providedOptions) {
|
|
194
194
|
);
|
195
195
|
|
196
196
|
/*
|
197
|
-
* The test "should use default options if none are provided" (source-code-
|
197
|
+
* The test "should use default options if none are provided" (source-code-utils.js) checks that 'module.exports.resolveFileGlobPatterns' was called.
|
198
198
|
* So it cannot use the local function "resolveFileGlobPatterns".
|
199
199
|
*/
|
200
200
|
const resolvedGlobPatterns = module.exports.resolveFileGlobPatterns(globPatterns, options);
|