eslint 7.0.0-alpha.3 → 7.2.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 +303 -0
- package/README.md +10 -11
- package/bin/eslint.js +115 -77
- package/conf/category-list.json +0 -1
- package/lib/api.js +2 -0
- package/lib/cli-engine/cascading-config-array-factory.js +12 -0
- package/lib/cli-engine/cli-engine.js +53 -48
- package/lib/cli-engine/config-array/config-array.js +1 -1
- package/lib/cli-engine/config-array/ignore-pattern.js +7 -1
- package/lib/cli-engine/config-array-factory.js +3 -3
- package/lib/cli.js +181 -95
- package/lib/eslint/eslint.js +656 -0
- package/lib/eslint/index.js +7 -0
- package/lib/init/autoconfig.js +4 -4
- package/lib/init/config-initializer.js +5 -10
- package/lib/init/source-code-utils.js +2 -2
- package/lib/linter/code-path-analysis/code-path-analyzer.js +2 -2
- package/lib/linter/code-path-analysis/code-path-state.js +34 -12
- package/lib/linter/config-comment-parser.js +1 -1
- package/lib/linter/linter.js +2 -1
- package/lib/options.js +0 -1
- package/lib/rule-tester/rule-tester.js +6 -1
- package/lib/rules/accessor-pairs.js +1 -1
- package/lib/rules/array-callback-return.js +3 -18
- package/lib/rules/arrow-parens.js +19 -3
- package/lib/rules/block-spacing.js +19 -2
- package/lib/rules/callback-return.js +4 -0
- package/lib/rules/comma-style.js +3 -8
- package/lib/rules/func-call-spacing.js +22 -6
- package/lib/rules/getter-return.js +2 -12
- package/lib/rules/global-require.js +4 -0
- package/lib/rules/handle-callback-err.js +4 -0
- package/lib/rules/index.js +1 -0
- package/lib/rules/key-spacing.js +1 -1
- package/lib/rules/keyword-spacing.js +9 -2
- package/lib/rules/linebreak-style.js +8 -2
- package/lib/rules/max-lines-per-function.js +1 -1
- package/lib/rules/multiline-ternary.js +44 -25
- package/lib/rules/new-cap.js +1 -1
- package/lib/rules/newline-per-chained-call.js +6 -3
- package/lib/rules/no-buffer-constructor.js +4 -0
- package/lib/rules/no-control-regex.js +1 -1
- package/lib/rules/no-empty-function.js +1 -1
- package/lib/rules/no-extra-boolean-cast.js +3 -0
- package/lib/rules/no-extra-parens.js +35 -3
- package/lib/rules/no-inner-declarations.js +31 -39
- package/lib/rules/no-invalid-regexp.js +1 -1
- package/lib/rules/no-lone-blocks.js +1 -1
- package/lib/rules/no-loss-of-precision.js +198 -0
- package/lib/rules/no-misleading-character-class.js +1 -1
- package/lib/rules/no-mixed-operators.js +3 -2
- package/lib/rules/no-mixed-requires.js +4 -0
- package/lib/rules/no-mixed-spaces-and-tabs.js +14 -6
- package/lib/rules/no-new-func.js +22 -19
- package/lib/rules/no-new-object.js +15 -3
- package/lib/rules/no-new-require.js +4 -0
- package/lib/rules/no-new-symbol.js +2 -1
- package/lib/rules/no-path-concat.js +4 -0
- package/lib/rules/no-process-env.js +4 -0
- package/lib/rules/no-process-exit.js +4 -0
- package/lib/rules/no-regex-spaces.js +1 -1
- package/lib/rules/no-restricted-exports.js +6 -0
- package/lib/rules/no-restricted-modules.js +4 -0
- package/lib/rules/no-sync.js +4 -0
- package/lib/rules/no-unexpected-multiline.js +22 -12
- package/lib/rules/no-unneeded-ternary.js +6 -4
- package/lib/rules/no-unused-expressions.js +1 -1
- package/lib/rules/no-unused-vars.js +3 -1
- package/lib/rules/no-useless-backreference.js +1 -1
- package/lib/rules/no-useless-concat.js +1 -1
- package/lib/rules/one-var-declaration-per-line.js +1 -1
- package/lib/rules/padded-blocks.js +17 -4
- package/lib/rules/prefer-named-capture-group.js +1 -1
- package/lib/rules/quote-props.js +2 -2
- package/lib/rules/rest-spread-spacing.js +3 -6
- package/lib/rules/semi-spacing.js +32 -8
- package/lib/rules/space-before-function-paren.js +5 -2
- package/lib/rules/template-tag-spacing.js +8 -2
- package/lib/rules/utils/ast-utils.js +106 -9
- package/lib/rules/yoda.js +101 -51
- package/lib/shared/relative-module-resolver.js +1 -0
- package/lib/shared/types.js +7 -0
- package/lib/source-code/source-code.js +1 -0
- package/messages/extend-config-missing.txt +1 -1
- package/messages/no-config-found.txt +1 -1
- package/messages/plugin-conflict.txt +1 -1
- package/messages/plugin-missing.txt +1 -1
- package/messages/whitespace-found.txt +1 -1
- package/package.json +27 -26
package/lib/rules/no-new-func.js
CHANGED
@@ -29,26 +29,29 @@ module.exports = {
|
|
29
29
|
|
30
30
|
create(context) {
|
31
31
|
|
32
|
-
//--------------------------------------------------------------------------
|
33
|
-
// Helpers
|
34
|
-
//--------------------------------------------------------------------------
|
35
|
-
|
36
|
-
/**
|
37
|
-
* Reports a node.
|
38
|
-
* @param {ASTNode} node The node to report
|
39
|
-
* @returns {void}
|
40
|
-
* @private
|
41
|
-
*/
|
42
|
-
function report(node) {
|
43
|
-
context.report({
|
44
|
-
node,
|
45
|
-
messageId: "noFunctionConstructor"
|
46
|
-
});
|
47
|
-
}
|
48
|
-
|
49
32
|
return {
|
50
|
-
"
|
51
|
-
|
33
|
+
"Program:exit"() {
|
34
|
+
const globalScope = context.getScope();
|
35
|
+
const variable = globalScope.set.get("Function");
|
36
|
+
|
37
|
+
if (variable && variable.defs.length === 0) {
|
38
|
+
variable.references.forEach(ref => {
|
39
|
+
const node = ref.identifier;
|
40
|
+
const { parent } = node;
|
41
|
+
|
42
|
+
if (
|
43
|
+
parent &&
|
44
|
+
(parent.type === "NewExpression" || parent.type === "CallExpression") &&
|
45
|
+
node === parent.callee
|
46
|
+
) {
|
47
|
+
context.report({
|
48
|
+
node: parent,
|
49
|
+
messageId: "noFunctionConstructor"
|
50
|
+
});
|
51
|
+
}
|
52
|
+
});
|
53
|
+
}
|
54
|
+
}
|
52
55
|
};
|
53
56
|
|
54
57
|
}
|
@@ -5,6 +5,12 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
//------------------------------------------------------------------------------
|
9
|
+
// Requirements
|
10
|
+
//------------------------------------------------------------------------------
|
11
|
+
|
12
|
+
const astUtils = require("./utils/ast-utils");
|
13
|
+
|
8
14
|
//------------------------------------------------------------------------------
|
9
15
|
// Rule Definition
|
10
16
|
//------------------------------------------------------------------------------
|
@@ -28,10 +34,17 @@ module.exports = {
|
|
28
34
|
},
|
29
35
|
|
30
36
|
create(context) {
|
31
|
-
|
32
37
|
return {
|
33
|
-
|
34
38
|
NewExpression(node) {
|
39
|
+
const variable = astUtils.getVariableByName(
|
40
|
+
context.getScope(),
|
41
|
+
node.callee.name
|
42
|
+
);
|
43
|
+
|
44
|
+
if (variable && variable.identifiers.length > 0) {
|
45
|
+
return;
|
46
|
+
}
|
47
|
+
|
35
48
|
if (node.callee.name === "Object") {
|
36
49
|
context.report({
|
37
50
|
node,
|
@@ -40,6 +53,5 @@ module.exports = {
|
|
40
53
|
}
|
41
54
|
}
|
42
55
|
};
|
43
|
-
|
44
56
|
}
|
45
57
|
};
|
@@ -37,8 +37,9 @@ module.exports = {
|
|
37
37
|
if (variable && variable.defs.length === 0) {
|
38
38
|
variable.references.forEach(ref => {
|
39
39
|
const node = ref.identifier;
|
40
|
+
const parent = node.parent;
|
40
41
|
|
41
|
-
if (
|
42
|
+
if (parent && parent.type === "NewExpression" && parent.callee === node) {
|
42
43
|
context.report({
|
43
44
|
node,
|
44
45
|
messageId: "noNewSymbol"
|
package/lib/rules/no-sync.js
CHANGED
@@ -53,7 +53,11 @@ module.exports = {
|
|
53
53
|
const nodeExpressionEnd = sourceCode.getTokenBefore(openParen);
|
54
54
|
|
55
55
|
if (openParen.loc.start.line !== nodeExpressionEnd.loc.end.line) {
|
56
|
-
context.report({
|
56
|
+
context.report({
|
57
|
+
node,
|
58
|
+
loc: openParen.loc,
|
59
|
+
messageId
|
60
|
+
});
|
57
61
|
}
|
58
62
|
}
|
59
63
|
|
@@ -71,18 +75,24 @@ module.exports = {
|
|
71
75
|
},
|
72
76
|
|
73
77
|
TaggedTemplateExpression(node) {
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
78
|
+
const { quasi } = node;
|
79
|
+
|
80
|
+
// handles common tags, parenthesized tags, and typescript's generic type arguments
|
81
|
+
const tokenBefore = sourceCode.getTokenBefore(quasi);
|
82
|
+
|
83
|
+
if (tokenBefore.loc.end.line !== quasi.loc.start.line) {
|
84
|
+
context.report({
|
85
|
+
node,
|
86
|
+
loc: {
|
87
|
+
start: quasi.loc.start,
|
88
|
+
end: {
|
89
|
+
line: quasi.loc.start.line,
|
90
|
+
column: quasi.loc.start.column + 1
|
91
|
+
}
|
92
|
+
},
|
93
|
+
messageId: "taggedTemplate"
|
94
|
+
});
|
83
95
|
}
|
84
|
-
|
85
|
-
context.report({ node, loc: node.loc.start, messageId: "taggedTemplate" });
|
86
96
|
},
|
87
97
|
|
88
98
|
CallExpression(node) {
|
@@ -147,10 +147,12 @@ module.exports = {
|
|
147
147
|
loc: node.consequent.loc.start,
|
148
148
|
messageId: "unnecessaryConditionalAssignment",
|
149
149
|
fix: fixer => {
|
150
|
-
const shouldParenthesizeAlternate =
|
151
|
-
|
152
|
-
|
153
|
-
|
150
|
+
const shouldParenthesizeAlternate =
|
151
|
+
(
|
152
|
+
astUtils.getPrecedence(node.alternate) < OR_PRECEDENCE ||
|
153
|
+
astUtils.isCoalesceExpression(node.alternate)
|
154
|
+
) &&
|
155
|
+
!astUtils.isParenthesised(sourceCode, node.alternate);
|
154
156
|
const alternateText = shouldParenthesizeAlternate
|
155
157
|
? `(${sourceCode.getText(node.alternate)})`
|
156
158
|
: astUtils.getParenthesisedText(sourceCode, node.alternate);
|
@@ -124,7 +124,7 @@ module.exports = {
|
|
124
124
|
return true;
|
125
125
|
}
|
126
126
|
|
127
|
-
return /^(?:Assignment|Call|New|Update|Yield|Await)Expression$/u.test(node.type) ||
|
127
|
+
return /^(?:Assignment|Call|New|Update|Yield|Await|Import)Expression$/u.test(node.type) ||
|
128
128
|
(node.type === "UnaryExpression" && ["delete", "void"].indexOf(node.operator) >= 0);
|
129
129
|
}
|
130
130
|
|
@@ -619,7 +619,9 @@ module.exports = {
|
|
619
619
|
// Report the first declaration.
|
620
620
|
if (unusedVar.defs.length > 0) {
|
621
621
|
context.report({
|
622
|
-
node: unusedVar.
|
622
|
+
node: unusedVar.references.length ? unusedVar.references[
|
623
|
+
unusedVar.references.length - 1
|
624
|
+
].identifier : unusedVar.identifiers[0],
|
623
625
|
messageId: "unusedVar",
|
624
626
|
data: unusedVar.references.some(ref => ref.isWrite())
|
625
627
|
? getAssignedMessageData(unusedVar)
|
@@ -203,10 +203,14 @@ module.exports = {
|
|
203
203
|
}
|
204
204
|
|
205
205
|
if (requirePaddingFor(node)) {
|
206
|
+
|
206
207
|
if (!blockHasTopPadding) {
|
207
208
|
context.report({
|
208
209
|
node,
|
209
|
-
loc: {
|
210
|
+
loc: {
|
211
|
+
start: tokenBeforeFirst.loc.start,
|
212
|
+
end: firstBlockToken.loc.start
|
213
|
+
},
|
210
214
|
fix(fixer) {
|
211
215
|
return fixer.insertTextAfter(tokenBeforeFirst, "\n");
|
212
216
|
},
|
@@ -216,7 +220,10 @@ module.exports = {
|
|
216
220
|
if (!blockHasBottomPadding) {
|
217
221
|
context.report({
|
218
222
|
node,
|
219
|
-
loc: {
|
223
|
+
loc: {
|
224
|
+
end: tokenAfterLast.loc.start,
|
225
|
+
start: lastBlockToken.loc.end
|
226
|
+
},
|
220
227
|
fix(fixer) {
|
221
228
|
return fixer.insertTextBefore(tokenAfterLast, "\n");
|
222
229
|
},
|
@@ -228,7 +235,10 @@ module.exports = {
|
|
228
235
|
|
229
236
|
context.report({
|
230
237
|
node,
|
231
|
-
loc: {
|
238
|
+
loc: {
|
239
|
+
start: tokenBeforeFirst.loc.start,
|
240
|
+
end: firstBlockToken.loc.start
|
241
|
+
},
|
232
242
|
fix(fixer) {
|
233
243
|
return fixer.replaceTextRange([tokenBeforeFirst.range[1], firstBlockToken.range[0] - firstBlockToken.loc.start.column], "\n");
|
234
244
|
},
|
@@ -240,7 +250,10 @@ module.exports = {
|
|
240
250
|
|
241
251
|
context.report({
|
242
252
|
node,
|
243
|
-
loc: {
|
253
|
+
loc: {
|
254
|
+
end: tokenAfterLast.loc.start,
|
255
|
+
start: lastBlockToken.loc.end
|
256
|
+
},
|
244
257
|
messageId: "neverPadBlock",
|
245
258
|
fix(fixer) {
|
246
259
|
return fixer.replaceTextRange([lastBlockToken.range[1], tokenAfterLast.range[0] - tokenAfterLast.loc.start.column], "\n");
|
package/lib/rules/quote-props.js
CHANGED
@@ -154,7 +154,7 @@ module.exports = {
|
|
154
154
|
|
155
155
|
try {
|
156
156
|
tokens = espree.tokenize(key.value);
|
157
|
-
} catch
|
157
|
+
} catch {
|
158
158
|
return;
|
159
159
|
}
|
160
160
|
|
@@ -239,7 +239,7 @@ module.exports = {
|
|
239
239
|
|
240
240
|
try {
|
241
241
|
tokens = espree.tokenize(key.value);
|
242
|
-
} catch
|
242
|
+
} catch {
|
243
243
|
necessaryQuotes = true;
|
244
244
|
return;
|
245
245
|
}
|
@@ -79,10 +79,7 @@ module.exports = {
|
|
79
79
|
if (alwaysSpace && !hasWhitespace) {
|
80
80
|
context.report({
|
81
81
|
node,
|
82
|
-
loc:
|
83
|
-
line: operator.loc.end.line,
|
84
|
-
column: operator.loc.end.column
|
85
|
-
},
|
82
|
+
loc: operator.loc,
|
86
83
|
messageId: "expectedWhitespace",
|
87
84
|
data: {
|
88
85
|
type
|
@@ -95,8 +92,8 @@ module.exports = {
|
|
95
92
|
context.report({
|
96
93
|
node,
|
97
94
|
loc: {
|
98
|
-
|
99
|
-
|
95
|
+
start: operator.loc.end,
|
96
|
+
end: nextToken.loc.start
|
100
97
|
},
|
101
98
|
messageId: "unexpectedWhitespace",
|
102
99
|
data: {
|
@@ -117,6 +117,18 @@ module.exports = {
|
|
117
117
|
}
|
118
118
|
|
119
119
|
/**
|
120
|
+
* Report location example :
|
121
|
+
*
|
122
|
+
* for unexpected space `before`
|
123
|
+
*
|
124
|
+
* var a = 'b' ;
|
125
|
+
* ^^^
|
126
|
+
*
|
127
|
+
* for unexpected space `after`
|
128
|
+
*
|
129
|
+
* var a = 'b'; c = 10;
|
130
|
+
* ^^
|
131
|
+
*
|
120
132
|
* Reports if the given token has invalid spacing.
|
121
133
|
* @param {Token} token The semicolon token to check.
|
122
134
|
* @param {ASTNode} node The corresponding node of the token.
|
@@ -124,16 +136,19 @@ module.exports = {
|
|
124
136
|
*/
|
125
137
|
function checkSemicolonSpacing(token, node) {
|
126
138
|
if (astUtils.isSemicolonToken(token)) {
|
127
|
-
const location = token.loc.start;
|
128
|
-
|
129
139
|
if (hasLeadingSpace(token)) {
|
130
140
|
if (!requireSpaceBefore) {
|
141
|
+
const tokenBefore = sourceCode.getTokenBefore(token);
|
142
|
+
const loc = {
|
143
|
+
start: tokenBefore.loc.end,
|
144
|
+
end: token.loc.start
|
145
|
+
};
|
146
|
+
|
131
147
|
context.report({
|
132
148
|
node,
|
133
|
-
loc
|
149
|
+
loc,
|
134
150
|
messageId: "unexpectedWhitespaceBefore",
|
135
151
|
fix(fixer) {
|
136
|
-
const tokenBefore = sourceCode.getTokenBefore(token);
|
137
152
|
|
138
153
|
return fixer.removeRange([tokenBefore.range[1], token.range[0]]);
|
139
154
|
}
|
@@ -141,9 +156,11 @@ module.exports = {
|
|
141
156
|
}
|
142
157
|
} else {
|
143
158
|
if (requireSpaceBefore) {
|
159
|
+
const loc = token.loc;
|
160
|
+
|
144
161
|
context.report({
|
145
162
|
node,
|
146
|
-
loc
|
163
|
+
loc,
|
147
164
|
messageId: "missingWhitespaceBefore",
|
148
165
|
fix(fixer) {
|
149
166
|
return fixer.insertTextBefore(token, " ");
|
@@ -155,12 +172,17 @@ module.exports = {
|
|
155
172
|
if (!isFirstTokenInCurrentLine(token) && !isLastTokenInCurrentLine(token) && !isBeforeClosingParen(token)) {
|
156
173
|
if (hasTrailingSpace(token)) {
|
157
174
|
if (!requireSpaceAfter) {
|
175
|
+
const tokenAfter = sourceCode.getTokenAfter(token);
|
176
|
+
const loc = {
|
177
|
+
start: token.loc.end,
|
178
|
+
end: tokenAfter.loc.start
|
179
|
+
};
|
180
|
+
|
158
181
|
context.report({
|
159
182
|
node,
|
160
|
-
loc
|
183
|
+
loc,
|
161
184
|
messageId: "unexpectedWhitespaceAfter",
|
162
185
|
fix(fixer) {
|
163
|
-
const tokenAfter = sourceCode.getTokenAfter(token);
|
164
186
|
|
165
187
|
return fixer.removeRange([token.range[1], tokenAfter.range[0]]);
|
166
188
|
}
|
@@ -168,9 +190,11 @@ module.exports = {
|
|
168
190
|
}
|
169
191
|
} else {
|
170
192
|
if (requireSpaceAfter) {
|
193
|
+
const loc = token.loc;
|
194
|
+
|
171
195
|
context.report({
|
172
196
|
node,
|
173
|
-
loc
|
197
|
+
loc,
|
174
198
|
messageId: "missingWhitespaceAfter",
|
175
199
|
fix(fixer) {
|
176
200
|
return fixer.insertTextAfter(token, " ");
|
@@ -127,7 +127,10 @@ module.exports = {
|
|
127
127
|
if (hasSpacing && functionConfig === "never") {
|
128
128
|
context.report({
|
129
129
|
node,
|
130
|
-
loc:
|
130
|
+
loc: {
|
131
|
+
start: leftToken.loc.end,
|
132
|
+
end: rightToken.loc.start
|
133
|
+
},
|
131
134
|
messageId: "unexpectedSpace",
|
132
135
|
fix(fixer) {
|
133
136
|
const comments = sourceCode.getCommentsBefore(rightToken);
|
@@ -145,7 +148,7 @@ module.exports = {
|
|
145
148
|
} else if (!hasSpacing && functionConfig === "always") {
|
146
149
|
context.report({
|
147
150
|
node,
|
148
|
-
loc:
|
151
|
+
loc: rightToken.loc,
|
149
152
|
messageId: "missingSpace",
|
150
153
|
fix: fixer => fixer.insertTextAfter(leftToken, " ")
|
151
154
|
});
|
@@ -49,7 +49,10 @@ module.exports = {
|
|
49
49
|
if (never && hasWhitespace) {
|
50
50
|
context.report({
|
51
51
|
node,
|
52
|
-
loc:
|
52
|
+
loc: {
|
53
|
+
start: tagToken.loc.end,
|
54
|
+
end: literalToken.loc.start
|
55
|
+
},
|
53
56
|
messageId: "unexpected",
|
54
57
|
fix(fixer) {
|
55
58
|
const comments = sourceCode.getCommentsBefore(node.quasi);
|
@@ -68,7 +71,10 @@ module.exports = {
|
|
68
71
|
} else if (!never && !hasWhitespace) {
|
69
72
|
context.report({
|
70
73
|
node,
|
71
|
-
loc:
|
74
|
+
loc: {
|
75
|
+
start: node.loc.start,
|
76
|
+
end: literalToken.loc.start
|
77
|
+
},
|
72
78
|
messageId: "missing",
|
73
79
|
fix(fixer) {
|
74
80
|
return fixer.insertTextAfter(tagToken, " ");
|