eslint 5.12.0 → 5.14.1
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 +70 -0
- package/README.md +76 -143
- package/conf/eslint-all.js +3 -5
- package/conf/eslint-recommended.js +4 -268
- package/lib/built-in-rules-index.js +277 -0
- package/lib/cli-engine.js +6 -2
- package/lib/config/config-file.js +25 -2
- package/lib/config/config-initializer.js +150 -143
- package/lib/config/config-ops.js +30 -0
- package/lib/config/config-rule.js +2 -4
- package/lib/config/plugins.js +12 -4
- package/lib/config.js +1 -1
- package/lib/formatters/table.js +13 -4
- package/lib/formatters/tap.js +7 -4
- package/lib/linter.js +31 -31
- package/lib/load-rules.js +2 -5
- package/lib/rules/accessor-pairs.js +4 -2
- package/lib/rules/array-bracket-newline.js +4 -2
- package/lib/rules/array-callback-return.js +2 -1
- package/lib/rules/array-element-newline.js +4 -2
- package/lib/rules/arrow-body-style.js +1 -1
- package/lib/rules/arrow-parens.js +2 -1
- package/lib/rules/arrow-spacing.js +7 -6
- package/lib/rules/brace-style.js +2 -1
- package/lib/rules/camelcase.js +3 -2
- package/lib/rules/capitalized-comments.js +15 -14
- package/lib/rules/class-methods-use-this.js +1 -1
- package/lib/rules/comma-spacing.js +10 -4
- package/lib/rules/complexity.js +7 -9
- package/lib/rules/consistent-return.js +2 -1
- package/lib/rules/dot-notation.js +5 -3
- package/lib/rules/eqeqeq.js +2 -1
- package/lib/rules/for-direction.js +30 -17
- package/lib/rules/func-call-spacing.js +2 -1
- package/lib/rules/func-style.js +3 -2
- package/lib/rules/getter-return.js +2 -1
- package/lib/rules/global-require.js +5 -2
- package/lib/rules/guard-for-in.js +5 -2
- package/lib/rules/handle-callback-err.js +5 -2
- package/lib/rules/id-blacklist.js +4 -1
- package/lib/rules/id-length.js +9 -6
- package/lib/rules/id-match.js +11 -5
- package/lib/rules/implicit-arrow-linebreak.js +7 -3
- package/lib/rules/indent-legacy.js +11 -5
- package/lib/rules/indent.js +18 -9
- package/lib/rules/init-declarations.js +13 -13
- package/lib/rules/jsx-quotes.js +5 -2
- package/lib/rules/key-spacing.js +70 -35
- package/lib/rules/keyword-spacing.js +18 -12
- package/lib/rules/line-comment-position.js +15 -8
- package/lib/rules/linebreak-style.js +6 -6
- package/lib/rules/lines-around-comment.js +20 -16
- package/lib/rules/lines-around-directive.js +5 -2
- package/lib/rules/lines-between-class-members.js +8 -6
- package/lib/rules/max-depth.js +11 -9
- package/lib/rules/max-len.js +24 -13
- package/lib/rules/max-lines-per-function.js +17 -18
- package/lib/rules/max-lines.js +14 -10
- package/lib/rules/max-nested-callbacks.js +12 -11
- package/lib/rules/max-params.js +11 -9
- package/lib/rules/max-statements-per-line.js +8 -5
- package/lib/rules/max-statements.js +12 -11
- package/lib/rules/multiline-comment-style.js +18 -17
- package/lib/rules/multiline-ternary.js +8 -6
- package/lib/rules/new-cap.js +18 -11
- package/lib/rules/new-parens.js +5 -2
- package/lib/rules/newline-after-var.js +6 -8
- package/lib/rules/newline-before-return.js +5 -1
- package/lib/rules/newline-per-chained-call.js +7 -3
- package/lib/rules/no-async-promise-executor.js +5 -2
- package/lib/rules/no-bitwise.js +2 -1
- package/lib/rules/no-confusing-arrow.js +1 -1
- package/lib/rules/no-constant-condition.js +24 -2
- package/lib/rules/no-duplicate-imports.js +17 -11
- package/lib/rules/no-else-return.js +2 -1
- package/lib/rules/no-empty.js +2 -1
- package/lib/rules/no-eval.js +1 -1
- package/lib/rules/no-extra-parens.js +4 -4
- package/lib/rules/no-fallthrough.js +8 -4
- package/lib/rules/no-floating-decimal.js +7 -3
- package/lib/rules/no-implicit-coercion.js +9 -6
- package/lib/rules/no-irregular-whitespace.js +8 -4
- package/lib/rules/no-labels.js +6 -4
- package/lib/rules/no-magic-numbers.js +6 -3
- package/lib/rules/no-mixed-operators.js +5 -4
- package/lib/rules/no-mixed-requires.js +4 -2
- package/lib/rules/no-multi-spaces.js +2 -1
- package/lib/rules/no-param-reassign.js +1 -1
- package/lib/rules/no-plusplus.js +2 -1
- package/lib/rules/no-redeclare.js +2 -2
- package/lib/rules/no-self-assign.js +2 -1
- package/lib/rules/no-shadow-restricted-names.js +16 -2
- package/lib/rules/no-shadow.js +3 -3
- package/lib/rules/no-sync.js +2 -1
- package/lib/rules/no-tabs.js +2 -1
- package/lib/rules/no-trailing-spaces.js +5 -3
- package/lib/rules/no-undef.js +7 -3
- package/lib/rules/no-underscore-dangle.js +6 -3
- package/lib/rules/no-unexpected-multiline.js +14 -13
- package/lib/rules/no-unneeded-ternary.js +2 -1
- package/lib/rules/no-unsafe-negation.js +6 -3
- package/lib/rules/no-unused-expressions.js +6 -3
- package/lib/rules/no-unused-labels.js +7 -2
- package/lib/rules/no-unused-vars.js +8 -4
- package/lib/rules/no-use-before-define.js +3 -3
- package/lib/rules/no-useless-rename.js +3 -3
- package/lib/rules/object-curly-newline.js +6 -4
- package/lib/rules/object-property-newline.js +5 -3
- package/lib/rules/object-shorthand.js +9 -5
- package/lib/rules/one-var.js +24 -38
- package/lib/rules/operator-assignment.js +8 -4
- package/lib/rules/padded-blocks.js +32 -9
- package/lib/rules/prefer-arrow-callback.js +4 -2
- package/lib/rules/prefer-const.js +7 -4
- package/lib/rules/prefer-destructuring.js +70 -12
- package/lib/rules/prefer-promise-reject-errors.js +1 -1
- package/lib/rules/prefer-spread.js +2 -13
- package/lib/rules/quote-props.js +10 -5
- package/lib/rules/quotes.js +4 -2
- package/lib/rules/require-jsdoc.js +13 -7
- package/lib/rules/semi-spacing.js +6 -8
- package/lib/rules/semi.js +5 -4
- package/lib/rules/sort-imports.js +6 -3
- package/lib/rules/sort-keys.js +13 -5
- package/lib/rules/sort-vars.js +2 -1
- package/lib/rules/space-before-function-paren.js +6 -3
- package/lib/rules/space-infix-ops.js +2 -1
- package/lib/rules/space-unary-ops.js +20 -10
- package/lib/rules/spaced-comment.js +2 -1
- package/lib/rules/strict.js +34 -35
- package/lib/rules/switch-colon-spacing.js +11 -8
- package/lib/rules/symbol-description.js +6 -3
- package/lib/rules/template-curly-spacing.js +10 -10
- package/lib/rules/template-tag-spacing.js +7 -3
- package/lib/rules/unicode-bom.js +7 -3
- package/lib/rules/use-isnan.js +5 -2
- package/lib/rules/valid-jsdoc.js +40 -19
- package/lib/rules/valid-typeof.js +9 -4
- package/lib/rules/vars-on-top.js +6 -4
- package/lib/rules/wrap-iife.js +12 -6
- package/lib/rules/yield-star-spacing.js +17 -10
- package/lib/rules/yoda.js +9 -4
- package/lib/rules.js +4 -34
- package/lib/util/ajv.js +1 -0
- package/lib/util/config-comment-parser.js +7 -10
- package/package.json +20 -20
@@ -40,11 +40,13 @@ module.exports = {
|
|
40
40
|
properties: {
|
41
41
|
maximum: {
|
42
42
|
type: "integer",
|
43
|
-
minimum: 0
|
43
|
+
minimum: 0,
|
44
|
+
default: 10
|
44
45
|
},
|
45
46
|
max: {
|
46
47
|
type: "integer",
|
47
|
-
minimum: 0
|
48
|
+
minimum: 0,
|
49
|
+
default: 10
|
48
50
|
}
|
49
51
|
},
|
50
52
|
additionalProperties: false
|
@@ -60,7 +62,10 @@ module.exports = {
|
|
60
62
|
},
|
61
63
|
additionalProperties: false
|
62
64
|
}
|
63
|
-
]
|
65
|
+
],
|
66
|
+
messages: {
|
67
|
+
exceed: "{{name}} has too many statements ({{count}}). Maximum allowed is {{max}}."
|
68
|
+
}
|
64
69
|
},
|
65
70
|
|
66
71
|
create(context) {
|
@@ -75,13 +80,9 @@ module.exports = {
|
|
75
80
|
topLevelFunctions = [];
|
76
81
|
let maxStatements = 10;
|
77
82
|
|
78
|
-
if (typeof option === "object"
|
79
|
-
maxStatements = option.maximum;
|
80
|
-
}
|
81
|
-
if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "max") && typeof option.max === "number") {
|
82
|
-
maxStatements = option.max;
|
83
|
-
}
|
84
|
-
if (typeof option === "number") {
|
83
|
+
if (typeof option === "object") {
|
84
|
+
maxStatements = option.maximum || option.max;
|
85
|
+
} else if (typeof option === "number") {
|
85
86
|
maxStatements = option;
|
86
87
|
}
|
87
88
|
|
@@ -99,7 +100,7 @@ module.exports = {
|
|
99
100
|
|
100
101
|
context.report({
|
101
102
|
node,
|
102
|
-
|
103
|
+
messageId: "exceed",
|
103
104
|
data: { name, count, max }
|
104
105
|
});
|
105
106
|
}
|
@@ -22,20 +22,21 @@ module.exports = {
|
|
22
22
|
},
|
23
23
|
|
24
24
|
fixable: "whitespace",
|
25
|
-
schema: [{ enum: ["starred-block", "separate-lines", "bare-block"] }]
|
25
|
+
schema: [{ enum: ["starred-block", "separate-lines", "bare-block"] }],
|
26
|
+
messages: {
|
27
|
+
expectedBlock: "Expected a block comment instead of consecutive line comments.",
|
28
|
+
startNewline: "Expected a linebreak after '/*'.",
|
29
|
+
endNewline: "Expected a linebreak before '*/'.",
|
30
|
+
missingStar: "Expected a '*' at the start of this line.",
|
31
|
+
alignment: "Expected this line to be aligned with the start of the comment.",
|
32
|
+
expectedLines: "Expected multiple line comments instead of a block comment."
|
33
|
+
}
|
26
34
|
},
|
27
35
|
|
28
36
|
create(context) {
|
29
37
|
const sourceCode = context.getSourceCode();
|
30
38
|
const option = context.options[0] || "starred-block";
|
31
39
|
|
32
|
-
const EXPECTED_BLOCK_ERROR = "Expected a block comment instead of consecutive line comments.";
|
33
|
-
const START_NEWLINE_ERROR = "Expected a linebreak after '/*'.";
|
34
|
-
const END_NEWLINE_ERROR = "Expected a linebreak before '*/'.";
|
35
|
-
const MISSING_STAR_ERROR = "Expected a '*' at the start of this line.";
|
36
|
-
const ALIGNMENT_ERROR = "Expected this line to be aligned with the start of the comment.";
|
37
|
-
const EXPECTED_LINES_ERROR = "Expected multiple line comments instead of a block comment.";
|
38
|
-
|
39
40
|
//----------------------------------------------------------------------
|
40
41
|
// Helpers
|
41
42
|
//----------------------------------------------------------------------
|
@@ -127,7 +128,7 @@ module.exports = {
|
|
127
128
|
start: commentGroup[0].loc.start,
|
128
129
|
end: commentGroup[commentGroup.length - 1].loc.end
|
129
130
|
},
|
130
|
-
|
131
|
+
messageId: "expectedBlock",
|
131
132
|
fix(fixer) {
|
132
133
|
const range = [commentGroup[0].range[0], commentGroup[commentGroup.length - 1].range[1]];
|
133
134
|
const starredBlock = `/*${convertToStarredBlock(commentGroup[0], commentLines)}*/`;
|
@@ -150,7 +151,7 @@ module.exports = {
|
|
150
151
|
start: block.loc.start,
|
151
152
|
end: { line: block.loc.start.line, column: block.loc.start.column + 2 }
|
152
153
|
},
|
153
|
-
|
154
|
+
messageId: "startNewline",
|
154
155
|
fix: fixer => fixer.insertTextAfterRange([start, start + 2], `\n${expectedLinePrefix}`)
|
155
156
|
});
|
156
157
|
}
|
@@ -161,7 +162,7 @@ module.exports = {
|
|
161
162
|
start: { line: block.loc.end.line, column: block.loc.end.column - 2 },
|
162
163
|
end: block.loc.end
|
163
164
|
},
|
164
|
-
|
165
|
+
messageId: "endNewline",
|
165
166
|
fix: fixer => fixer.replaceTextRange([block.range[1] - 2, block.range[1]], `\n${expectedLinePrefix}/`)
|
166
167
|
});
|
167
168
|
}
|
@@ -175,9 +176,9 @@ module.exports = {
|
|
175
176
|
start: { line: lineNumber, column: 0 },
|
176
177
|
end: { line: lineNumber, column: sourceCode.lines[lineNumber - 1].length }
|
177
178
|
},
|
178
|
-
|
179
|
-
?
|
180
|
-
:
|
179
|
+
messageId: /^\s*\*/.test(lineText)
|
180
|
+
? "alignment"
|
181
|
+
: "missingStar",
|
181
182
|
fix(fixer) {
|
182
183
|
const lineStartIndex = sourceCode.getIndexFromLoc({ line: lineNumber, column: 0 });
|
183
184
|
const linePrefixLength = lineText.match(/^\s*\*? ?/)[0].length;
|
@@ -209,7 +210,7 @@ module.exports = {
|
|
209
210
|
start: block.loc.start,
|
210
211
|
end: { line: block.loc.start.line, column: block.loc.start.column + 2 }
|
211
212
|
},
|
212
|
-
|
213
|
+
messageId: "expectedLines",
|
213
214
|
fix(fixer) {
|
214
215
|
return fixer.replaceText(block, convertToSeparateLines(block, commentLines.filter(line => line)));
|
215
216
|
}
|
@@ -228,7 +229,7 @@ module.exports = {
|
|
228
229
|
start: commentGroup[0].loc.start,
|
229
230
|
end: commentGroup[commentGroup.length - 1].loc.end
|
230
231
|
},
|
231
|
-
|
232
|
+
messageId: "expectedBlock",
|
232
233
|
fix(fixer) {
|
233
234
|
const range = [commentGroup[0].range[0], commentGroup[commentGroup.length - 1].range[1]];
|
234
235
|
const block = convertToBlock(commentGroup[0], commentLines.filter(line => line));
|
@@ -249,7 +250,7 @@ module.exports = {
|
|
249
250
|
start: block.loc.start,
|
250
251
|
end: { line: block.loc.start.line, column: block.loc.start.column + 2 }
|
251
252
|
},
|
252
|
-
|
253
|
+
messageId: "expectedBlock",
|
253
254
|
fix(fixer) {
|
254
255
|
return fixer.replaceText(block, convertToBlock(block, commentLines.filter(line => line)));
|
255
256
|
}
|
@@ -26,7 +26,13 @@ module.exports = {
|
|
26
26
|
{
|
27
27
|
enum: ["always", "always-multiline", "never"]
|
28
28
|
}
|
29
|
-
]
|
29
|
+
],
|
30
|
+
messages: {
|
31
|
+
expectedTestCons: "Expected newline between test and consequent of ternary expression.",
|
32
|
+
expectedConsAlt: "Expected newline between consequent and alternate of ternary expression.",
|
33
|
+
unexpectedTestCons: "Unexpected newline between test and consequent of ternary expression.",
|
34
|
+
unexpectedConsAlt: "Unexpected newline between consequent and alternate of ternary expression."
|
35
|
+
}
|
30
36
|
},
|
31
37
|
|
32
38
|
create(context) {
|
@@ -49,11 +55,7 @@ module.exports = {
|
|
49
55
|
function reportError(node, parentNode, expected) {
|
50
56
|
context.report({
|
51
57
|
node,
|
52
|
-
|
53
|
-
data: {
|
54
|
-
expected: expected ? "Expected" : "Unexpected",
|
55
|
-
typeOfError: node === parentNode.test ? "test and consequent" : "consequent and alternate"
|
56
|
-
}
|
58
|
+
messageId: `${expected ? "expected" : "unexpected"}${node === parentNode.test ? "TestCons" : "ConsAlt"}`
|
57
59
|
});
|
58
60
|
}
|
59
61
|
|
package/lib/rules/new-cap.js
CHANGED
@@ -88,10 +88,12 @@ module.exports = {
|
|
88
88
|
type: "object",
|
89
89
|
properties: {
|
90
90
|
newIsCap: {
|
91
|
-
type: "boolean"
|
91
|
+
type: "boolean",
|
92
|
+
default: true
|
92
93
|
},
|
93
94
|
capIsNew: {
|
94
|
-
type: "boolean"
|
95
|
+
type: "boolean",
|
96
|
+
default: true
|
95
97
|
},
|
96
98
|
newIsCapExceptions: {
|
97
99
|
type: "array",
|
@@ -112,17 +114,22 @@ module.exports = {
|
|
112
114
|
type: "string"
|
113
115
|
},
|
114
116
|
properties: {
|
115
|
-
type: "boolean"
|
117
|
+
type: "boolean",
|
118
|
+
default: true
|
116
119
|
}
|
117
120
|
},
|
118
121
|
additionalProperties: false
|
119
122
|
}
|
120
|
-
]
|
123
|
+
],
|
124
|
+
messages: {
|
125
|
+
upper: "A function with a name starting with an uppercase letter should only be used as a constructor.",
|
126
|
+
lower: "A constructor name should not start with a lowercase letter."
|
127
|
+
}
|
121
128
|
},
|
122
129
|
|
123
130
|
create(context) {
|
124
131
|
|
125
|
-
const config =
|
132
|
+
const config = Object.assign({}, context.options[0]);
|
126
133
|
|
127
134
|
config.newIsCap = config.newIsCap !== false;
|
128
135
|
config.capIsNew = config.capIsNew !== false;
|
@@ -219,19 +226,19 @@ module.exports = {
|
|
219
226
|
}
|
220
227
|
|
221
228
|
/**
|
222
|
-
* Reports the given
|
229
|
+
* Reports the given messageId for the given node. The location will be the start of the property or the callee.
|
223
230
|
* @param {ASTNode} node CallExpression or NewExpression node.
|
224
|
-
* @param {string}
|
231
|
+
* @param {string} messageId The messageId to report.
|
225
232
|
* @returns {void}
|
226
233
|
*/
|
227
|
-
function report(node,
|
234
|
+
function report(node, messageId) {
|
228
235
|
let callee = node.callee;
|
229
236
|
|
230
237
|
if (callee.type === "MemberExpression") {
|
231
238
|
callee = callee.property;
|
232
239
|
}
|
233
240
|
|
234
|
-
context.report({ node, loc: callee.loc.start,
|
241
|
+
context.report({ node, loc: callee.loc.start, messageId });
|
235
242
|
}
|
236
243
|
|
237
244
|
//--------------------------------------------------------------------------
|
@@ -248,7 +255,7 @@ module.exports = {
|
|
248
255
|
const isAllowed = capitalization !== "lower" || isCapAllowed(newIsCapExceptions, node, constructorName, newIsCapExceptionPattern);
|
249
256
|
|
250
257
|
if (!isAllowed) {
|
251
|
-
report(node, "
|
258
|
+
report(node, "lower");
|
252
259
|
}
|
253
260
|
}
|
254
261
|
};
|
@@ -264,7 +271,7 @@ module.exports = {
|
|
264
271
|
const isAllowed = capitalization !== "upper" || isCapAllowed(capIsNewExceptions, node, calleeName, capIsNewExceptionPattern);
|
265
272
|
|
266
273
|
if (!isAllowed) {
|
267
|
-
report(node, "
|
274
|
+
report(node, "upper");
|
268
275
|
}
|
269
276
|
}
|
270
277
|
};
|
package/lib/rules/new-parens.js
CHANGED
@@ -30,8 +30,11 @@ module.exports = {
|
|
30
30
|
url: "https://eslint.org/docs/rules/new-parens"
|
31
31
|
},
|
32
32
|
|
33
|
+
fixable: "code",
|
33
34
|
schema: [],
|
34
|
-
|
35
|
+
messages: {
|
36
|
+
missing: "Missing '()' invoking a constructor."
|
37
|
+
}
|
35
38
|
},
|
36
39
|
|
37
40
|
create(context) {
|
@@ -50,7 +53,7 @@ module.exports = {
|
|
50
53
|
if (!hasParens) {
|
51
54
|
context.report({
|
52
55
|
node,
|
53
|
-
|
56
|
+
messageId: "missing",
|
54
57
|
fix: fixer => fixer.insertTextAfter(node, "()")
|
55
58
|
});
|
56
59
|
}
|
@@ -26,14 +26,16 @@ module.exports = {
|
|
26
26
|
recommended: false,
|
27
27
|
url: "https://eslint.org/docs/rules/newline-after-var"
|
28
28
|
},
|
29
|
-
|
30
29
|
schema: [
|
31
30
|
{
|
32
31
|
enum: ["never", "always"]
|
33
32
|
}
|
34
33
|
],
|
35
|
-
|
36
34
|
fixable: "whitespace",
|
35
|
+
messages: {
|
36
|
+
expected: "Expected blank line after variable declarations.",
|
37
|
+
unexpected: "Unexpected blank line after variable declarations."
|
38
|
+
},
|
37
39
|
|
38
40
|
deprecated: true,
|
39
41
|
|
@@ -41,10 +43,6 @@ module.exports = {
|
|
41
43
|
},
|
42
44
|
|
43
45
|
create(context) {
|
44
|
-
|
45
|
-
const ALWAYS_MESSAGE = "Expected blank line after variable declarations.",
|
46
|
-
NEVER_MESSAGE = "Unexpected blank line after variable declarations.";
|
47
|
-
|
48
46
|
const sourceCode = context.getSourceCode();
|
49
47
|
|
50
48
|
// Default `mode` to "always".
|
@@ -214,7 +212,7 @@ module.exports = {
|
|
214
212
|
if (mode === "never" && noNextLineToken && !hasNextLineComment) {
|
215
213
|
context.report({
|
216
214
|
node,
|
217
|
-
|
215
|
+
messageId: "unexpected",
|
218
216
|
data: { identifier: node.name },
|
219
217
|
fix(fixer) {
|
220
218
|
const linesBetween = sourceCode.getText().slice(lastToken.range[1], nextToken.range[0]).split(astUtils.LINEBREAK_MATCHER);
|
@@ -233,7 +231,7 @@ module.exports = {
|
|
233
231
|
) {
|
234
232
|
context.report({
|
235
233
|
node,
|
236
|
-
|
234
|
+
messageId: "expected",
|
237
235
|
data: { identifier: node.name },
|
238
236
|
fix(fixer) {
|
239
237
|
if ((noNextLineToken ? getLastCommentLineOfBlock(nextLineNum) : lastToken.loc.end.line) === nextToken.loc.start.line) {
|
@@ -22,6 +22,10 @@ module.exports = {
|
|
22
22
|
|
23
23
|
fixable: "whitespace",
|
24
24
|
schema: [],
|
25
|
+
messages: {
|
26
|
+
expected: "Expected newline before return statement."
|
27
|
+
},
|
28
|
+
|
25
29
|
deprecated: true,
|
26
30
|
replacedBy: ["padding-line-between-statements"]
|
27
31
|
},
|
@@ -196,7 +200,7 @@ module.exports = {
|
|
196
200
|
if (!isFirstNode(node) && !hasNewlineBefore(node)) {
|
197
201
|
context.report({
|
198
202
|
node,
|
199
|
-
|
203
|
+
messageId: "expected",
|
200
204
|
fix(fixer) {
|
201
205
|
if (canFix(node)) {
|
202
206
|
const tokenBefore = sourceCode.getTokenBefore(node);
|
@@ -31,11 +31,15 @@ module.exports = {
|
|
31
31
|
ignoreChainWithDepth: {
|
32
32
|
type: "integer",
|
33
33
|
minimum: 1,
|
34
|
-
maximum: 10
|
34
|
+
maximum: 10,
|
35
|
+
default: 2
|
35
36
|
}
|
36
37
|
},
|
37
38
|
additionalProperties: false
|
38
|
-
}]
|
39
|
+
}],
|
40
|
+
messages: {
|
41
|
+
expected: "Expected line break before `{{callee}}`."
|
42
|
+
}
|
39
43
|
},
|
40
44
|
|
41
45
|
create(context) {
|
@@ -91,7 +95,7 @@ module.exports = {
|
|
91
95
|
context.report({
|
92
96
|
node: callee.property,
|
93
97
|
loc: callee.property.loc.start,
|
94
|
-
|
98
|
+
messageId: "expected",
|
95
99
|
data: {
|
96
100
|
callee: getPropertyText(callee)
|
97
101
|
},
|
@@ -20,7 +20,10 @@ module.exports = {
|
|
20
20
|
},
|
21
21
|
|
22
22
|
fixable: null,
|
23
|
-
schema: []
|
23
|
+
schema: [],
|
24
|
+
messages: {
|
25
|
+
async: "Promise executor functions should not be async."
|
26
|
+
}
|
24
27
|
},
|
25
28
|
|
26
29
|
create(context) {
|
@@ -28,7 +31,7 @@ module.exports = {
|
|
28
31
|
"NewExpression[callee.name='Promise'][arguments.0.async=true]"(node) {
|
29
32
|
context.report({
|
30
33
|
node: context.getSourceCode().getFirstToken(node.arguments[0], token => token.value === "async"),
|
31
|
-
|
34
|
+
messageId: "async"
|
32
35
|
});
|
33
36
|
}
|
34
37
|
};
|
package/lib/rules/no-bitwise.js
CHANGED
@@ -5,6 +5,13 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
//------------------------------------------------------------------------------
|
9
|
+
// Helpers
|
10
|
+
//------------------------------------------------------------------------------
|
11
|
+
|
12
|
+
const EQUALITY_OPERATORS = ["===", "!==", "==", "!="];
|
13
|
+
const RELATIONAL_OPERATORS = [">", "<", ">=", "<=", "in", "instanceof"];
|
14
|
+
|
8
15
|
//------------------------------------------------------------------------------
|
9
16
|
// Rule Definition
|
10
17
|
//------------------------------------------------------------------------------
|
@@ -25,7 +32,8 @@ module.exports = {
|
|
25
32
|
type: "object",
|
26
33
|
properties: {
|
27
34
|
checkLoops: {
|
28
|
-
type: "boolean"
|
35
|
+
type: "boolean",
|
36
|
+
default: true
|
29
37
|
}
|
30
38
|
},
|
31
39
|
additionalProperties: false
|
@@ -109,7 +117,21 @@ module.exports = {
|
|
109
117
|
const isLeftShortCircuit = (isLeftConstant && isLogicalIdentity(node.left, node.operator));
|
110
118
|
const isRightShortCircuit = (isRightConstant && isLogicalIdentity(node.right, node.operator));
|
111
119
|
|
112
|
-
return (isLeftConstant && isRightConstant) ||
|
120
|
+
return (isLeftConstant && isRightConstant) ||
|
121
|
+
(
|
122
|
+
|
123
|
+
// in the case of an "OR", we need to know if the right constant value is truthy
|
124
|
+
node.operator === "||" &&
|
125
|
+
isRightConstant &&
|
126
|
+
node.right.value &&
|
127
|
+
(
|
128
|
+
!node.parent ||
|
129
|
+
node.parent.type !== "BinaryExpression" ||
|
130
|
+
!(EQUALITY_OPERATORS.includes(node.parent.operator) || RELATIONAL_OPERATORS.includes(node.parent.operator))
|
131
|
+
)
|
132
|
+
) ||
|
133
|
+
isLeftShortCircuit ||
|
134
|
+
isRightShortCircuit;
|
113
135
|
}
|
114
136
|
|
115
137
|
case "AssignmentExpression":
|
@@ -29,18 +29,17 @@ function getValue(node) {
|
|
29
29
|
* @param {ASTNode} node - A node to get.
|
30
30
|
* @param {string} value - The name of the imported or exported module.
|
31
31
|
* @param {string[]} array - The array containing other imports or exports in the file.
|
32
|
-
* @param {string}
|
32
|
+
* @param {string} messageId - A messageId to be reported after the name of the module
|
33
33
|
*
|
34
34
|
* @returns {void} No return value
|
35
35
|
*/
|
36
|
-
function checkAndReport(context, node, value, array,
|
36
|
+
function checkAndReport(context, node, value, array, messageId) {
|
37
37
|
if (array.indexOf(value) !== -1) {
|
38
38
|
context.report({
|
39
39
|
node,
|
40
|
-
|
40
|
+
messageId,
|
41
41
|
data: {
|
42
|
-
module: value
|
43
|
-
message
|
42
|
+
module: value
|
44
43
|
}
|
45
44
|
});
|
46
45
|
}
|
@@ -66,10 +65,10 @@ function handleImports(context, includeExports, importsInFile, exportsInFile) {
|
|
66
65
|
const value = getValue(node);
|
67
66
|
|
68
67
|
if (value) {
|
69
|
-
checkAndReport(context, node, value, importsInFile, "import
|
68
|
+
checkAndReport(context, node, value, importsInFile, "import");
|
70
69
|
|
71
70
|
if (includeExports) {
|
72
|
-
checkAndReport(context, node, value, exportsInFile, "
|
71
|
+
checkAndReport(context, node, value, exportsInFile, "importAs");
|
73
72
|
}
|
74
73
|
|
75
74
|
importsInFile.push(value);
|
@@ -91,8 +90,8 @@ function handleExports(context, importsInFile, exportsInFile) {
|
|
91
90
|
const value = getValue(node);
|
92
91
|
|
93
92
|
if (value) {
|
94
|
-
checkAndReport(context, node, value, exportsInFile, "export
|
95
|
-
checkAndReport(context, node, value, importsInFile, "
|
93
|
+
checkAndReport(context, node, value, exportsInFile, "export");
|
94
|
+
checkAndReport(context, node, value, importsInFile, "exportAs");
|
96
95
|
|
97
96
|
exportsInFile.push(value);
|
98
97
|
}
|
@@ -114,11 +113,18 @@ module.exports = {
|
|
114
113
|
type: "object",
|
115
114
|
properties: {
|
116
115
|
includeExports: {
|
117
|
-
type: "boolean"
|
116
|
+
type: "boolean",
|
117
|
+
default: false
|
118
118
|
}
|
119
119
|
},
|
120
120
|
additionalProperties: false
|
121
|
-
}]
|
121
|
+
}],
|
122
|
+
messages: {
|
123
|
+
import: "'{{module}}' import is duplicated.",
|
124
|
+
importAs: "'{{module}}' import is duplicated as export.",
|
125
|
+
export: "'{{module}}' export is duplicated.",
|
126
|
+
exportAs: "'{{module}}' export is duplicated as import."
|
127
|
+
}
|
122
128
|
},
|
123
129
|
|
124
130
|
create(context) {
|
package/lib/rules/no-empty.js
CHANGED
package/lib/rules/no-eval.js
CHANGED
@@ -44,11 +44,11 @@ module.exports = {
|
|
44
44
|
{
|
45
45
|
type: "object",
|
46
46
|
properties: {
|
47
|
-
conditionalAssign: { type: "boolean" },
|
48
|
-
nestedBinaryExpressions: { type: "boolean" },
|
49
|
-
returnAssign: { type: "boolean" },
|
47
|
+
conditionalAssign: { type: "boolean", default: true },
|
48
|
+
nestedBinaryExpressions: { type: "boolean", default: true },
|
49
|
+
returnAssign: { type: "boolean", default: true },
|
50
50
|
ignoreJSX: { enum: ["none", "all", "single-line", "multi-line"] },
|
51
|
-
enforceForArrowConditionals: { type: "boolean" }
|
51
|
+
enforceForArrowConditionals: { type: "boolean", default: true }
|
52
52
|
},
|
53
53
|
additionalProperties: false
|
54
54
|
}
|
@@ -69,12 +69,17 @@ module.exports = {
|
|
69
69
|
type: "object",
|
70
70
|
properties: {
|
71
71
|
commentPattern: {
|
72
|
-
type: "string"
|
72
|
+
type: "string",
|
73
|
+
default: ""
|
73
74
|
}
|
74
75
|
},
|
75
76
|
additionalProperties: false
|
76
77
|
}
|
77
|
-
]
|
78
|
+
],
|
79
|
+
messages: {
|
80
|
+
case: "Expected a 'break' statement before 'case'.",
|
81
|
+
default: "Expected a 'break' statement before 'default'."
|
82
|
+
}
|
78
83
|
},
|
79
84
|
|
80
85
|
create(context) {
|
@@ -111,8 +116,7 @@ module.exports = {
|
|
111
116
|
*/
|
112
117
|
if (fallthroughCase && !hasFallthroughComment(node, context, fallthroughCommentPattern)) {
|
113
118
|
context.report({
|
114
|
-
|
115
|
-
data: { type: node.test ? "case" : "default" },
|
119
|
+
messageId: node.test ? "case" : "default",
|
116
120
|
node
|
117
121
|
});
|
118
122
|
}
|
@@ -27,7 +27,11 @@ module.exports = {
|
|
27
27
|
},
|
28
28
|
|
29
29
|
schema: [],
|
30
|
-
fixable: "code"
|
30
|
+
fixable: "code",
|
31
|
+
messages: {
|
32
|
+
leading: "A leading decimal point can be confused with a dot.",
|
33
|
+
trailing: "A trailing decimal point can be confused with a dot."
|
34
|
+
}
|
31
35
|
},
|
32
36
|
|
33
37
|
create(context) {
|
@@ -40,7 +44,7 @@ module.exports = {
|
|
40
44
|
if (node.raw.startsWith(".")) {
|
41
45
|
context.report({
|
42
46
|
node,
|
43
|
-
|
47
|
+
messageId: "leading",
|
44
48
|
fix(fixer) {
|
45
49
|
const tokenBefore = sourceCode.getTokenBefore(node);
|
46
50
|
const needsSpaceBefore = tokenBefore &&
|
@@ -54,7 +58,7 @@ module.exports = {
|
|
54
58
|
if (node.raw.indexOf(".") === node.raw.length - 1) {
|
55
59
|
context.report({
|
56
60
|
node,
|
57
|
-
|
61
|
+
messageId: "trailing",
|
58
62
|
fix: fixer => fixer.insertTextAfter(node, "0")
|
59
63
|
});
|
60
64
|
}
|