eslint 4.7.2 → 4.11.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 +123 -0
- package/README.md +34 -19
- package/conf/default-cli-options.js +7 -4
- package/conf/eslint-recommended.js +2 -0
- package/lib/ast-utils.js +83 -42
- package/lib/cli-engine.js +53 -17
- package/lib/cli.js +17 -9
- package/lib/code-path-analysis/code-path-analyzer.js +8 -4
- package/lib/code-path-analysis/code-path-segment.js +43 -41
- package/lib/code-path-analysis/code-path-state.js +7 -2
- package/lib/config/autoconfig.js +14 -12
- package/lib/config/config-file.js +8 -51
- package/lib/config/config-initializer.js +10 -6
- package/lib/config/config-ops.js +21 -21
- package/lib/config/config-rule.js +24 -24
- package/lib/config/config-validator.js +38 -36
- package/lib/config/plugins.js +8 -35
- package/lib/config.js +12 -8
- package/lib/formatters/html-template-message.html +1 -1
- package/lib/formatters/html-template-page.html +3 -1
- package/lib/formatters/html.js +2 -1
- package/lib/formatters/junit.js +21 -15
- package/lib/formatters/tap.js +5 -3
- package/lib/ignored-paths.js +5 -3
- package/lib/linter.js +42 -42
- package/lib/logging.js +2 -2
- package/lib/options.js +12 -0
- package/lib/rules/.eslintrc.yml +2 -2
- package/lib/rules/array-bracket-newline.js +39 -25
- package/lib/rules/array-bracket-spacing.js +28 -28
- package/lib/rules/array-callback-return.js +13 -9
- package/lib/rules/array-element-newline.js +8 -8
- package/lib/rules/arrow-body-style.js +12 -6
- package/lib/rules/arrow-parens.js +4 -2
- package/lib/rules/block-spacing.js +1 -1
- package/lib/rules/brace-style.js +14 -14
- package/lib/rules/callback-return.js +2 -1
- package/lib/rules/capitalized-comments.js +2 -1
- package/lib/rules/comma-style.js +3 -1
- package/lib/rules/computed-property-spacing.js +22 -22
- package/lib/rules/consistent-return.js +4 -4
- package/lib/rules/consistent-this.js +4 -2
- package/lib/rules/curly.js +13 -9
- package/lib/rules/dot-notation.js +56 -35
- package/lib/rules/func-call-spacing.js +4 -2
- package/lib/rules/generator-star-spacing.js +3 -3
- package/lib/rules/getter-return.js +2 -1
- package/lib/rules/indent-legacy.js +25 -14
- package/lib/rules/indent.js +101 -91
- package/lib/rules/key-spacing.js +5 -3
- package/lib/rules/lines-around-comment.js +33 -4
- package/lib/rules/lines-around-directive.js +16 -12
- package/lib/rules/lines-between-class-members.js +91 -0
- package/lib/rules/max-len.js +2 -3
- package/lib/rules/max-statements-per-line.js +5 -3
- package/lib/rules/multiline-comment-style.js +294 -0
- package/lib/rules/new-cap.js +2 -1
- package/lib/rules/newline-after-var.js +8 -6
- package/lib/rules/newline-before-return.js +13 -9
- package/lib/rules/no-alert.js +7 -15
- package/lib/rules/no-await-in-loop.js +17 -9
- package/lib/rules/no-bitwise.js +5 -3
- package/lib/rules/no-catch-shadow.js +4 -2
- package/lib/rules/no-console.js +2 -1
- package/lib/rules/no-constant-condition.js +2 -2
- package/lib/rules/no-control-regex.js +2 -1
- package/lib/rules/no-else-return.js +60 -19
- package/lib/rules/no-empty-character-class.js +11 -11
- package/lib/rules/no-extra-parens.js +22 -11
- package/lib/rules/no-extra-semi.js +5 -3
- package/lib/rules/no-global-assign.js +4 -2
- package/lib/rules/no-implicit-coercion.js +6 -6
- package/lib/rules/no-implied-eval.js +2 -1
- package/lib/rules/no-label-var.js +4 -2
- package/lib/rules/no-lone-blocks.js +3 -3
- package/lib/rules/no-lonely-if.js +2 -1
- package/lib/rules/no-loop-func.js +10 -7
- package/lib/rules/no-mixed-requires.js +8 -4
- package/lib/rules/no-native-reassign.js +4 -2
- package/lib/rules/no-param-reassign.js +4 -2
- package/lib/rules/no-regex-spaces.js +1 -1
- package/lib/rules/no-restricted-imports.js +86 -17
- package/lib/rules/no-restricted-modules.js +84 -15
- package/lib/rules/no-restricted-properties.js +10 -10
- package/lib/rules/no-return-await.js +6 -6
- package/lib/rules/no-self-assign.js +4 -2
- package/lib/rules/no-sequences.js +6 -4
- package/lib/rules/no-trailing-spaces.js +14 -8
- package/lib/rules/no-unneeded-ternary.js +3 -1
- package/lib/rules/no-unreachable.js +4 -2
- package/lib/rules/no-unused-labels.js +2 -1
- package/lib/rules/no-use-before-define.js +13 -11
- package/lib/rules/no-useless-call.js +1 -25
- package/lib/rules/no-useless-computed-key.js +2 -1
- package/lib/rules/no-useless-escape.js +31 -23
- package/lib/rules/no-useless-return.js +14 -8
- package/lib/rules/no-var.js +11 -0
- package/lib/rules/no-whitespace-before-property.js +4 -2
- package/lib/rules/object-curly-newline.js +9 -2
- package/lib/rules/object-curly-spacing.js +20 -20
- package/lib/rules/object-shorthand.js +47 -35
- package/lib/rules/operator-assignment.js +9 -9
- package/lib/rules/operator-linebreak.js +15 -11
- package/lib/rules/padding-line-between-statements.js +6 -4
- package/lib/rules/prefer-arrow-callback.js +12 -10
- package/lib/rules/prefer-const.js +18 -10
- package/lib/rules/prefer-destructuring.js +4 -2
- package/lib/rules/prefer-numeric-literals.js +4 -2
- package/lib/rules/prefer-promise-reject-errors.js +16 -16
- package/lib/rules/prefer-rest-params.js +4 -2
- package/lib/rules/prefer-spread.js +1 -25
- package/lib/rules/prefer-template.js +33 -29
- package/lib/rules/quote-props.js +8 -8
- package/lib/rules/require-jsdoc.js +11 -18
- package/lib/rules/semi-style.js +44 -19
- package/lib/rules/semi.js +5 -3
- package/lib/rules/sort-imports.js +11 -6
- package/lib/rules/space-unary-ops.js +67 -69
- package/lib/rules/strict.js +8 -8
- package/lib/rules/valid-jsdoc.js +39 -33
- package/lib/rules/valid-typeof.js +4 -4
- package/lib/rules/wrap-iife.js +4 -4
- package/lib/rules/yoda.js +9 -7
- package/lib/testers/rule-tester.js +63 -40
- package/lib/token-store/backward-token-cursor.js +5 -3
- package/lib/token-store/forward-token-cursor.js +5 -3
- package/lib/token-store/utils.js +8 -4
- package/lib/util/apply-disable-directives.js +56 -27
- package/lib/util/glob.js +1 -1
- package/lib/util/naming.js +112 -0
- package/lib/util/node-event-generator.js +13 -27
- package/lib/util/safe-emitter.js +54 -0
- package/lib/util/source-code-fixer.js +4 -2
- package/lib/util/source-code.js +70 -65
- package/messages/no-config-found.txt +1 -1
- package/package.json +8 -8
- package/lib/internal-rules/.eslintrc.yml +0 -3
- package/lib/internal-rules/internal-consistent-docs-description.js +0 -130
- package/lib/internal-rules/internal-no-invalid-meta.js +0 -188
package/lib/logging.js
CHANGED
@@ -15,7 +15,7 @@ module.exports = {
|
|
15
15
|
* @returns {void}
|
16
16
|
*/
|
17
17
|
info() {
|
18
|
-
console.log.apply(console,
|
18
|
+
console.log.apply(console, arguments);
|
19
19
|
},
|
20
20
|
|
21
21
|
/**
|
@@ -23,6 +23,6 @@ module.exports = {
|
|
23
23
|
* @returns {void}
|
24
24
|
*/
|
25
25
|
error() {
|
26
|
-
console.error.apply(console,
|
26
|
+
console.error.apply(console, arguments);
|
27
27
|
}
|
28
28
|
};
|
package/lib/options.js
CHANGED
@@ -190,6 +190,12 @@ module.exports = optionator({
|
|
190
190
|
default: false,
|
191
191
|
description: "Automatically fix problems"
|
192
192
|
},
|
193
|
+
{
|
194
|
+
option: "fix-dry-run",
|
195
|
+
type: "Boolean",
|
196
|
+
default: false,
|
197
|
+
description: "Automatically fix problems without saving the changes to the file system"
|
198
|
+
},
|
193
199
|
{
|
194
200
|
option: "debug",
|
195
201
|
type: "Boolean",
|
@@ -214,6 +220,12 @@ module.exports = optionator({
|
|
214
220
|
default: "true",
|
215
221
|
description: "Prevent comments from changing config or rules"
|
216
222
|
},
|
223
|
+
{
|
224
|
+
option: "report-unused-disable-directives",
|
225
|
+
type: "Boolean",
|
226
|
+
default: false,
|
227
|
+
description: "Adds reported errors for unused eslint-disable directives"
|
228
|
+
},
|
217
229
|
{
|
218
230
|
option: "print-config",
|
219
231
|
type: "path::String",
|
package/lib/rules/.eslintrc.yml
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
rules:
|
2
|
-
|
3
|
-
|
2
|
+
rulesdir/no-invalid-meta: "error"
|
3
|
+
rulesdir/consistent-docs-description: "error"
|
@@ -23,7 +23,7 @@ module.exports = {
|
|
23
23
|
{
|
24
24
|
oneOf: [
|
25
25
|
{
|
26
|
-
enum: ["always", "never"]
|
26
|
+
enum: ["always", "never", "consistent"]
|
27
27
|
},
|
28
28
|
{
|
29
29
|
type: "object",
|
@@ -58,11 +58,15 @@ module.exports = {
|
|
58
58
|
* @returns {{multiline: boolean, minItems: number}} Normalized option object.
|
59
59
|
*/
|
60
60
|
function normalizeOptionValue(option) {
|
61
|
+
let consistent = false;
|
61
62
|
let multiline = false;
|
62
63
|
let minItems = 0;
|
63
64
|
|
64
65
|
if (option) {
|
65
|
-
if (option === "
|
66
|
+
if (option === "consistent") {
|
67
|
+
consistent = true;
|
68
|
+
minItems = Number.POSITIVE_INFINITY;
|
69
|
+
} else if (option === "always" || option.minItems === 0) {
|
66
70
|
minItems = 0;
|
67
71
|
} else if (option === "never") {
|
68
72
|
minItems = Number.POSITIVE_INFINITY;
|
@@ -71,11 +75,12 @@ module.exports = {
|
|
71
75
|
minItems = option.minItems || Number.POSITIVE_INFINITY;
|
72
76
|
}
|
73
77
|
} else {
|
78
|
+
consistent = false;
|
74
79
|
multiline = true;
|
75
80
|
minItems = Number.POSITIVE_INFINITY;
|
76
81
|
}
|
77
82
|
|
78
|
-
return { multiline, minItems };
|
83
|
+
return { consistent, multiline, minItems };
|
79
84
|
}
|
80
85
|
|
81
86
|
/**
|
@@ -91,11 +96,11 @@ module.exports = {
|
|
91
96
|
}
|
92
97
|
|
93
98
|
/**
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
+
* Reports that there shouldn't be a linebreak after the first token
|
100
|
+
* @param {ASTNode} node - The node to report in the event of an error.
|
101
|
+
* @param {Token} token - The token to use for the report.
|
102
|
+
* @returns {void}
|
103
|
+
*/
|
99
104
|
function reportNoBeginningLinebreak(node, token) {
|
100
105
|
context.report({
|
101
106
|
node,
|
@@ -114,11 +119,11 @@ module.exports = {
|
|
114
119
|
}
|
115
120
|
|
116
121
|
/**
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
+
* Reports that there shouldn't be a linebreak before the last token
|
123
|
+
* @param {ASTNode} node - The node to report in the event of an error.
|
124
|
+
* @param {Token} token - The token to use for the report.
|
125
|
+
* @returns {void}
|
126
|
+
*/
|
122
127
|
function reportNoEndingLinebreak(node, token) {
|
123
128
|
context.report({
|
124
129
|
node,
|
@@ -137,11 +142,11 @@ module.exports = {
|
|
137
142
|
}
|
138
143
|
|
139
144
|
/**
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
+
* Reports that there should be a linebreak after the first token
|
146
|
+
* @param {ASTNode} node - The node to report in the event of an error.
|
147
|
+
* @param {Token} token - The token to use for the report.
|
148
|
+
* @returns {void}
|
149
|
+
*/
|
145
150
|
function reportRequiredBeginningLinebreak(node, token) {
|
146
151
|
context.report({
|
147
152
|
node,
|
@@ -154,11 +159,11 @@ module.exports = {
|
|
154
159
|
}
|
155
160
|
|
156
161
|
/**
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
+
* Reports that there should be a linebreak before the last token
|
163
|
+
* @param {ASTNode} node - The node to report in the event of an error.
|
164
|
+
* @param {Token} token - The token to use for the report.
|
165
|
+
* @returns {void}
|
166
|
+
*/
|
162
167
|
function reportRequiredEndingLinebreak(node, token) {
|
163
168
|
context.report({
|
164
169
|
node,
|
@@ -173,8 +178,7 @@ module.exports = {
|
|
173
178
|
/**
|
174
179
|
* Reports a given node if it violated this rule.
|
175
180
|
*
|
176
|
-
* @param {ASTNode} node - A node to check. This is an
|
177
|
-
* @param {{multiline: boolean, minItems: number}} options - An option object.
|
181
|
+
* @param {ASTNode} node - A node to check. This is an ArrayExpression node or an ArrayPattern node.
|
178
182
|
* @returns {void}
|
179
183
|
*/
|
180
184
|
function check(node) {
|
@@ -194,6 +198,16 @@ module.exports = {
|
|
194
198
|
options.multiline &&
|
195
199
|
elements.length > 0 &&
|
196
200
|
firstIncComment.loc.start.line !== lastIncComment.loc.end.line
|
201
|
+
) ||
|
202
|
+
(
|
203
|
+
elements.length === 0 &&
|
204
|
+
firstIncComment.type === "Block" &&
|
205
|
+
firstIncComment.loc.start.line !== lastIncComment.loc.end.line &&
|
206
|
+
firstIncComment === lastIncComment
|
207
|
+
) ||
|
208
|
+
(
|
209
|
+
options.consistent &&
|
210
|
+
firstIncComment.loc.start.line !== openBracket.loc.end.line
|
197
211
|
)
|
198
212
|
);
|
199
213
|
|
@@ -66,11 +66,11 @@ module.exports = {
|
|
66
66
|
//--------------------------------------------------------------------------
|
67
67
|
|
68
68
|
/**
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
69
|
+
* Reports that there shouldn't be a space after the first token
|
70
|
+
* @param {ASTNode} node - The node to report in the event of an error.
|
71
|
+
* @param {Token} token - The token to use for the report.
|
72
|
+
* @returns {void}
|
73
|
+
*/
|
74
74
|
function reportNoBeginningSpace(node, token) {
|
75
75
|
context.report({
|
76
76
|
node,
|
@@ -88,11 +88,11 @@ module.exports = {
|
|
88
88
|
}
|
89
89
|
|
90
90
|
/**
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
91
|
+
* Reports that there shouldn't be a space before the last token
|
92
|
+
* @param {ASTNode} node - The node to report in the event of an error.
|
93
|
+
* @param {Token} token - The token to use for the report.
|
94
|
+
* @returns {void}
|
95
|
+
*/
|
96
96
|
function reportNoEndingSpace(node, token) {
|
97
97
|
context.report({
|
98
98
|
node,
|
@@ -110,11 +110,11 @@ module.exports = {
|
|
110
110
|
}
|
111
111
|
|
112
112
|
/**
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
113
|
+
* Reports that there should be a space after the first token
|
114
|
+
* @param {ASTNode} node - The node to report in the event of an error.
|
115
|
+
* @param {Token} token - The token to use for the report.
|
116
|
+
* @returns {void}
|
117
|
+
*/
|
118
118
|
function reportRequiredBeginningSpace(node, token) {
|
119
119
|
context.report({
|
120
120
|
node,
|
@@ -130,11 +130,11 @@ module.exports = {
|
|
130
130
|
}
|
131
131
|
|
132
132
|
/**
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
133
|
+
* Reports that there should be a space before the last token
|
134
|
+
* @param {ASTNode} node - The node to report in the event of an error.
|
135
|
+
* @param {Token} token - The token to use for the report.
|
136
|
+
* @returns {void}
|
137
|
+
*/
|
138
138
|
function reportRequiredEndingSpace(node, token) {
|
139
139
|
context.report({
|
140
140
|
node,
|
@@ -150,19 +150,19 @@ module.exports = {
|
|
150
150
|
}
|
151
151
|
|
152
152
|
/**
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
153
|
+
* Determines if a node is an object type
|
154
|
+
* @param {ASTNode} node - The node to check.
|
155
|
+
* @returns {boolean} Whether or not the node is an object type.
|
156
|
+
*/
|
157
157
|
function isObjectType(node) {
|
158
158
|
return node && (node.type === "ObjectExpression" || node.type === "ObjectPattern");
|
159
159
|
}
|
160
160
|
|
161
161
|
/**
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
162
|
+
* Determines if a node is an array type
|
163
|
+
* @param {ASTNode} node - The node to check.
|
164
|
+
* @returns {boolean} Whether or not the node is an array type.
|
165
|
+
*/
|
166
166
|
function isArrayType(node) {
|
167
167
|
return node && (node.type === "ArrayExpression" || node.type === "ArrayPattern");
|
168
168
|
}
|
@@ -85,12 +85,14 @@ function isCallbackOfArrayMethod(node) {
|
|
85
85
|
node = parent;
|
86
86
|
break;
|
87
87
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
88
|
+
/*
|
89
|
+
* If the upper function is IIFE, checks the destination of the return value.
|
90
|
+
* e.g.
|
91
|
+
* foo.every((function() {
|
92
|
+
* // setup...
|
93
|
+
* return function callback() { ... };
|
94
|
+
* })());
|
95
|
+
*/
|
94
96
|
case "ReturnStatement": {
|
95
97
|
const func = astUtils.getUpperFunction(parent);
|
96
98
|
|
@@ -101,9 +103,11 @@ function isCallbackOfArrayMethod(node) {
|
|
101
103
|
break;
|
102
104
|
}
|
103
105
|
|
104
|
-
|
105
|
-
|
106
|
-
|
106
|
+
/*
|
107
|
+
* e.g.
|
108
|
+
* Array.from([], function() {});
|
109
|
+
* list.every(function() {});
|
110
|
+
*/
|
107
111
|
case "CallExpression":
|
108
112
|
if (astUtils.isArrayFromMethod(parent.callee)) {
|
109
113
|
return (
|
@@ -87,10 +87,10 @@ module.exports = {
|
|
87
87
|
}
|
88
88
|
|
89
89
|
/**
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
90
|
+
* Reports that there shouldn't be a line break after the first token
|
91
|
+
* @param {Token} token - The token to use for the report.
|
92
|
+
* @returns {void}
|
93
|
+
*/
|
94
94
|
function reportNoLineBreak(token) {
|
95
95
|
const tokenBefore = sourceCode.getTokenBefore(token, { includeComments: true });
|
96
96
|
|
@@ -136,10 +136,10 @@ module.exports = {
|
|
136
136
|
}
|
137
137
|
|
138
138
|
/**
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
139
|
+
* Reports that there should be a line break after the first token
|
140
|
+
* @param {Token} token - The token to use for the report.
|
141
|
+
* @returns {void}
|
142
|
+
*/
|
143
143
|
function reportRequiredLineBreak(token) {
|
144
144
|
const tokenBefore = sourceCode.getTokenBefore(token, { includeComments: true });
|
145
145
|
|
@@ -132,8 +132,10 @@ module.exports = {
|
|
132
132
|
sourceCode.commentsExistBetween(openingBrace, firstValueToken) ||
|
133
133
|
sourceCode.commentsExistBetween(lastValueToken, closingBrace);
|
134
134
|
|
135
|
-
|
136
|
-
|
135
|
+
/*
|
136
|
+
* Remove tokens around the return value.
|
137
|
+
* If comments don't exist, remove extra spaces as well.
|
138
|
+
*/
|
137
139
|
if (commentsExist) {
|
138
140
|
fixes.push(
|
139
141
|
fixer.remove(openingBrace),
|
@@ -147,8 +149,10 @@ module.exports = {
|
|
147
149
|
);
|
148
150
|
}
|
149
151
|
|
150
|
-
|
151
|
-
|
152
|
+
/*
|
153
|
+
* If the first token of the reutrn value is `{`,
|
154
|
+
* enclose the return value by parentheses to avoid syntax error.
|
155
|
+
*/
|
152
156
|
if (astUtils.isOpeningBraceToken(firstValueToken)) {
|
153
157
|
fixes.push(
|
154
158
|
fixer.insertTextBefore(firstValueToken, "("),
|
@@ -156,8 +160,10 @@ module.exports = {
|
|
156
160
|
);
|
157
161
|
}
|
158
162
|
|
159
|
-
|
160
|
-
|
163
|
+
/*
|
164
|
+
* If the last token of the return statement is semicolon, remove it.
|
165
|
+
* Non-block arrow body is an expression, not a statement.
|
166
|
+
*/
|
161
167
|
if (astUtils.isSemicolonToken(lastValueToken)) {
|
162
168
|
fixes.push(fixer.remove(lastValueToken));
|
163
169
|
}
|
@@ -67,8 +67,10 @@ module.exports = {
|
|
67
67
|
function fixParamsWithParenthesis(fixer) {
|
68
68
|
const paramToken = sourceCode.getTokenAfter(firstTokenOfParam);
|
69
69
|
|
70
|
-
|
71
|
-
|
70
|
+
/*
|
71
|
+
* ES8 allows Trailing commas in function parameter lists and calls
|
72
|
+
* https://github.com/eslint/eslint/issues/8834
|
73
|
+
*/
|
72
74
|
const closingParenToken = sourceCode.getTokenAfter(paramToken, astUtils.isClosingParenToken);
|
73
75
|
const asyncToken = isAsync ? sourceCode.getTokenBefore(firstTokenOfParam) : null;
|
74
76
|
const shouldAddSpaceForAsync = asyncToken && (asyncToken.range[1] === firstTokenOfParam.range[0]);
|
@@ -14,7 +14,7 @@ const util = require("../ast-utils");
|
|
14
14
|
module.exports = {
|
15
15
|
meta: {
|
16
16
|
docs: {
|
17
|
-
description: "enforce
|
17
|
+
description: "disallow or enforce spaces inside of blocks after opening block and before closing block",
|
18
18
|
category: "Stylistic Issues",
|
19
19
|
recommended: false
|
20
20
|
},
|
package/lib/rules/brace-style.js
CHANGED
@@ -54,11 +54,11 @@ module.exports = {
|
|
54
54
|
//--------------------------------------------------------------------------
|
55
55
|
|
56
56
|
/**
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
57
|
+
* Fixes a place where a newline unexpectedly appears
|
58
|
+
* @param {Token} firstToken The token before the unexpected newline
|
59
|
+
* @param {Token} secondToken The token after the unexpected newline
|
60
|
+
* @returns {Function} A fixer function to remove the newlines between the tokens
|
61
|
+
*/
|
62
62
|
function removeNewlineBetween(firstToken, secondToken) {
|
63
63
|
const textRange = [firstToken.range[1], secondToken.range[0]];
|
64
64
|
const textBetween = sourceCode.text.slice(textRange[0], textRange[1]);
|
@@ -71,11 +71,11 @@ module.exports = {
|
|
71
71
|
}
|
72
72
|
|
73
73
|
/**
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
74
|
+
* Validates a pair of curly brackets based on the user's config
|
75
|
+
* @param {Token} openingCurly The opening curly bracket
|
76
|
+
* @param {Token} closingCurly The closing curly bracket
|
77
|
+
* @returns {void}
|
78
|
+
*/
|
79
79
|
function validateCurlyPair(openingCurly, closingCurly) {
|
80
80
|
const tokenBeforeOpeningCurly = sourceCode.getTokenBefore(openingCurly);
|
81
81
|
const tokenAfterOpeningCurly = sourceCode.getTokenAfter(openingCurly);
|
@@ -116,10 +116,10 @@ module.exports = {
|
|
116
116
|
}
|
117
117
|
|
118
118
|
/**
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
119
|
+
* Validates the location of a token that appears before a keyword (e.g. a newline before `else`)
|
120
|
+
* @param {Token} curlyToken The closing curly token. This is assumed to precede a keyword token (such as `else` or `finally`).
|
121
|
+
* @returns {void}
|
122
|
+
*/
|
123
123
|
function validateCurlyBeforeKeyword(curlyToken) {
|
124
124
|
const keywordToken = sourceCode.getTokenAfter(curlyToken);
|
125
125
|
|
@@ -60,7 +60,8 @@ module.exports = {
|
|
60
60
|
if (node.type === "MemberExpression") {
|
61
61
|
if (node.object.type === "Identifier") {
|
62
62
|
return true;
|
63
|
-
}
|
63
|
+
}
|
64
|
+
if (node.object.type === "MemberExpression") {
|
64
65
|
return containsOnlyIdentifiers(node.object);
|
65
66
|
}
|
66
67
|
}
|
package/lib/rules/comma-style.js
CHANGED
@@ -208,7 +208,9 @@ module.exports = {
|
|
208
208
|
if (item) {
|
209
209
|
const tokenAfterItem = sourceCode.getTokenAfter(item, astUtils.isNotClosingParenToken);
|
210
210
|
|
211
|
-
previousItemToken = tokenAfterItem
|
211
|
+
previousItemToken = tokenAfterItem
|
212
|
+
? sourceCode.getTokenBefore(tokenAfterItem)
|
213
|
+
: sourceCode.ast.tokens[sourceCode.ast.tokens.length - 1];
|
212
214
|
}
|
213
215
|
});
|
214
216
|
|
@@ -36,12 +36,12 @@ module.exports = {
|
|
36
36
|
//--------------------------------------------------------------------------
|
37
37
|
|
38
38
|
/**
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
39
|
+
* Reports that there shouldn't be a space after the first token
|
40
|
+
* @param {ASTNode} node - The node to report in the event of an error.
|
41
|
+
* @param {Token} token - The token to use for the report.
|
42
|
+
* @param {Token} tokenAfter - The token after `token`.
|
43
|
+
* @returns {void}
|
44
|
+
*/
|
45
45
|
function reportNoBeginningSpace(node, token, tokenAfter) {
|
46
46
|
context.report({
|
47
47
|
node,
|
@@ -57,12 +57,12 @@ module.exports = {
|
|
57
57
|
}
|
58
58
|
|
59
59
|
/**
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
60
|
+
* Reports that there shouldn't be a space before the last token
|
61
|
+
* @param {ASTNode} node - The node to report in the event of an error.
|
62
|
+
* @param {Token} token - The token to use for the report.
|
63
|
+
* @param {Token} tokenBefore - The token before `token`.
|
64
|
+
* @returns {void}
|
65
|
+
*/
|
66
66
|
function reportNoEndingSpace(node, token, tokenBefore) {
|
67
67
|
context.report({
|
68
68
|
node,
|
@@ -78,11 +78,11 @@ module.exports = {
|
|
78
78
|
}
|
79
79
|
|
80
80
|
/**
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
81
|
+
* Reports that there should be a space after the first token
|
82
|
+
* @param {ASTNode} node - The node to report in the event of an error.
|
83
|
+
* @param {Token} token - The token to use for the report.
|
84
|
+
* @returns {void}
|
85
|
+
*/
|
86
86
|
function reportRequiredBeginningSpace(node, token) {
|
87
87
|
context.report({
|
88
88
|
node,
|
@@ -98,11 +98,11 @@ module.exports = {
|
|
98
98
|
}
|
99
99
|
|
100
100
|
/**
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
101
|
+
* Reports that there should be a space before the last token
|
102
|
+
* @param {ASTNode} node - The node to report in the event of an error.
|
103
|
+
* @param {Token} token - The token to use for the report.
|
104
|
+
* @returns {void}
|
105
|
+
*/
|
106
106
|
function reportRequiredEndingSpace(node, token) {
|
107
107
|
context.report({
|
108
108
|
node,
|
@@ -36,10 +36,10 @@ function isUnreachable(segment) {
|
|
36
36
|
}
|
37
37
|
|
38
38
|
/**
|
39
|
-
* Checks whether a given node is a `constructor` method in an ES6 class
|
40
|
-
* @param {ASTNode} node A node to check
|
41
|
-
* @returns {boolean} `true` if the node is a `constructor` method
|
42
|
-
*/
|
39
|
+
* Checks whether a given node is a `constructor` method in an ES6 class
|
40
|
+
* @param {ASTNode} node A node to check
|
41
|
+
* @returns {boolean} `true` if the node is a `constructor` method
|
42
|
+
*/
|
43
43
|
function isClassConstructor(node) {
|
44
44
|
return node.type === "FunctionExpression" &&
|
45
45
|
node.parent &&
|
@@ -86,8 +86,10 @@ module.exports = {
|
|
86
86
|
return;
|
87
87
|
}
|
88
88
|
|
89
|
-
|
90
|
-
|
89
|
+
/*
|
90
|
+
* The alias has been declared and not assigned: check it was
|
91
|
+
* assigned later in the same scope.
|
92
|
+
*/
|
91
93
|
if (!variable.references.some(reference => {
|
92
94
|
const write = reference.writeExpr;
|
93
95
|
|
package/lib/rules/curly.js
CHANGED
@@ -164,10 +164,10 @@ module.exports = {
|
|
164
164
|
}
|
165
165
|
|
166
166
|
/**
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
167
|
+
* Determines if a semicolon needs to be inserted after removing a set of curly brackets, in order to avoid a SyntaxError.
|
168
|
+
* @param {Token} closingBracket The } token
|
169
|
+
* @returns {boolean} `true` if a semicolon needs to be inserted after the last statement in the block.
|
170
|
+
*/
|
171
171
|
function needsSemicolon(closingBracket) {
|
172
172
|
const tokenBefore = sourceCode.getTokenBefore(closingBracket);
|
173
173
|
const tokenAfter = sourceCode.getTokenAfter(closingBracket);
|
@@ -187,9 +187,11 @@ module.exports = {
|
|
187
187
|
|
188
188
|
if (lastBlockNode.type === "BlockStatement" && lastBlockNode.parent.type !== "FunctionExpression" && lastBlockNode.parent.type !== "ArrowFunctionExpression") {
|
189
189
|
|
190
|
-
|
191
|
-
|
192
|
-
|
190
|
+
/*
|
191
|
+
* If the last node surrounded by curly brackets is a BlockStatement (other than a FunctionExpression or an ArrowFunctionExpression),
|
192
|
+
* don't insert a semicolon. Otherwise, the semicolon would be parsed as a separate statement, which would cause
|
193
|
+
* a SyntaxError if it was followed by `else`.
|
194
|
+
*/
|
193
195
|
return false;
|
194
196
|
}
|
195
197
|
|
@@ -235,8 +237,10 @@ module.exports = {
|
|
235
237
|
},
|
236
238
|
fix(fixer) {
|
237
239
|
|
238
|
-
|
239
|
-
|
240
|
+
/*
|
241
|
+
* `do while` expressions sometimes need a space to be inserted after `do`.
|
242
|
+
* e.g. `do{foo()} while (bar)` should be corrected to `do foo() while (bar)`
|
243
|
+
*/
|
240
244
|
const needsPrecedingSpace = node.type === "DoWhileStatement" &&
|
241
245
|
sourceCode.getTokenBefore(bodyNode).range[1] === bodyNode.range[0] &&
|
242
246
|
!astUtils.canTokensBeAdjacent("do", sourceCode.getFirstToken(bodyNode, { skip: 1 }));
|