eslint 6.3.0 → 6.4.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 +33 -0
- package/README.md +2 -2
- package/lib/cli-engine/config-array/override-tester.js +2 -2
- package/lib/rules/accessor-pairs.js +51 -11
- package/lib/rules/computed-property-spacing.js +18 -1
- package/lib/rules/default-param-last.js +61 -0
- package/lib/rules/eqeqeq.js +7 -19
- package/lib/rules/indent.js +16 -6
- package/lib/rules/index.js +3 -0
- package/lib/rules/no-extra-boolean-cast.js +1 -1
- package/lib/rules/no-import-assign.js +238 -0
- package/lib/rules/no-lone-blocks.js +6 -1
- package/lib/rules/no-obj-calls.js +29 -9
- package/lib/rules/no-octal-escape.js +14 -8
- package/lib/rules/no-self-assign.js +6 -5
- package/lib/rules/no-sequences.js +2 -2
- package/lib/rules/no-unsafe-negation.js +2 -10
- package/lib/rules/object-curly-spacing.js +1 -1
- package/lib/rules/object-shorthand.js +35 -9
- package/lib/rules/prefer-regex-literals.js +125 -0
- package/lib/rules/quotes.js +6 -0
- package/lib/rules/space-before-function-paren.js +12 -1
- package/lib/rules/space-in-parens.js +77 -71
- package/package.json +1 -1
@@ -40,23 +40,28 @@ module.exports = {
|
|
40
40
|
},
|
41
41
|
additionalProperties: false
|
42
42
|
}
|
43
|
-
]
|
43
|
+
],
|
44
|
+
|
45
|
+
messages: {
|
46
|
+
missingOpeningSpace: "There must be a space after this paren.",
|
47
|
+
missingClosingSpace: "There must be a space before this paren.",
|
48
|
+
rejectedOpeningSpace: "There should be no space after this paren.",
|
49
|
+
rejectedClosingSpace: "There should be no space before this paren."
|
50
|
+
}
|
44
51
|
},
|
45
52
|
|
46
53
|
create(context) {
|
47
|
-
|
48
|
-
const MISSING_SPACE_MESSAGE = "There must be a space inside this paren.",
|
49
|
-
REJECTED_SPACE_MESSAGE = "There should be no spaces inside this paren.",
|
50
|
-
ALWAYS = context.options[0] === "always",
|
54
|
+
const ALWAYS = context.options[0] === "always",
|
51
55
|
exceptionsArrayOptions = (context.options[1] && context.options[1].exceptions) || [],
|
52
56
|
options = {};
|
57
|
+
|
53
58
|
let exceptions;
|
54
59
|
|
55
60
|
if (exceptionsArrayOptions.length) {
|
56
|
-
options.braceException = exceptionsArrayOptions.
|
57
|
-
options.bracketException = exceptionsArrayOptions.
|
58
|
-
options.parenException = exceptionsArrayOptions.
|
59
|
-
options.empty = exceptionsArrayOptions.
|
61
|
+
options.braceException = exceptionsArrayOptions.includes("{}");
|
62
|
+
options.bracketException = exceptionsArrayOptions.includes("[]");
|
63
|
+
options.parenException = exceptionsArrayOptions.includes("()");
|
64
|
+
options.empty = exceptionsArrayOptions.includes("empty");
|
60
65
|
}
|
61
66
|
|
62
67
|
/**
|
@@ -105,7 +110,7 @@ module.exports = {
|
|
105
110
|
* @returns {boolean} True if the token is one of the exceptions for the opener paren
|
106
111
|
*/
|
107
112
|
function isOpenerException(token) {
|
108
|
-
return
|
113
|
+
return exceptions.openers.includes(token.value);
|
109
114
|
}
|
110
115
|
|
111
116
|
/**
|
@@ -114,102 +119,95 @@ module.exports = {
|
|
114
119
|
* @returns {boolean} True if the token is one of the exceptions for the closer paren
|
115
120
|
*/
|
116
121
|
function isCloserException(token) {
|
117
|
-
return
|
122
|
+
return exceptions.closers.includes(token.value);
|
118
123
|
}
|
119
124
|
|
120
125
|
/**
|
121
|
-
* Determines if an
|
122
|
-
* @param {Object}
|
123
|
-
* @param {Object}
|
124
|
-
* @returns {boolean} True if the paren
|
126
|
+
* Determines if an opening paren is immediately followed by a required space
|
127
|
+
* @param {Object} openingParenToken The paren token
|
128
|
+
* @param {Object} tokenAfterOpeningParen The token after it
|
129
|
+
* @returns {boolean} True if the opening paren is missing a required space
|
125
130
|
*/
|
126
|
-
function
|
127
|
-
if (sourceCode.isSpaceBetweenTokens(
|
131
|
+
function openerMissingSpace(openingParenToken, tokenAfterOpeningParen) {
|
132
|
+
if (sourceCode.isSpaceBetweenTokens(openingParenToken, tokenAfterOpeningParen)) {
|
128
133
|
return false;
|
129
134
|
}
|
130
135
|
|
131
|
-
if (
|
132
|
-
|
133
|
-
return false;
|
134
|
-
}
|
135
|
-
return !isOpenerException(right);
|
136
|
+
if (!options.empty && astUtils.isClosingParenToken(tokenAfterOpeningParen)) {
|
137
|
+
return false;
|
136
138
|
}
|
137
|
-
return isOpenerException(right);
|
138
139
|
|
140
|
+
if (ALWAYS) {
|
141
|
+
return !isOpenerException(tokenAfterOpeningParen);
|
142
|
+
}
|
143
|
+
return isOpenerException(tokenAfterOpeningParen);
|
139
144
|
}
|
140
145
|
|
141
146
|
/**
|
142
|
-
* Determines if an
|
143
|
-
* @param {Object}
|
144
|
-
* @param {Object}
|
145
|
-
* @returns {boolean} True if the paren
|
147
|
+
* Determines if an opening paren is immediately followed by a disallowed space
|
148
|
+
* @param {Object} openingParenToken The paren token
|
149
|
+
* @param {Object} tokenAfterOpeningParen The token after it
|
150
|
+
* @returns {boolean} True if the opening paren has a disallowed space
|
146
151
|
*/
|
147
|
-
function
|
148
|
-
if (astUtils.
|
152
|
+
function openerRejectsSpace(openingParenToken, tokenAfterOpeningParen) {
|
153
|
+
if (!astUtils.isTokenOnSameLine(openingParenToken, tokenAfterOpeningParen)) {
|
149
154
|
return false;
|
150
155
|
}
|
151
156
|
|
152
|
-
if (
|
157
|
+
if (tokenAfterOpeningParen.type === "Line") {
|
153
158
|
return false;
|
154
159
|
}
|
155
160
|
|
156
|
-
if (
|
157
|
-
return
|
161
|
+
if (!sourceCode.isSpaceBetweenTokens(openingParenToken, tokenAfterOpeningParen)) {
|
162
|
+
return false;
|
158
163
|
}
|
159
|
-
return isCloserException(left);
|
160
164
|
|
165
|
+
if (ALWAYS) {
|
166
|
+
return isOpenerException(tokenAfterOpeningParen);
|
167
|
+
}
|
168
|
+
return !isOpenerException(tokenAfterOpeningParen);
|
161
169
|
}
|
162
170
|
|
163
171
|
/**
|
164
|
-
* Determines if
|
165
|
-
* @param {Object}
|
166
|
-
* @param {Object}
|
167
|
-
* @returns {boolean} True if the paren
|
172
|
+
* Determines if a closing paren is immediately preceeded by a required space
|
173
|
+
* @param {Object} tokenBeforeClosingParen The token before the paren
|
174
|
+
* @param {Object} closingParenToken The paren token
|
175
|
+
* @returns {boolean} True if the closing paren is missing a required space
|
168
176
|
*/
|
169
|
-
function
|
170
|
-
if (
|
171
|
-
return false;
|
172
|
-
}
|
173
|
-
|
174
|
-
if (!astUtils.isTokenOnSameLine(left, right)) {
|
177
|
+
function closerMissingSpace(tokenBeforeClosingParen, closingParenToken) {
|
178
|
+
if (sourceCode.isSpaceBetweenTokens(tokenBeforeClosingParen, closingParenToken)) {
|
175
179
|
return false;
|
176
180
|
}
|
177
181
|
|
178
|
-
if (!
|
182
|
+
if (!options.empty && astUtils.isOpeningParenToken(tokenBeforeClosingParen)) {
|
179
183
|
return false;
|
180
184
|
}
|
181
185
|
|
182
186
|
if (ALWAYS) {
|
183
|
-
return
|
187
|
+
return !isCloserException(tokenBeforeClosingParen);
|
184
188
|
}
|
185
|
-
return
|
186
|
-
|
189
|
+
return isCloserException(tokenBeforeClosingParen);
|
187
190
|
}
|
188
191
|
|
189
192
|
/**
|
190
|
-
* Determines if
|
191
|
-
* @param {Object}
|
192
|
-
* @param {Object}
|
193
|
-
* @returns {boolean} True if the paren
|
193
|
+
* Determines if a closer paren is immediately preceeded by a disallowed space
|
194
|
+
* @param {Object} tokenBeforeClosingParen The token before the paren
|
195
|
+
* @param {Object} closingParenToken The paren token
|
196
|
+
* @returns {boolean} True if the closing paren has a disallowed space
|
194
197
|
*/
|
195
|
-
function
|
196
|
-
if (astUtils.
|
198
|
+
function closerRejectsSpace(tokenBeforeClosingParen, closingParenToken) {
|
199
|
+
if (!astUtils.isTokenOnSameLine(tokenBeforeClosingParen, closingParenToken)) {
|
197
200
|
return false;
|
198
201
|
}
|
199
202
|
|
200
|
-
if (!
|
201
|
-
return false;
|
202
|
-
}
|
203
|
-
|
204
|
-
if (!sourceCode.isSpaceBetweenTokens(left, right)) {
|
203
|
+
if (!sourceCode.isSpaceBetweenTokens(tokenBeforeClosingParen, closingParenToken)) {
|
205
204
|
return false;
|
206
205
|
}
|
207
206
|
|
208
207
|
if (ALWAYS) {
|
209
|
-
return isCloserException(
|
208
|
+
return isCloserException(tokenBeforeClosingParen);
|
210
209
|
}
|
211
|
-
return !isCloserException(
|
212
|
-
|
210
|
+
return !isCloserException(tokenBeforeClosingParen);
|
213
211
|
}
|
214
212
|
|
215
213
|
//--------------------------------------------------------------------------
|
@@ -225,44 +223,53 @@ module.exports = {
|
|
225
223
|
const prevToken = tokens[i - 1];
|
226
224
|
const nextToken = tokens[i + 1];
|
227
225
|
|
226
|
+
// if token is not an opening or closing paren token, do nothing
|
228
227
|
if (!astUtils.isOpeningParenToken(token) && !astUtils.isClosingParenToken(token)) {
|
229
228
|
return;
|
230
229
|
}
|
231
230
|
|
232
|
-
if
|
231
|
+
// if token is an opening paren and is not followed by a required space
|
232
|
+
if (token.value === "(" && openerMissingSpace(token, nextToken)) {
|
233
233
|
context.report({
|
234
234
|
node,
|
235
235
|
loc: token.loc.start,
|
236
|
-
|
236
|
+
messageId: "missingOpeningSpace",
|
237
237
|
fix(fixer) {
|
238
238
|
return fixer.insertTextAfter(token, " ");
|
239
239
|
}
|
240
240
|
});
|
241
|
-
}
|
241
|
+
}
|
242
|
+
|
243
|
+
// if token is an opening paren and is followed by a disallowed space
|
244
|
+
if (token.value === "(" && openerRejectsSpace(token, nextToken)) {
|
242
245
|
context.report({
|
243
246
|
node,
|
244
247
|
loc: token.loc.start,
|
245
|
-
|
248
|
+
messageId: "rejectedOpeningSpace",
|
246
249
|
fix(fixer) {
|
247
250
|
return fixer.removeRange([token.range[1], nextToken.range[0]]);
|
248
251
|
}
|
249
252
|
});
|
250
|
-
}
|
253
|
+
}
|
251
254
|
|
252
|
-
|
255
|
+
// if token is a closing paren and is not preceded by a required space
|
256
|
+
if (token.value === ")" && closerMissingSpace(prevToken, token)) {
|
253
257
|
context.report({
|
254
258
|
node,
|
255
259
|
loc: token.loc.start,
|
256
|
-
|
260
|
+
messageId: "missingClosingSpace",
|
257
261
|
fix(fixer) {
|
258
262
|
return fixer.insertTextBefore(token, " ");
|
259
263
|
}
|
260
264
|
});
|
261
|
-
}
|
265
|
+
}
|
266
|
+
|
267
|
+
// if token is a closing paren and is preceded by a disallowed space
|
268
|
+
if (token.value === ")" && closerRejectsSpace(prevToken, token)) {
|
262
269
|
context.report({
|
263
270
|
node,
|
264
271
|
loc: token.loc.start,
|
265
|
-
|
272
|
+
messageId: "rejectedClosingSpace",
|
266
273
|
fix(fixer) {
|
267
274
|
return fixer.removeRange([prevToken.range[1], token.range[0]]);
|
268
275
|
}
|
@@ -271,6 +278,5 @@ module.exports = {
|
|
271
278
|
});
|
272
279
|
}
|
273
280
|
};
|
274
|
-
|
275
281
|
}
|
276
282
|
};
|