eslint 4.15.0 → 4.18.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 +56 -0
- package/lib/config/config-validator.js +9 -2
- package/lib/linter.js +38 -19
- package/lib/options.js +7 -7
- package/lib/report-translator.js +28 -37
- package/lib/rules/accessor-pairs.js +7 -3
- package/lib/rules/array-bracket-newline.js +11 -5
- package/lib/rules/array-bracket-spacing.js +11 -5
- package/lib/rules/array-callback-return.js +11 -5
- package/lib/rules/array-element-newline.js +8 -3
- package/lib/rules/arrow-body-style.js +16 -8
- package/lib/rules/arrow-parens.js +13 -9
- package/lib/rules/arrow-spacing.js +13 -5
- package/lib/rules/block-scoped-var.js +6 -2
- package/lib/rules/block-spacing.js +13 -6
- package/lib/rules/brace-style.js +16 -14
- package/lib/rules/callback-return.js +6 -2
- package/lib/rules/camelcase.js +6 -2
- package/lib/rules/capitalized-comments.js +11 -8
- package/lib/rules/class-methods-use-this.js +7 -3
- package/lib/rules/comma-dangle.js +7 -4
- package/lib/rules/comma-spacing.js +13 -10
- package/lib/rules/comma-style.js +16 -5
- package/lib/rules/complexity.js +6 -2
- package/lib/rules/computed-property-spacing.js +13 -5
- package/lib/rules/consistent-return.js +12 -7
- package/lib/rules/consistent-this.js +9 -4
- package/lib/rules/constructor-super.js +17 -8
- package/lib/rules/curly.js +59 -80
- package/lib/rules/default-case.js +6 -2
- package/lib/rules/dot-location.js +8 -3
- package/lib/rules/dot-notation.js +10 -5
- package/lib/rules/eol-last.js +7 -3
- package/lib/rules/eqeqeq.js +6 -2
- package/lib/rules/guard-for-in.js +35 -7
- package/lib/rules/indent.js +4 -4
- package/lib/rules/key-spacing.js +3 -2
- package/lib/rules/keyword-spacing.js +6 -1
- package/lib/rules/no-alert.js +19 -18
- package/lib/rules/no-array-constructor.js +6 -2
- package/lib/rules/no-await-in-loop.js +75 -57
- package/lib/rules/no-bitwise.js +6 -2
- package/lib/rules/no-buffer-constructor.js +6 -3
- package/lib/rules/no-caller.js +6 -2
- package/lib/rules/no-case-declarations.js +6 -2
- package/lib/rules/no-catch-shadow.js +6 -2
- package/lib/rules/no-class-assign.js +6 -2
- package/lib/rules/no-compare-neg-zero.js +5 -2
- package/lib/rules/no-cond-assign.js +10 -4
- package/lib/rules/no-confusing-arrow.js +6 -2
- package/lib/rules/no-console.js +6 -2
- package/lib/rules/no-const-assign.js +6 -2
- package/lib/rules/no-constant-condition.js +6 -3
- package/lib/rules/no-continue.js +6 -2
- package/lib/rules/no-control-regex.js +7 -3
- package/lib/rules/no-debugger.js +5 -2
- package/lib/rules/no-delete-var.js +6 -2
- package/lib/rules/no-div-regex.js +6 -2
- package/lib/rules/no-dupe-args.js +6 -2
- package/lib/rules/no-dupe-class-members.js +6 -2
- package/lib/rules/no-dupe-keys.js +6 -2
- package/lib/rules/no-duplicate-case.js +6 -2
- package/lib/rules/no-else-return.js +7 -2
- package/lib/rules/no-empty-character-class.js +6 -2
- package/lib/rules/no-empty-function.js +6 -2
- package/lib/rules/no-empty-pattern.js +7 -3
- package/lib/rules/no-empty.js +7 -3
- package/lib/rules/no-eq-null.js +6 -2
- package/lib/rules/no-eval.js +6 -2
- package/lib/rules/no-ex-assign.js +6 -2
- package/lib/rules/no-extend-native.js +6 -2
- package/lib/rules/no-extra-bind.js +6 -2
- package/lib/rules/no-extra-boolean-cast.js +8 -3
- package/lib/rules/no-extra-label.js +6 -2
- package/lib/rules/no-extra-parens.js +5 -1
- package/lib/rules/no-extra-semi.js +6 -2
- package/lib/rules/no-self-assign.js +3 -1
- package/lib/rules/no-unused-vars.js +1 -1
- package/lib/rules/object-curly-newline.js +67 -19
- package/lib/rules/object-property-newline.js +8 -2
- package/lib/rules/object-shorthand.js +9 -7
- package/lib/rules/padding-line-between-statements.js +6 -0
- package/lib/rules/prefer-destructuring.js +4 -2
- package/lib/rules/require-await.js +5 -0
- package/lib/rules/rest-spread-spacing.js +6 -0
- package/lib/rules/space-unary-ops.js +1 -10
- package/lib/rules/valid-jsdoc.js +89 -28
- package/lib/util/glob-util.js +17 -4
- package/lib/util/npm-util.js +1 -1
- package/package.json +2 -2
@@ -38,7 +38,15 @@ module.exports = {
|
|
38
38
|
},
|
39
39
|
additionalProperties: false
|
40
40
|
}
|
41
|
-
]
|
41
|
+
],
|
42
|
+
|
43
|
+
messages: {
|
44
|
+
expectedBefore: "Missing space before =>.",
|
45
|
+
unexpectedBefore: "Unexpected space before =>.",
|
46
|
+
|
47
|
+
expectedAfter: "Missing space after =>.",
|
48
|
+
unexpectedAfter: "Unexpected space after =>."
|
49
|
+
}
|
42
50
|
},
|
43
51
|
|
44
52
|
create(context) {
|
@@ -96,7 +104,7 @@ module.exports = {
|
|
96
104
|
if (countSpace.before === 0) {
|
97
105
|
context.report({
|
98
106
|
node: tokens.before,
|
99
|
-
|
107
|
+
messageId: "expectedBefore",
|
100
108
|
fix(fixer) {
|
101
109
|
return fixer.insertTextBefore(tokens.arrow, " ");
|
102
110
|
}
|
@@ -108,7 +116,7 @@ module.exports = {
|
|
108
116
|
if (countSpace.before > 0) {
|
109
117
|
context.report({
|
110
118
|
node: tokens.before,
|
111
|
-
|
119
|
+
messageId: "unexpectedBefore",
|
112
120
|
fix(fixer) {
|
113
121
|
return fixer.removeRange([tokens.before.range[1], tokens.arrow.range[0]]);
|
114
122
|
}
|
@@ -122,7 +130,7 @@ module.exports = {
|
|
122
130
|
if (countSpace.after === 0) {
|
123
131
|
context.report({
|
124
132
|
node: tokens.after,
|
125
|
-
|
133
|
+
messageId: "expectedAfter",
|
126
134
|
fix(fixer) {
|
127
135
|
return fixer.insertTextAfter(tokens.arrow, " ");
|
128
136
|
}
|
@@ -134,7 +142,7 @@ module.exports = {
|
|
134
142
|
if (countSpace.after > 0) {
|
135
143
|
context.report({
|
136
144
|
node: tokens.after,
|
137
|
-
|
145
|
+
messageId: "unexpectedAfter",
|
138
146
|
fix(fixer) {
|
139
147
|
return fixer.removeRange([tokens.arrow.range[1], tokens.after.range[0]]);
|
140
148
|
}
|
@@ -17,7 +17,11 @@ module.exports = {
|
|
17
17
|
url: "https://eslint.org/docs/rules/block-scoped-var"
|
18
18
|
},
|
19
19
|
|
20
|
-
schema: []
|
20
|
+
schema: [],
|
21
|
+
|
22
|
+
messages: {
|
23
|
+
outOfScope: "'{{name}}' used outside of binding context."
|
24
|
+
}
|
21
25
|
},
|
22
26
|
|
23
27
|
create(context) {
|
@@ -48,7 +52,7 @@ module.exports = {
|
|
48
52
|
function report(reference) {
|
49
53
|
const identifier = reference.identifier;
|
50
54
|
|
51
|
-
context.report({ node: identifier,
|
55
|
+
context.report({ node: identifier, messageId: "outOfScope", data: { name: identifier.name } });
|
52
56
|
}
|
53
57
|
|
54
58
|
/**
|
@@ -24,12 +24,17 @@ module.exports = {
|
|
24
24
|
|
25
25
|
schema: [
|
26
26
|
{ enum: ["always", "never"] }
|
27
|
-
]
|
27
|
+
],
|
28
|
+
|
29
|
+
messages: {
|
30
|
+
missing: "Requires a space {{location}} '{{token}}'",
|
31
|
+
extra: "Unexpected space(s) {{location}} '{{token}}'"
|
32
|
+
}
|
28
33
|
},
|
29
34
|
|
30
35
|
create(context) {
|
31
36
|
const always = (context.options[0] !== "never"),
|
32
|
-
|
37
|
+
messageId = always ? "missing" : "extra",
|
33
38
|
sourceCode = context.getSourceCode();
|
34
39
|
|
35
40
|
/**
|
@@ -98,9 +103,10 @@ module.exports = {
|
|
98
103
|
context.report({
|
99
104
|
node,
|
100
105
|
loc: openBrace.loc.start,
|
101
|
-
|
106
|
+
messageId,
|
102
107
|
data: {
|
103
|
-
|
108
|
+
location: "after",
|
109
|
+
token: openBrace.value
|
104
110
|
},
|
105
111
|
fix(fixer) {
|
106
112
|
if (always) {
|
@@ -115,9 +121,10 @@ module.exports = {
|
|
115
121
|
context.report({
|
116
122
|
node,
|
117
123
|
loc: closeBrace.loc.start,
|
118
|
-
|
124
|
+
messageId,
|
119
125
|
data: {
|
120
|
-
|
126
|
+
location: "before",
|
127
|
+
token: closeBrace.value
|
121
128
|
},
|
122
129
|
fix(fixer) {
|
123
130
|
if (always) {
|
package/lib/rules/brace-style.js
CHANGED
@@ -35,7 +35,16 @@ module.exports = {
|
|
35
35
|
}
|
36
36
|
],
|
37
37
|
|
38
|
-
fixable: "whitespace"
|
38
|
+
fixable: "whitespace",
|
39
|
+
|
40
|
+
messages: {
|
41
|
+
nextLineOpen: "Opening curly brace does not appear on the same line as controlling statement.",
|
42
|
+
sameLineOpen: "Opening curly brace appears on the same line as controlling statement.",
|
43
|
+
blockSameLine: "Statement inside of curly braces should be on next line.",
|
44
|
+
nextLineClose: "Closing curly brace does not appear on the same line as the subsequent block.",
|
45
|
+
singleLineClose: "Closing curly brace should be on the same line as opening curly brace or on the line after the previous block.",
|
46
|
+
sameLineClose: "Closing curly brace appears on the same line as the subsequent block."
|
47
|
+
}
|
39
48
|
},
|
40
49
|
|
41
50
|
create(context) {
|
@@ -43,13 +52,6 @@ module.exports = {
|
|
43
52
|
params = context.options[1] || {},
|
44
53
|
sourceCode = context.getSourceCode();
|
45
54
|
|
46
|
-
const OPEN_MESSAGE = "Opening curly brace does not appear on the same line as controlling statement.",
|
47
|
-
OPEN_MESSAGE_ALLMAN = "Opening curly brace appears on the same line as controlling statement.",
|
48
|
-
BODY_MESSAGE = "Statement inside of curly braces should be on next line.",
|
49
|
-
CLOSE_MESSAGE = "Closing curly brace does not appear on the same line as the subsequent block.",
|
50
|
-
CLOSE_MESSAGE_SINGLE = "Closing curly brace should be on the same line as opening curly brace or on the line after the previous block.",
|
51
|
-
CLOSE_MESSAGE_STROUSTRUP_ALLMAN = "Closing curly brace appears on the same line as the subsequent block.";
|
52
|
-
|
53
55
|
//--------------------------------------------------------------------------
|
54
56
|
// Helpers
|
55
57
|
//--------------------------------------------------------------------------
|
@@ -86,7 +88,7 @@ module.exports = {
|
|
86
88
|
if (style !== "allman" && !astUtils.isTokenOnSameLine(tokenBeforeOpeningCurly, openingCurly)) {
|
87
89
|
context.report({
|
88
90
|
node: openingCurly,
|
89
|
-
|
91
|
+
messageId: "nextLineOpen",
|
90
92
|
fix: removeNewlineBetween(tokenBeforeOpeningCurly, openingCurly)
|
91
93
|
});
|
92
94
|
}
|
@@ -94,7 +96,7 @@ module.exports = {
|
|
94
96
|
if (style === "allman" && astUtils.isTokenOnSameLine(tokenBeforeOpeningCurly, openingCurly) && !singleLineException) {
|
95
97
|
context.report({
|
96
98
|
node: openingCurly,
|
97
|
-
|
99
|
+
messageId: "sameLineOpen",
|
98
100
|
fix: fixer => fixer.insertTextBefore(openingCurly, "\n")
|
99
101
|
});
|
100
102
|
}
|
@@ -102,7 +104,7 @@ module.exports = {
|
|
102
104
|
if (astUtils.isTokenOnSameLine(openingCurly, tokenAfterOpeningCurly) && tokenAfterOpeningCurly !== closingCurly && !singleLineException) {
|
103
105
|
context.report({
|
104
106
|
node: openingCurly,
|
105
|
-
|
107
|
+
messageId: "blockSameLine",
|
106
108
|
fix: fixer => fixer.insertTextAfter(openingCurly, "\n")
|
107
109
|
});
|
108
110
|
}
|
@@ -110,7 +112,7 @@ module.exports = {
|
|
110
112
|
if (tokenBeforeClosingCurly !== openingCurly && !singleLineException && astUtils.isTokenOnSameLine(tokenBeforeClosingCurly, closingCurly)) {
|
111
113
|
context.report({
|
112
114
|
node: closingCurly,
|
113
|
-
|
115
|
+
messageId: "singleLineClose",
|
114
116
|
fix: fixer => fixer.insertTextBefore(closingCurly, "\n")
|
115
117
|
});
|
116
118
|
}
|
@@ -127,7 +129,7 @@ module.exports = {
|
|
127
129
|
if (style === "1tbs" && !astUtils.isTokenOnSameLine(curlyToken, keywordToken)) {
|
128
130
|
context.report({
|
129
131
|
node: curlyToken,
|
130
|
-
|
132
|
+
messageId: "nextLineClose",
|
131
133
|
fix: removeNewlineBetween(curlyToken, keywordToken)
|
132
134
|
});
|
133
135
|
}
|
@@ -135,7 +137,7 @@ module.exports = {
|
|
135
137
|
if (style !== "1tbs" && astUtils.isTokenOnSameLine(curlyToken, keywordToken)) {
|
136
138
|
context.report({
|
137
139
|
node: curlyToken,
|
138
|
-
|
140
|
+
messageId: "sameLineClose",
|
139
141
|
fix: fixer => fixer.insertTextAfter(curlyToken, "\n")
|
140
142
|
});
|
141
143
|
}
|
@@ -20,7 +20,11 @@ module.exports = {
|
|
20
20
|
schema: [{
|
21
21
|
type: "array",
|
22
22
|
items: { type: "string" }
|
23
|
-
}]
|
23
|
+
}],
|
24
|
+
|
25
|
+
messages: {
|
26
|
+
missingReturn: "Expected return with your callback function."
|
27
|
+
}
|
24
28
|
},
|
25
29
|
|
26
30
|
create(context) {
|
@@ -166,7 +170,7 @@ module.exports = {
|
|
166
170
|
|
167
171
|
// as long as you're the child of a function at this point you should be asked to return
|
168
172
|
if (findClosestParentOfType(node, ["FunctionDeclaration", "FunctionExpression", "ArrowFunctionExpression"])) {
|
169
|
-
context.report({ node,
|
173
|
+
context.report({ node, messageId: "missingReturn" });
|
170
174
|
}
|
171
175
|
|
172
176
|
}
|
package/lib/rules/camelcase.js
CHANGED
@@ -28,7 +28,11 @@ module.exports = {
|
|
28
28
|
},
|
29
29
|
additionalProperties: false
|
30
30
|
}
|
31
|
-
]
|
31
|
+
],
|
32
|
+
|
33
|
+
messages: {
|
34
|
+
notCamelCase: "Identifier '{{name}}' is not in camel case."
|
35
|
+
}
|
32
36
|
},
|
33
37
|
|
34
38
|
create(context) {
|
@@ -62,7 +66,7 @@ module.exports = {
|
|
62
66
|
function report(node) {
|
63
67
|
if (reported.indexOf(node) < 0) {
|
64
68
|
reported.push(node);
|
65
|
-
context.report({ node,
|
69
|
+
context.report({ node, messageId: "notCamelCase", data: { name: node.name } });
|
66
70
|
}
|
67
71
|
}
|
68
72
|
|
@@ -15,9 +15,7 @@ const astUtils = require("../ast-utils");
|
|
15
15
|
// Helpers
|
16
16
|
//------------------------------------------------------------------------------
|
17
17
|
|
18
|
-
const
|
19
|
-
NEVER_MESSAGE = "Comments should not begin with an uppercase character",
|
20
|
-
DEFAULT_IGNORE_PATTERN = astUtils.COMMENTS_IGNORE_PATTERN,
|
18
|
+
const DEFAULT_IGNORE_PATTERN = astUtils.COMMENTS_IGNORE_PATTERN,
|
21
19
|
WHITESPACE = /\s/g,
|
22
20
|
MAYBE_URL = /^\s*[^:/?#\s]+:\/\/[^?#]/, // TODO: Combine w/ max-len pattern?
|
23
21
|
DEFAULTS = {
|
@@ -132,7 +130,12 @@ module.exports = {
|
|
132
130
|
}
|
133
131
|
]
|
134
132
|
}
|
135
|
-
]
|
133
|
+
],
|
134
|
+
|
135
|
+
messages: {
|
136
|
+
unexpectedLowercaseComment: "Comments should not begin with a lowercase character",
|
137
|
+
unexpectedUppercaseComment: "Comments should not begin with an uppercase character"
|
138
|
+
}
|
136
139
|
},
|
137
140
|
|
138
141
|
create(context) {
|
@@ -267,14 +270,14 @@ module.exports = {
|
|
267
270
|
commentValid = isCommentValid(comment, options);
|
268
271
|
|
269
272
|
if (!commentValid) {
|
270
|
-
const
|
271
|
-
?
|
272
|
-
:
|
273
|
+
const messageId = capitalize === "always"
|
274
|
+
? "unexpectedLowercaseComment"
|
275
|
+
: "unexpectedUppercaseComment";
|
273
276
|
|
274
277
|
context.report({
|
275
278
|
node: null, // Intentionally using loc instead
|
276
279
|
loc: comment.loc,
|
277
|
-
|
280
|
+
messageId,
|
278
281
|
fix(fixer) {
|
279
282
|
const match = comment.value.match(LETTER_PATTERN);
|
280
283
|
|
@@ -28,7 +28,11 @@ module.exports = {
|
|
28
28
|
}
|
29
29
|
},
|
30
30
|
additionalProperties: false
|
31
|
-
}]
|
31
|
+
}],
|
32
|
+
|
33
|
+
messages: {
|
34
|
+
missingThis: "Expected 'this' to be used by class method '{{name}}'."
|
35
|
+
}
|
32
36
|
},
|
33
37
|
create(context) {
|
34
38
|
const config = context.options[0] ? Object.assign({}, context.options[0]) : {};
|
@@ -80,9 +84,9 @@ module.exports = {
|
|
80
84
|
if (isIncludedInstanceMethod(node.parent) && !methodUsesThis) {
|
81
85
|
context.report({
|
82
86
|
node,
|
83
|
-
|
87
|
+
messageId: "missingThis",
|
84
88
|
data: {
|
85
|
-
|
89
|
+
name: node.parent.key.name
|
86
90
|
}
|
87
91
|
});
|
88
92
|
}
|
@@ -124,14 +124,17 @@ module.exports = {
|
|
124
124
|
]
|
125
125
|
}
|
126
126
|
]
|
127
|
+
},
|
128
|
+
|
129
|
+
messages: {
|
130
|
+
unexpected: "Unexpected trailing comma.",
|
131
|
+
missing: "Missing trailing comma."
|
127
132
|
}
|
128
133
|
},
|
129
134
|
|
130
135
|
create(context) {
|
131
136
|
const options = normalizeOptions(context.options[0]);
|
132
137
|
const sourceCode = context.getSourceCode();
|
133
|
-
const UNEXPECTED_MESSAGE = "Unexpected trailing comma.";
|
134
|
-
const MISSING_MESSAGE = "Missing trailing comma.";
|
135
138
|
|
136
139
|
/**
|
137
140
|
* Gets the last item of the given node.
|
@@ -230,7 +233,7 @@ module.exports = {
|
|
230
233
|
context.report({
|
231
234
|
node: lastItem,
|
232
235
|
loc: trailingToken.loc.start,
|
233
|
-
|
236
|
+
messageId: "unexpected",
|
234
237
|
fix(fixer) {
|
235
238
|
return fixer.remove(trailingToken);
|
236
239
|
}
|
@@ -267,7 +270,7 @@ module.exports = {
|
|
267
270
|
context.report({
|
268
271
|
node: lastItem,
|
269
272
|
loc: trailingToken.loc.end,
|
270
|
-
|
273
|
+
messageId: "missing",
|
271
274
|
fix(fixer) {
|
272
275
|
return fixer.insertTextAfter(trailingToken, ",");
|
273
276
|
}
|
@@ -34,7 +34,12 @@ module.exports = {
|
|
34
34
|
},
|
35
35
|
additionalProperties: false
|
36
36
|
}
|
37
|
-
]
|
37
|
+
],
|
38
|
+
|
39
|
+
messages: {
|
40
|
+
missing: "A space is required {{loc}} ','.",
|
41
|
+
unexpected: "There should be no space {{loc}} ','."
|
42
|
+
}
|
38
43
|
},
|
39
44
|
|
40
45
|
create(context) {
|
@@ -57,17 +62,17 @@ module.exports = {
|
|
57
62
|
/**
|
58
63
|
* Reports a spacing error with an appropriate message.
|
59
64
|
* @param {ASTNode} node The binary expression node to report.
|
60
|
-
* @param {string}
|
65
|
+
* @param {string} loc Is the error "before" or "after" the comma?
|
61
66
|
* @param {ASTNode} otherNode The node at the left or right of `node`
|
62
67
|
* @returns {void}
|
63
68
|
* @private
|
64
69
|
*/
|
65
|
-
function report(node,
|
70
|
+
function report(node, loc, otherNode) {
|
66
71
|
context.report({
|
67
72
|
node,
|
68
73
|
fix(fixer) {
|
69
|
-
if (options[
|
70
|
-
if (
|
74
|
+
if (options[loc]) {
|
75
|
+
if (loc === "before") {
|
71
76
|
return fixer.insertTextBefore(node, " ");
|
72
77
|
}
|
73
78
|
return fixer.insertTextAfter(node, " ");
|
@@ -76,7 +81,7 @@ module.exports = {
|
|
76
81
|
let start, end;
|
77
82
|
const newText = "";
|
78
83
|
|
79
|
-
if (
|
84
|
+
if (loc === "before") {
|
80
85
|
start = otherNode.range[1];
|
81
86
|
end = node.range[0];
|
82
87
|
} else {
|
@@ -87,11 +92,9 @@ module.exports = {
|
|
87
92
|
return fixer.replaceTextRange([start, end], newText);
|
88
93
|
|
89
94
|
},
|
90
|
-
|
91
|
-
? "A space is required {{dir}} ','."
|
92
|
-
: "There should be no space {{dir}} ','.",
|
95
|
+
messageId: options[loc] ? "missing" : "unexpected",
|
93
96
|
data: {
|
94
|
-
|
97
|
+
loc
|
95
98
|
}
|
96
99
|
});
|
97
100
|
}
|
package/lib/rules/comma-style.js
CHANGED
@@ -36,7 +36,12 @@ module.exports = {
|
|
36
36
|
},
|
37
37
|
additionalProperties: false
|
38
38
|
}
|
39
|
-
]
|
39
|
+
],
|
40
|
+
messages: {
|
41
|
+
unexpectedLineBeforeAndAfterComma: "Bad line breaking before and after ','.",
|
42
|
+
expectedCommaFirst: "',' should be placed first.",
|
43
|
+
expectedCommaLast: "',' should be placed last."
|
44
|
+
}
|
40
45
|
},
|
41
46
|
|
42
47
|
create(context) {
|
@@ -49,7 +54,8 @@ module.exports = {
|
|
49
54
|
FunctionDeclaration: true,
|
50
55
|
FunctionExpression: true,
|
51
56
|
ImportDeclaration: true,
|
52
|
-
ObjectPattern: true
|
57
|
+
ObjectPattern: true,
|
58
|
+
NewExpression: true
|
53
59
|
};
|
54
60
|
|
55
61
|
if (context.options.length === 2 && context.options[1].hasOwnProperty("exceptions")) {
|
@@ -134,7 +140,7 @@ module.exports = {
|
|
134
140
|
line: commaToken.loc.end.line,
|
135
141
|
column: commaToken.loc.start.column
|
136
142
|
},
|
137
|
-
|
143
|
+
messageId: "unexpectedLineBeforeAndAfterComma",
|
138
144
|
fix: getFixerFunction("between", previousItemToken, commaToken, currentItemToken)
|
139
145
|
});
|
140
146
|
|
@@ -142,7 +148,7 @@ module.exports = {
|
|
142
148
|
|
143
149
|
context.report({
|
144
150
|
node: reportItem,
|
145
|
-
|
151
|
+
messageId: "expectedCommaFirst",
|
146
152
|
fix: getFixerFunction(style, previousItemToken, commaToken, currentItemToken)
|
147
153
|
});
|
148
154
|
|
@@ -154,7 +160,7 @@ module.exports = {
|
|
154
160
|
line: commaToken.loc.end.line,
|
155
161
|
column: commaToken.loc.end.column
|
156
162
|
},
|
157
|
-
|
163
|
+
messageId: "expectedCommaLast",
|
158
164
|
fix: getFixerFunction(style, previousItemToken, commaToken, currentItemToken)
|
159
165
|
});
|
160
166
|
}
|
@@ -294,6 +300,11 @@ module.exports = {
|
|
294
300
|
validateComma(node, "specifiers");
|
295
301
|
};
|
296
302
|
}
|
303
|
+
if (!exceptions.NewExpression) {
|
304
|
+
nodes.NewExpression = function(node) {
|
305
|
+
validateComma(node, "arguments");
|
306
|
+
};
|
307
|
+
}
|
297
308
|
|
298
309
|
return nodes;
|
299
310
|
}
|
package/lib/rules/complexity.js
CHANGED
@@ -50,7 +50,11 @@ module.exports = {
|
|
50
50
|
}
|
51
51
|
]
|
52
52
|
}
|
53
|
-
]
|
53
|
+
],
|
54
|
+
|
55
|
+
messages: {
|
56
|
+
complex: "{{name}} has a complexity of {{complexity}}."
|
57
|
+
}
|
54
58
|
},
|
55
59
|
|
56
60
|
create(context) {
|
@@ -96,7 +100,7 @@ module.exports = {
|
|
96
100
|
if (complexity > THRESHOLD) {
|
97
101
|
context.report({
|
98
102
|
node,
|
99
|
-
|
103
|
+
messageId: "complex",
|
100
104
|
data: { name, complexity }
|
101
105
|
});
|
102
106
|
}
|
@@ -25,7 +25,15 @@ module.exports = {
|
|
25
25
|
{
|
26
26
|
enum: ["always", "never"]
|
27
27
|
}
|
28
|
-
]
|
28
|
+
],
|
29
|
+
|
30
|
+
messages: {
|
31
|
+
unexpectedSpaceBefore: "There should be no space before '{{tokenValue}}'.",
|
32
|
+
unexpectedSpaceAfter: "There should be no space after '{{tokenValue}}'.",
|
33
|
+
|
34
|
+
missingSpaceBefore: "A space is required before '{{tokenValue}}'.",
|
35
|
+
missingSpaceAfter: "A space is required after '{{tokenValue}}'."
|
36
|
+
}
|
29
37
|
},
|
30
38
|
|
31
39
|
create(context) {
|
@@ -47,7 +55,7 @@ module.exports = {
|
|
47
55
|
context.report({
|
48
56
|
node,
|
49
57
|
loc: token.loc.start,
|
50
|
-
|
58
|
+
messageId: "unexpectedSpaceAfter",
|
51
59
|
data: {
|
52
60
|
tokenValue: token.value
|
53
61
|
},
|
@@ -68,7 +76,7 @@ module.exports = {
|
|
68
76
|
context.report({
|
69
77
|
node,
|
70
78
|
loc: token.loc.start,
|
71
|
-
|
79
|
+
messageId: "unexpectedSpaceBefore",
|
72
80
|
data: {
|
73
81
|
tokenValue: token.value
|
74
82
|
},
|
@@ -88,7 +96,7 @@ module.exports = {
|
|
88
96
|
context.report({
|
89
97
|
node,
|
90
98
|
loc: token.loc.start,
|
91
|
-
|
99
|
+
messageId: "missingSpaceAfter",
|
92
100
|
data: {
|
93
101
|
tokenValue: token.value
|
94
102
|
},
|
@@ -108,7 +116,7 @@ module.exports = {
|
|
108
116
|
context.report({
|
109
117
|
node,
|
110
118
|
loc: token.loc.start,
|
111
|
-
|
119
|
+
messageId: "missingSpaceBefore",
|
112
120
|
data: {
|
113
121
|
tokenValue: token.value
|
114
122
|
},
|
@@ -68,7 +68,13 @@ module.exports = {
|
|
68
68
|
}
|
69
69
|
},
|
70
70
|
additionalProperties: false
|
71
|
-
}]
|
71
|
+
}],
|
72
|
+
|
73
|
+
messages: {
|
74
|
+
missingReturn: "Expected to return a value at the end of {{name}}.",
|
75
|
+
missingReturnValue: "{{name}} expected a return value.",
|
76
|
+
unexpectedReturnValue: "{{name}} expected no return value."
|
77
|
+
}
|
72
78
|
},
|
73
79
|
|
74
80
|
create(context) {
|
@@ -129,7 +135,7 @@ module.exports = {
|
|
129
135
|
context.report({
|
130
136
|
node,
|
131
137
|
loc,
|
132
|
-
|
138
|
+
messageId: "missingReturn",
|
133
139
|
data: { name }
|
134
140
|
});
|
135
141
|
}
|
@@ -143,7 +149,7 @@ module.exports = {
|
|
143
149
|
codePath,
|
144
150
|
hasReturn: false,
|
145
151
|
hasReturnValue: false,
|
146
|
-
|
152
|
+
messageId: "",
|
147
153
|
node
|
148
154
|
};
|
149
155
|
},
|
@@ -163,17 +169,16 @@ module.exports = {
|
|
163
169
|
if (!funcInfo.hasReturn) {
|
164
170
|
funcInfo.hasReturn = true;
|
165
171
|
funcInfo.hasReturnValue = hasReturnValue;
|
166
|
-
funcInfo.
|
172
|
+
funcInfo.messageId = hasReturnValue ? "missingReturnValue" : "unexpectedReturnValue";
|
167
173
|
funcInfo.data = {
|
168
174
|
name: funcInfo.node.type === "Program"
|
169
175
|
? "Program"
|
170
|
-
: lodash.upperFirst(astUtils.getFunctionNameWithKind(funcInfo.node))
|
171
|
-
which: hasReturnValue ? "a" : "no"
|
176
|
+
: lodash.upperFirst(astUtils.getFunctionNameWithKind(funcInfo.node))
|
172
177
|
};
|
173
178
|
} else if (funcInfo.hasReturnValue !== hasReturnValue) {
|
174
179
|
context.report({
|
175
180
|
node,
|
176
|
-
|
181
|
+
messageId: funcInfo.messageId,
|
177
182
|
data: funcInfo.data
|
178
183
|
});
|
179
184
|
}
|
@@ -24,6 +24,11 @@ module.exports = {
|
|
24
24
|
minLength: 1
|
25
25
|
},
|
26
26
|
uniqueItems: true
|
27
|
+
},
|
28
|
+
|
29
|
+
messages: {
|
30
|
+
aliasNotAssignedToThis: "Designated alias '{{name}}' is not assigned to 'this'.",
|
31
|
+
unexpectedAlias: "Unexpected alias '{{name}}' for 'this'."
|
27
32
|
}
|
28
33
|
},
|
29
34
|
|
@@ -40,11 +45,11 @@ module.exports = {
|
|
40
45
|
* Reports that a variable declarator or assignment expression is assigning
|
41
46
|
* a non-'this' value to the specified alias.
|
42
47
|
* @param {ASTNode} node - The assigning node.
|
43
|
-
* @param {string}
|
48
|
+
* @param {string} name - the name of the alias that was incorrectly used.
|
44
49
|
* @returns {void}
|
45
50
|
*/
|
46
|
-
function reportBadAssignment(node,
|
47
|
-
context.report({ node,
|
51
|
+
function reportBadAssignment(node, name) {
|
52
|
+
context.report({ node, messageId: "aliasNotAssignedToThis", data: { name } });
|
48
53
|
}
|
49
54
|
|
50
55
|
/**
|
@@ -63,7 +68,7 @@ module.exports = {
|
|
63
68
|
reportBadAssignment(node, name);
|
64
69
|
}
|
65
70
|
} else if (isThis) {
|
66
|
-
context.report({ node,
|
71
|
+
context.report({ node, messageId: "unexpectedAlias", data: { name } });
|
67
72
|
}
|
68
73
|
}
|
69
74
|
|