eslint 6.0.1 → 6.2.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 +77 -0
- package/README.md +8 -5
- package/bin/eslint.js +3 -0
- package/conf/config-schema.js +1 -0
- package/conf/environments.js +72 -15
- package/lib/cli-engine/cli-engine.js +5 -2
- package/lib/cli-engine/config-array/config-array.js +7 -0
- package/lib/cli-engine/config-array/extracted-config.js +16 -1
- package/lib/cli-engine/config-array-factory.js +3 -1
- package/lib/cli-engine/file-enumerator.js +5 -13
- package/lib/init/config-initializer.js +19 -9
- package/lib/init/npm-utils.js +2 -2
- package/lib/linter/code-path-analysis/code-path-analyzer.js +1 -0
- package/lib/linter/linter.js +49 -16
- package/lib/rule-tester/rule-tester.js +1 -1
- package/lib/rules/accessor-pairs.js +195 -35
- package/lib/rules/arrow-body-style.js +2 -2
- package/lib/rules/class-methods-use-this.js +10 -3
- package/lib/rules/dot-location.js +21 -17
- package/lib/rules/dot-notation.js +6 -2
- package/lib/rules/func-call-spacing.js +30 -20
- package/lib/rules/func-names.js +4 -0
- package/lib/rules/function-call-argument-newline.js +120 -0
- package/lib/rules/function-paren-newline.js +34 -22
- package/lib/rules/indent.js +13 -2
- package/lib/rules/index.js +1 -0
- package/lib/rules/new-cap.js +2 -1
- package/lib/rules/no-dupe-keys.js +1 -1
- package/lib/rules/no-duplicate-case.js +10 -8
- package/lib/rules/no-extra-bind.js +1 -0
- package/lib/rules/no-extra-boolean-cast.js +44 -5
- package/lib/rules/no-extra-parens.js +295 -39
- package/lib/rules/no-mixed-operators.js +48 -13
- package/lib/rules/no-param-reassign.js +12 -1
- package/lib/rules/no-restricted-syntax.js +2 -2
- package/lib/rules/no-unused-vars.js +1 -1
- package/lib/rules/prefer-const.js +9 -3
- package/lib/rules/prefer-template.js +1 -10
- package/lib/rules/sort-keys.js +11 -3
- package/lib/rules/utils/ast-utils.js +45 -3
- package/lib/rules/yoda.js +1 -1
- package/lib/{cli-engine → shared}/naming.js +0 -0
- package/lib/shared/types.js +2 -0
- package/package.json +22 -21
@@ -232,25 +232,15 @@ module.exports = {
|
|
232
232
|
};
|
233
233
|
}
|
234
234
|
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
}
|
239
|
-
|
240
|
-
/**
|
241
|
-
* Validates the parentheses for a node
|
242
|
-
* @param {ASTNode} node The node with parens
|
243
|
-
* @returns {void}
|
244
|
-
*/
|
245
|
-
function validateNode(node) {
|
246
|
-
const parens = getParenTokens(node);
|
247
|
-
|
248
|
-
if (parens) {
|
249
|
-
validateParens(parens, astUtils.isFunction(node) ? node.params : node.arguments);
|
235
|
+
case "ImportExpression": {
|
236
|
+
const leftParen = sourceCode.getFirstToken(node, 1);
|
237
|
+
const rightParen = sourceCode.getLastToken(node);
|
250
238
|
|
251
|
-
|
252
|
-
validateArguments(parens, astUtils.isFunction(node) ? node.params : node.arguments);
|
239
|
+
return { leftParen, rightParen };
|
253
240
|
}
|
241
|
+
|
242
|
+
default:
|
243
|
+
throw new TypeError(`unexpected node with type ${node.type}`);
|
254
244
|
}
|
255
245
|
}
|
256
246
|
|
@@ -259,11 +249,33 @@ module.exports = {
|
|
259
249
|
//----------------------------------------------------------------------
|
260
250
|
|
261
251
|
return {
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
252
|
+
[[
|
253
|
+
"ArrowFunctionExpression",
|
254
|
+
"CallExpression",
|
255
|
+
"FunctionDeclaration",
|
256
|
+
"FunctionExpression",
|
257
|
+
"ImportExpression",
|
258
|
+
"NewExpression"
|
259
|
+
]](node) {
|
260
|
+
const parens = getParenTokens(node);
|
261
|
+
let params;
|
262
|
+
|
263
|
+
if (node.type === "ImportExpression") {
|
264
|
+
params = [node.source];
|
265
|
+
} else if (astUtils.isFunction(node)) {
|
266
|
+
params = node.params;
|
267
|
+
} else {
|
268
|
+
params = node.arguments;
|
269
|
+
}
|
270
|
+
|
271
|
+
if (parens) {
|
272
|
+
validateParens(parens, params);
|
273
|
+
|
274
|
+
if (multilineArgumentsOption) {
|
275
|
+
validateArguments(parens, params);
|
276
|
+
}
|
277
|
+
}
|
278
|
+
}
|
267
279
|
};
|
268
280
|
}
|
269
281
|
};
|
package/lib/rules/indent.js
CHANGED
@@ -99,7 +99,8 @@ const KNOWN_NODES = new Set([
|
|
99
99
|
"ImportDeclaration",
|
100
100
|
"ImportSpecifier",
|
101
101
|
"ImportDefaultSpecifier",
|
102
|
-
"ImportNamespaceSpecifier"
|
102
|
+
"ImportNamespaceSpecifier",
|
103
|
+
"ImportExpression"
|
103
104
|
]);
|
104
105
|
|
105
106
|
/*
|
@@ -1109,7 +1110,6 @@ module.exports = {
|
|
1109
1110
|
|
1110
1111
|
CallExpression: addFunctionCallIndent,
|
1111
1112
|
|
1112
|
-
|
1113
1113
|
"ClassDeclaration[superClass], ClassExpression[superClass]"(node) {
|
1114
1114
|
const classToken = sourceCode.getFirstToken(node);
|
1115
1115
|
const extendsToken = sourceCode.getTokenBefore(node.superClass, astUtils.isNotOpeningParenToken);
|
@@ -1236,6 +1236,17 @@ module.exports = {
|
|
1236
1236
|
}
|
1237
1237
|
},
|
1238
1238
|
|
1239
|
+
ImportExpression(node) {
|
1240
|
+
const openingParen = sourceCode.getFirstToken(node, 1);
|
1241
|
+
const closingParen = sourceCode.getLastToken(node);
|
1242
|
+
|
1243
|
+
parameterParens.add(openingParen);
|
1244
|
+
parameterParens.add(closingParen);
|
1245
|
+
offsets.setDesiredOffset(openingParen, sourceCode.getTokenBefore(openingParen), 0);
|
1246
|
+
|
1247
|
+
addElementListIndent([node.source], openingParen, closingParen, options.CallExpression.arguments);
|
1248
|
+
},
|
1249
|
+
|
1239
1250
|
"MemberExpression, JSXMemberExpression, MetaProperty"(node) {
|
1240
1251
|
const object = node.type === "MetaProperty" ? node.meta : node.object;
|
1241
1252
|
const firstNonObjectToken = sourceCode.getFirstTokenBetween(object, node.property, astUtils.isNotClosingParenToken);
|
package/lib/rules/index.js
CHANGED
@@ -46,6 +46,7 @@ module.exports = new LazyLoadingRuleMap(Object.entries({
|
|
46
46
|
"func-name-matching": () => require("./func-name-matching"),
|
47
47
|
"func-names": () => require("./func-names"),
|
48
48
|
"func-style": () => require("./func-style"),
|
49
|
+
"function-call-argument-newline": () => require("./function-call-argument-newline"),
|
49
50
|
"function-paren-newline": () => require("./function-paren-newline"),
|
50
51
|
"generator-star-spacing": () => require("./generator-star-spacing"),
|
51
52
|
"getter-return": () => require("./getter-return"),
|
package/lib/rules/new-cap.js
CHANGED
@@ -33,17 +33,19 @@ module.exports = {
|
|
33
33
|
|
34
34
|
return {
|
35
35
|
SwitchStatement(node) {
|
36
|
-
const
|
36
|
+
const previousKeys = new Set();
|
37
37
|
|
38
|
-
node.cases
|
39
|
-
|
38
|
+
for (const switchCase of node.cases) {
|
39
|
+
if (switchCase.test) {
|
40
|
+
const key = sourceCode.getText(switchCase.test);
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
if (previousKeys.has(key)) {
|
43
|
+
context.report({ node: switchCase, messageId: "unexpected" });
|
44
|
+
} else {
|
45
|
+
previousKeys.add(key);
|
46
|
+
}
|
45
47
|
}
|
46
|
-
}
|
48
|
+
}
|
47
49
|
}
|
48
50
|
};
|
49
51
|
}
|
@@ -98,6 +98,7 @@ module.exports = {
|
|
98
98
|
grandparent.type === "CallExpression" &&
|
99
99
|
grandparent.callee === parent &&
|
100
100
|
grandparent.arguments.length === 1 &&
|
101
|
+
grandparent.arguments[0].type !== "SpreadElement" &&
|
101
102
|
parent.type === "MemberExpression" &&
|
102
103
|
parent.object === node &&
|
103
104
|
astUtils.getStaticPropertyName(parent) === "bind"
|
@@ -50,8 +50,8 @@ module.exports = {
|
|
50
50
|
/**
|
51
51
|
* Check if a node is in a context where its value would be coerced to a boolean at runtime.
|
52
52
|
*
|
53
|
-
* @param {
|
54
|
-
* @param {
|
53
|
+
* @param {ASTNode} node The node
|
54
|
+
* @param {ASTNode} parent Its parent
|
55
55
|
* @returns {boolean} If it is in a boolean context
|
56
56
|
*/
|
57
57
|
function isInBooleanContext(node, parent) {
|
@@ -65,6 +65,15 @@ module.exports = {
|
|
65
65
|
);
|
66
66
|
}
|
67
67
|
|
68
|
+
/**
|
69
|
+
* Check if a node has comments inside.
|
70
|
+
*
|
71
|
+
* @param {ASTNode} node The node to check.
|
72
|
+
* @returns {boolean} `true` if it has comments inside.
|
73
|
+
*/
|
74
|
+
function hasCommentsInside(node) {
|
75
|
+
return Boolean(sourceCode.getCommentsInside(node).length);
|
76
|
+
}
|
68
77
|
|
69
78
|
return {
|
70
79
|
UnaryExpression(node) {
|
@@ -89,7 +98,12 @@ module.exports = {
|
|
89
98
|
context.report({
|
90
99
|
node,
|
91
100
|
messageId: "unexpectedNegation",
|
92
|
-
fix: fixer =>
|
101
|
+
fix: fixer => {
|
102
|
+
if (hasCommentsInside(parent)) {
|
103
|
+
return null;
|
104
|
+
}
|
105
|
+
return fixer.replaceText(parent, sourceCode.getText(node.argument));
|
106
|
+
}
|
93
107
|
});
|
94
108
|
}
|
95
109
|
},
|
@@ -106,10 +120,35 @@ module.exports = {
|
|
106
120
|
messageId: "unexpectedCall",
|
107
121
|
fix: fixer => {
|
108
122
|
if (!node.arguments.length) {
|
109
|
-
|
123
|
+
if (parent.type === "UnaryExpression" && parent.operator === "!") {
|
124
|
+
|
125
|
+
// !Boolean() -> true
|
126
|
+
|
127
|
+
if (hasCommentsInside(parent)) {
|
128
|
+
return null;
|
129
|
+
}
|
130
|
+
|
131
|
+
const replacement = "true";
|
132
|
+
let prefix = "";
|
133
|
+
const tokenBefore = sourceCode.getTokenBefore(parent);
|
134
|
+
|
135
|
+
if (tokenBefore && tokenBefore.range[1] === parent.range[0] &&
|
136
|
+
!astUtils.canTokensBeAdjacent(tokenBefore, replacement)) {
|
137
|
+
prefix = " ";
|
138
|
+
}
|
139
|
+
|
140
|
+
return fixer.replaceText(parent, prefix + replacement);
|
141
|
+
}
|
142
|
+
|
143
|
+
// Boolean() -> false
|
144
|
+
if (hasCommentsInside(node)) {
|
145
|
+
return null;
|
146
|
+
}
|
147
|
+
return fixer.replaceText(node, "false");
|
110
148
|
}
|
111
149
|
|
112
|
-
if (node.arguments.length > 1 || node.arguments[0].type === "SpreadElement"
|
150
|
+
if (node.arguments.length > 1 || node.arguments[0].type === "SpreadElement" ||
|
151
|
+
hasCommentsInside(node)) {
|
113
152
|
return null;
|
114
153
|
}
|
115
154
|
|