eslint 5.14.1 → 5.15.3
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 +51 -0
- package/README.md +2 -2
- package/lib/built-in-rules-index.js +1 -0
- package/lib/cli-engine.js +2 -2
- package/lib/config/config-file.js +3 -3
- package/lib/config/config-initializer.js +1 -1
- package/lib/config/config-validator.js +13 -13
- package/lib/config/plugins.js +1 -1
- package/lib/formatters/codeframe.js +1 -1
- package/lib/formatters/stylish.js +2 -2
- package/lib/linter.js +23 -8
- package/lib/rules/array-bracket-newline.js +2 -4
- package/lib/rules/array-callback-return.js +2 -2
- package/lib/rules/array-element-newline.js +2 -4
- package/lib/rules/arrow-body-style.js +2 -2
- package/lib/rules/camelcase.js +2 -2
- package/lib/rules/capitalized-comments.js +12 -17
- package/lib/rules/complexity.js +6 -5
- package/lib/rules/curly.js +1 -1
- package/lib/rules/default-case.js +2 -2
- package/lib/rules/dot-notation.js +2 -2
- package/lib/rules/eol-last.js +1 -1
- package/lib/rules/eqeqeq.js +1 -2
- package/lib/rules/func-call-spacing.js +3 -4
- package/lib/rules/getter-return.js +1 -1
- package/lib/rules/handle-callback-err.js +1 -1
- package/lib/rules/id-match.js +1 -1
- package/lib/rules/implicit-arrow-linebreak.js +17 -172
- package/lib/rules/indent-legacy.js +1 -1
- package/lib/rules/indent.js +2 -2
- package/lib/rules/init-declarations.js +1 -2
- package/lib/rules/jsx-quotes.js +2 -2
- package/lib/rules/key-spacing.js +28 -55
- package/lib/rules/keyword-spacing.js +7 -7
- package/lib/rules/line-comment-position.js +5 -7
- package/lib/rules/lines-around-comment.js +1 -1
- package/lib/rules/max-depth.js +6 -5
- package/lib/rules/max-len.js +4 -4
- package/lib/rules/max-lines-per-function.js +1 -1
- package/lib/rules/max-lines.js +4 -7
- package/lib/rules/max-nested-callbacks.js +6 -5
- package/lib/rules/max-params.js +6 -5
- package/lib/rules/max-statements-per-line.js +1 -1
- package/lib/rules/max-statements.js +6 -5
- package/lib/rules/multiline-comment-style.js +9 -9
- package/lib/rules/new-cap.js +2 -2
- package/lib/rules/no-alert.js +1 -1
- package/lib/rules/no-caller.js +1 -1
- package/lib/rules/no-dupe-keys.js +2 -2
- package/lib/rules/no-else-return.js +2 -2
- package/lib/rules/no-empty-character-class.js +1 -1
- package/lib/rules/no-extra-parens.js +11 -5
- package/lib/rules/no-fallthrough.js +2 -2
- package/lib/rules/no-implicit-coercion.js +1 -1
- package/lib/rules/no-implied-eval.js +1 -1
- package/lib/rules/no-invalid-regexp.js +2 -2
- package/lib/rules/no-irregular-whitespace.js +3 -3
- package/lib/rules/no-lonely-if.js +1 -1
- package/lib/rules/no-mixed-operators.js +1 -1
- package/lib/rules/no-mixed-requires.js +3 -5
- package/lib/rules/no-mixed-spaces-and-tabs.js +2 -2
- package/lib/rules/no-octal-escape.js +1 -1
- package/lib/rules/no-octal.js +1 -1
- package/lib/rules/no-param-reassign.js +1 -1
- package/lib/rules/no-path-concat.js +1 -1
- package/lib/rules/no-regex-spaces.js +1 -1
- package/lib/rules/no-return-assign.js +1 -1
- package/lib/rules/no-self-assign.js +1 -1
- package/lib/rules/no-tabs.js +2 -2
- package/lib/rules/no-template-curly-in-string.js +1 -1
- package/lib/rules/no-trailing-spaces.js +2 -2
- package/lib/rules/no-unexpected-multiline.js +1 -1
- package/lib/rules/no-unmodified-loop-condition.js +5 -5
- package/lib/rules/no-unsafe-finally.js +3 -3
- package/lib/rules/no-unused-expressions.js +2 -2
- package/lib/rules/no-unused-vars.js +10 -14
- package/lib/rules/no-use-before-define.js +5 -5
- package/lib/rules/no-useless-escape.js +1 -1
- package/lib/rules/no-var.js +1 -1
- package/lib/rules/no-warning-comments.js +6 -6
- package/lib/rules/object-curly-newline.js +4 -6
- package/lib/rules/object-shorthand.js +4 -8
- package/lib/rules/one-var.js +3 -6
- package/lib/rules/padding-line-between-statements.js +4 -3
- package/lib/rules/prefer-const.js +3 -3
- package/lib/rules/prefer-destructuring.js +7 -14
- package/lib/rules/prefer-named-capture-group.js +123 -0
- package/lib/rules/prefer-object-spread.js +1 -1
- package/lib/rules/prefer-template.js +3 -3
- package/lib/rules/quote-props.js +5 -10
- package/lib/rules/quotes.js +4 -6
- package/lib/rules/semi.js +7 -8
- package/lib/rules/space-before-function-paren.js +3 -6
- package/lib/rules/spaced-comment.js +4 -4
- package/lib/rules/template-curly-spacing.js +2 -2
- package/lib/rules/use-isnan.js +1 -1
- package/lib/rules/valid-jsdoc.js +2 -2
- package/lib/rules/vars-on-top.js +1 -1
- package/lib/rules/yield-star-spacing.js +2 -2
- package/lib/rules/yoda.js +2 -2
- package/lib/testers/rule-tester.js +1 -1
- package/lib/util/ast-utils.js +12 -12
- package/lib/util/config-comment-parser.js +4 -4
- package/lib/util/glob-utils.js +15 -4
- package/lib/util/ignored-paths.js +4 -4
- package/lib/util/interpolate.js +1 -1
- package/lib/util/naming.js +6 -6
- package/lib/util/node-event-generator.js +1 -1
- package/lib/util/path-utils.js +2 -2
- package/lib/util/patterns/letters.js +1 -1
- package/lib/util/source-code.js +2 -2
- package/lib/util/xml-escape.js +1 -1
- package/package.json +10 -9
package/lib/rules/id-match.js
CHANGED
@@ -53,7 +53,7 @@ module.exports = {
|
|
53
53
|
// Options
|
54
54
|
//--------------------------------------------------------------------------
|
55
55
|
const pattern = context.options[0] || "^.+$",
|
56
|
-
regexp = new RegExp(pattern);
|
56
|
+
regexp = new RegExp(pattern); // eslint-disable-line require-unicode-regexp
|
57
57
|
|
58
58
|
const options = context.options[1] || {},
|
59
59
|
properties = !!options.properties,
|
@@ -4,11 +4,7 @@
|
|
4
4
|
*/
|
5
5
|
"use strict";
|
6
6
|
|
7
|
-
const {
|
8
|
-
isArrowToken,
|
9
|
-
isParenthesised,
|
10
|
-
isOpeningParenToken
|
11
|
-
} = require("../util/ast-utils");
|
7
|
+
const { isCommentToken, isNotOpeningParenToken } = require("../util/ast-utils");
|
12
8
|
|
13
9
|
//------------------------------------------------------------------------------
|
14
10
|
// Rule Definition
|
@@ -39,153 +35,7 @@ module.exports = {
|
|
39
35
|
|
40
36
|
create(context) {
|
41
37
|
const sourceCode = context.getSourceCode();
|
42
|
-
|
43
|
-
//----------------------------------------------------------------------
|
44
|
-
// Helpers
|
45
|
-
//----------------------------------------------------------------------
|
46
|
-
/**
|
47
|
-
* Gets the applicable preference for a particular keyword
|
48
|
-
* @returns {string} The applicable option for the keyword, e.g. 'beside'
|
49
|
-
*/
|
50
|
-
function getOption() {
|
51
|
-
return context.options[0] || "beside";
|
52
|
-
}
|
53
|
-
|
54
|
-
/**
|
55
|
-
* Formats the comments depending on whether it's a line or block comment.
|
56
|
-
* @param {Comment[]} comments The array of comments between the arrow and body
|
57
|
-
* @param {Integer} column The column number of the first token
|
58
|
-
* @returns {string} A string of comment text joined by line breaks
|
59
|
-
*/
|
60
|
-
function formatComments(comments, column) {
|
61
|
-
const whiteSpaces = " ".repeat(column);
|
62
|
-
|
63
|
-
return `${comments.map(comment => {
|
64
|
-
|
65
|
-
if (comment.type === "Line") {
|
66
|
-
return `//${comment.value}`;
|
67
|
-
}
|
68
|
-
|
69
|
-
return `/*${comment.value}*/`;
|
70
|
-
}).join(`\n${whiteSpaces}`)}\n${whiteSpaces}`;
|
71
|
-
}
|
72
|
-
|
73
|
-
/**
|
74
|
-
* Finds the first token to prepend comments to depending on the parent type
|
75
|
-
* @param {Node} node The validated node
|
76
|
-
* @returns {Token|Node} The node to prepend comments to
|
77
|
-
*/
|
78
|
-
function findFirstToken(node) {
|
79
|
-
switch (node.parent.type) {
|
80
|
-
case "VariableDeclarator":
|
81
|
-
|
82
|
-
// If the parent is first or only declarator, return the declaration, else, declarator
|
83
|
-
return sourceCode.getFirstToken(
|
84
|
-
node.parent.parent.declarations.length === 1 ||
|
85
|
-
node.parent.parent.declarations[0].id.name === node.parent.id.name
|
86
|
-
? node.parent.parent : node.parent
|
87
|
-
);
|
88
|
-
case "CallExpression":
|
89
|
-
case "Property":
|
90
|
-
|
91
|
-
// find the object key
|
92
|
-
return sourceCode.getFirstToken(node.parent);
|
93
|
-
default:
|
94
|
-
return node;
|
95
|
-
}
|
96
|
-
}
|
97
|
-
|
98
|
-
/**
|
99
|
-
* Helper function for adding parentheses fixes for nodes containing nested arrow functions
|
100
|
-
* @param {Fixer} fixer Fixer
|
101
|
-
* @param {Token} arrow - The arrow token
|
102
|
-
* @param {ASTNode} arrowBody - The arrow function body
|
103
|
-
* @returns {Function[]} autofixer -- wraps function bodies with parentheses
|
104
|
-
*/
|
105
|
-
function addParentheses(fixer, arrow, arrowBody) {
|
106
|
-
const parenthesesFixes = [];
|
107
|
-
let closingParentheses = "";
|
108
|
-
|
109
|
-
let followingBody = arrowBody;
|
110
|
-
let currentArrow = arrow;
|
111
|
-
|
112
|
-
while (currentArrow) {
|
113
|
-
if (!isParenthesised(sourceCode, followingBody)) {
|
114
|
-
parenthesesFixes.push(
|
115
|
-
fixer.insertTextAfter(currentArrow, " (")
|
116
|
-
);
|
117
|
-
|
118
|
-
const paramsToken = sourceCode.getTokenBefore(currentArrow, token =>
|
119
|
-
isOpeningParenToken(token) || token.type === "Identifier");
|
120
|
-
|
121
|
-
const whiteSpaces = " ".repeat(paramsToken.loc.start.column);
|
122
|
-
|
123
|
-
closingParentheses = `\n${whiteSpaces})${closingParentheses}`;
|
124
|
-
}
|
125
|
-
|
126
|
-
currentArrow = sourceCode.getTokenAfter(currentArrow, isArrowToken);
|
127
|
-
|
128
|
-
if (currentArrow) {
|
129
|
-
followingBody = sourceCode.getTokenAfter(currentArrow, token => !isOpeningParenToken(token));
|
130
|
-
}
|
131
|
-
}
|
132
|
-
|
133
|
-
return [...parenthesesFixes,
|
134
|
-
fixer.insertTextAfter(arrowBody, closingParentheses)
|
135
|
-
];
|
136
|
-
}
|
137
|
-
|
138
|
-
/**
|
139
|
-
* Autofixes the function body to collapse onto the same line as the arrow.
|
140
|
-
* If comments exist, prepends the comments before the arrow function.
|
141
|
-
* If the function body contains arrow functions, appends the function bodies with parentheses.
|
142
|
-
* @param {Token} arrowToken The arrow token.
|
143
|
-
* @param {ASTNode} arrowBody the function body
|
144
|
-
* @param {ASTNode} node The evaluated node
|
145
|
-
* @returns {Function} autofixer -- validates the node to adhere to besides
|
146
|
-
*/
|
147
|
-
function autoFixBesides(arrowToken, arrowBody, node) {
|
148
|
-
return fixer => {
|
149
|
-
const placeBesides = fixer.replaceTextRange([arrowToken.range[1], arrowBody.range[0]], " ");
|
150
|
-
|
151
|
-
const comments = sourceCode.getCommentsInside(node).filter(comment =>
|
152
|
-
comment.loc.start.line < arrowBody.loc.start.line);
|
153
|
-
|
154
|
-
if (comments.length) {
|
155
|
-
|
156
|
-
// If the grandparent is not a variable declarator
|
157
|
-
if (
|
158
|
-
arrowBody.parent &&
|
159
|
-
arrowBody.parent.parent &&
|
160
|
-
arrowBody.parent.parent.type !== "VariableDeclarator"
|
161
|
-
) {
|
162
|
-
|
163
|
-
// If any arrow functions follow, return the necessary parens fixes.
|
164
|
-
if (sourceCode.getTokenAfter(arrowToken, isArrowToken) && arrowBody.parent.parent.type !== "VariableDeclarator") {
|
165
|
-
return addParentheses(fixer, arrowToken, arrowBody);
|
166
|
-
}
|
167
|
-
|
168
|
-
// If any arrow functions precede, the necessary fixes have already been returned, so return null.
|
169
|
-
if (sourceCode.getTokenBefore(arrowToken, isArrowToken) && arrowBody.parent.parent.type !== "VariableDeclarator") {
|
170
|
-
return null;
|
171
|
-
}
|
172
|
-
}
|
173
|
-
|
174
|
-
const firstToken = findFirstToken(node);
|
175
|
-
|
176
|
-
const commentText = formatComments(comments, firstToken.loc.start.column);
|
177
|
-
|
178
|
-
const commentBeforeExpression = fixer.insertTextBeforeRange(
|
179
|
-
firstToken.range,
|
180
|
-
commentText
|
181
|
-
);
|
182
|
-
|
183
|
-
return [placeBesides, commentBeforeExpression];
|
184
|
-
}
|
185
|
-
|
186
|
-
return placeBesides;
|
187
|
-
};
|
188
|
-
}
|
38
|
+
const option = context.options[0] || "beside";
|
189
39
|
|
190
40
|
/**
|
191
41
|
* Validates the location of an arrow function body
|
@@ -193,35 +43,30 @@ module.exports = {
|
|
193
43
|
* @returns {void}
|
194
44
|
*/
|
195
45
|
function validateExpression(node) {
|
196
|
-
|
197
|
-
|
198
|
-
let tokenBefore = sourceCode.getTokenBefore(node.body);
|
199
|
-
const hasParens = tokenBefore.value === "(";
|
200
|
-
|
201
|
-
if (node.type === "BlockStatement") {
|
46
|
+
if (node.body.type === "BlockStatement") {
|
202
47
|
return;
|
203
48
|
}
|
204
49
|
|
205
|
-
|
50
|
+
const arrowToken = sourceCode.getTokenBefore(node.body, isNotOpeningParenToken);
|
51
|
+
const firstTokenOfBody = sourceCode.getTokenAfter(arrowToken);
|
206
52
|
|
207
|
-
if (
|
208
|
-
|
209
|
-
// Gets the first token before the function body that is not an open paren
|
210
|
-
tokenBefore = sourceCode.getTokenBefore(node.body, token => token.value !== "(");
|
211
|
-
fixerTarget = sourceCode.getTokenAfter(tokenBefore);
|
212
|
-
}
|
213
|
-
|
214
|
-
if (tokenBefore.loc.end.line === fixerTarget.loc.start.line && option === "below") {
|
53
|
+
if (arrowToken.loc.end.line === firstTokenOfBody.loc.start.line && option === "below") {
|
215
54
|
context.report({
|
216
|
-
node:
|
55
|
+
node: firstTokenOfBody,
|
217
56
|
messageId: "expected",
|
218
|
-
fix: fixer => fixer.insertTextBefore(
|
57
|
+
fix: fixer => fixer.insertTextBefore(firstTokenOfBody, "\n")
|
219
58
|
});
|
220
|
-
} else if (
|
59
|
+
} else if (arrowToken.loc.end.line !== firstTokenOfBody.loc.start.line && option === "beside") {
|
221
60
|
context.report({
|
222
|
-
node:
|
61
|
+
node: firstTokenOfBody,
|
223
62
|
messageId: "unexpected",
|
224
|
-
fix
|
63
|
+
fix(fixer) {
|
64
|
+
if (sourceCode.getFirstTokenBetween(arrowToken, firstTokenOfBody, { includeComments: true, filter: isCommentToken })) {
|
65
|
+
return null;
|
66
|
+
}
|
67
|
+
|
68
|
+
return fixer.replaceTextRange([arrowToken.range[1], firstTokenOfBody.range[0]], " ");
|
69
|
+
}
|
225
70
|
});
|
226
71
|
}
|
227
72
|
}
|
@@ -975,7 +975,7 @@ module.exports = {
|
|
975
975
|
* @returns {boolean} the result
|
976
976
|
*/
|
977
977
|
function isWrappedInParenthesis(node) {
|
978
|
-
const regex = /^return\s*?\(\s*?\)
|
978
|
+
const regex = /^return\s*?\(\s*?\);*?/u;
|
979
979
|
|
980
980
|
const statementWithoutArgument = sourceCode.getText(node).replace(
|
981
981
|
sourceCode.getText(node.argument), ""
|
package/lib/rules/indent.js
CHANGED
@@ -442,7 +442,7 @@ class OffsetStorage {
|
|
442
442
|
const offset = (
|
443
443
|
offsetInfo.from &&
|
444
444
|
offsetInfo.from.loc.start.line === token.loc.start.line &&
|
445
|
-
!/^\s*?\n
|
445
|
+
!/^\s*?\n/u.test(token.value) &&
|
446
446
|
!offsetInfo.force
|
447
447
|
) ? 0 : offsetInfo.offset * this._indentSize;
|
448
448
|
|
@@ -785,7 +785,7 @@ module.exports = {
|
|
785
785
|
* or the total number of linebreaks if the string is all whitespace.
|
786
786
|
*/
|
787
787
|
function countTrailingLinebreaks(string) {
|
788
|
-
const trailingWhitespace = string.match(/\s*$/)[0];
|
788
|
+
const trailingWhitespace = string.match(/\s*$/u)[0];
|
789
789
|
const linebreakMatches = trailingWhitespace.match(astUtils.createGlobalLinebreakMatcher());
|
790
790
|
|
791
791
|
return linebreakMatches === null ? 0 : linebreakMatches.length;
|
package/lib/rules/jsx-quotes.js
CHANGED
@@ -20,14 +20,14 @@ const QUOTE_SETTINGS = {
|
|
20
20
|
quote: "\"",
|
21
21
|
description: "singlequote",
|
22
22
|
convert(str) {
|
23
|
-
return str.replace(/'/
|
23
|
+
return str.replace(/'/gu, "\"");
|
24
24
|
}
|
25
25
|
},
|
26
26
|
"prefer-single": {
|
27
27
|
quote: "'",
|
28
28
|
description: "doublequote",
|
29
29
|
convert(str) {
|
30
|
-
return str.replace(/"/
|
30
|
+
return str.replace(/"/gu, "'");
|
31
31
|
}
|
32
32
|
}
|
33
33
|
};
|
package/lib/rules/key-spacing.js
CHANGED
@@ -148,20 +148,16 @@ module.exports = {
|
|
148
148
|
type: "object",
|
149
149
|
properties: {
|
150
150
|
mode: {
|
151
|
-
enum: ["strict", "minimum"]
|
152
|
-
default: "strict"
|
151
|
+
enum: ["strict", "minimum"]
|
153
152
|
},
|
154
153
|
on: {
|
155
|
-
enum: ["colon", "value"]
|
156
|
-
default: "colon"
|
154
|
+
enum: ["colon", "value"]
|
157
155
|
},
|
158
156
|
beforeColon: {
|
159
|
-
type: "boolean"
|
160
|
-
default: false
|
157
|
+
type: "boolean"
|
161
158
|
},
|
162
159
|
afterColon: {
|
163
|
-
type: "boolean"
|
164
|
-
default: true
|
160
|
+
type: "boolean"
|
165
161
|
}
|
166
162
|
},
|
167
163
|
additionalProperties: false
|
@@ -169,16 +165,13 @@ module.exports = {
|
|
169
165
|
]
|
170
166
|
},
|
171
167
|
mode: {
|
172
|
-
enum: ["strict", "minimum"]
|
173
|
-
default: "strict"
|
168
|
+
enum: ["strict", "minimum"]
|
174
169
|
},
|
175
170
|
beforeColon: {
|
176
|
-
type: "boolean"
|
177
|
-
default: false
|
171
|
+
type: "boolean"
|
178
172
|
},
|
179
173
|
afterColon: {
|
180
|
-
type: "boolean"
|
181
|
-
default: true
|
174
|
+
type: "boolean"
|
182
175
|
}
|
183
176
|
},
|
184
177
|
additionalProperties: false
|
@@ -190,16 +183,13 @@ module.exports = {
|
|
190
183
|
type: "object",
|
191
184
|
properties: {
|
192
185
|
mode: {
|
193
|
-
enum: ["strict", "minimum"]
|
194
|
-
default: "strict"
|
186
|
+
enum: ["strict", "minimum"]
|
195
187
|
},
|
196
188
|
beforeColon: {
|
197
|
-
type: "boolean"
|
198
|
-
default: false
|
189
|
+
type: "boolean"
|
199
190
|
},
|
200
191
|
afterColon: {
|
201
|
-
type: "boolean"
|
202
|
-
default: true
|
192
|
+
type: "boolean"
|
203
193
|
}
|
204
194
|
},
|
205
195
|
additionalProperties: false
|
@@ -216,20 +206,16 @@ module.exports = {
|
|
216
206
|
type: "object",
|
217
207
|
properties: {
|
218
208
|
mode: {
|
219
|
-
enum: ["strict", "minimum"]
|
220
|
-
default: "strict"
|
209
|
+
enum: ["strict", "minimum"]
|
221
210
|
},
|
222
211
|
on: {
|
223
|
-
enum: ["colon", "value"]
|
224
|
-
default: "colon"
|
212
|
+
enum: ["colon", "value"]
|
225
213
|
},
|
226
214
|
beforeColon: {
|
227
|
-
type: "boolean"
|
228
|
-
default: false
|
215
|
+
type: "boolean"
|
229
216
|
},
|
230
217
|
afterColon: {
|
231
|
-
type: "boolean"
|
232
|
-
default: true
|
218
|
+
type: "boolean"
|
233
219
|
}
|
234
220
|
},
|
235
221
|
additionalProperties: false
|
@@ -237,16 +223,13 @@ module.exports = {
|
|
237
223
|
]
|
238
224
|
},
|
239
225
|
mode: {
|
240
|
-
enum: ["strict", "minimum"]
|
241
|
-
default: "strict"
|
226
|
+
enum: ["strict", "minimum"]
|
242
227
|
},
|
243
228
|
beforeColon: {
|
244
|
-
type: "boolean"
|
245
|
-
default: false
|
229
|
+
type: "boolean"
|
246
230
|
},
|
247
231
|
afterColon: {
|
248
|
-
type: "boolean"
|
249
|
-
default: true
|
232
|
+
type: "boolean"
|
250
233
|
}
|
251
234
|
},
|
252
235
|
additionalProperties: false
|
@@ -261,16 +244,13 @@ module.exports = {
|
|
261
244
|
type: "object",
|
262
245
|
properties: {
|
263
246
|
mode: {
|
264
|
-
enum: ["strict", "minimum"]
|
265
|
-
default: "strict"
|
247
|
+
enum: ["strict", "minimum"]
|
266
248
|
},
|
267
249
|
beforeColon: {
|
268
|
-
type: "boolean"
|
269
|
-
default: false
|
250
|
+
type: "boolean"
|
270
251
|
},
|
271
252
|
afterColon: {
|
272
|
-
type: "boolean"
|
273
|
-
default: true
|
253
|
+
type: "boolean"
|
274
254
|
}
|
275
255
|
},
|
276
256
|
additionalProperties: false
|
@@ -279,16 +259,13 @@ module.exports = {
|
|
279
259
|
type: "object",
|
280
260
|
properties: {
|
281
261
|
mode: {
|
282
|
-
enum: ["strict", "minimum"]
|
283
|
-
default: "strict"
|
262
|
+
enum: ["strict", "minimum"]
|
284
263
|
},
|
285
264
|
beforeColon: {
|
286
|
-
type: "boolean"
|
287
|
-
default: false
|
265
|
+
type: "boolean"
|
288
266
|
},
|
289
267
|
afterColon: {
|
290
|
-
type: "boolean"
|
291
|
-
default: true
|
268
|
+
type: "boolean"
|
292
269
|
}
|
293
270
|
},
|
294
271
|
additionalProperties: false
|
@@ -297,20 +274,16 @@ module.exports = {
|
|
297
274
|
type: "object",
|
298
275
|
properties: {
|
299
276
|
mode: {
|
300
|
-
enum: ["strict", "minimum"]
|
301
|
-
default: "strict"
|
277
|
+
enum: ["strict", "minimum"]
|
302
278
|
},
|
303
279
|
on: {
|
304
|
-
enum: ["colon", "value"]
|
305
|
-
default: "colon"
|
280
|
+
enum: ["colon", "value"]
|
306
281
|
},
|
307
282
|
beforeColon: {
|
308
|
-
type: "boolean"
|
309
|
-
default: false
|
283
|
+
type: "boolean"
|
310
284
|
},
|
311
285
|
afterColon: {
|
312
|
-
type: "boolean"
|
313
|
-
default: true
|
286
|
+
type: "boolean"
|
314
287
|
}
|
315
288
|
},
|
316
289
|
additionalProperties: false
|
@@ -528,7 +501,7 @@ module.exports = {
|
|
528
501
|
* @returns {Object} Whitespace before and after the property's colon.
|
529
502
|
*/
|
530
503
|
function getPropertyWhitespace(property) {
|
531
|
-
const whitespace = /(\s*):(\s*)
|
504
|
+
const whitespace = /(\s*):(\s*)/u.exec(sourceCode.getText().slice(
|
532
505
|
property.key.range[1], property.value.range[0]
|
533
506
|
));
|
534
507
|
|
@@ -16,13 +16,13 @@ const astUtils = require("../util/ast-utils"),
|
|
16
16
|
// Constants
|
17
17
|
//------------------------------------------------------------------------------
|
18
18
|
|
19
|
-
const PREV_TOKEN = /^[)\]}>]
|
20
|
-
const NEXT_TOKEN = /^(?:[([{<~!]|\+\+?|--?)
|
21
|
-
const PREV_TOKEN_M = /^[)\]}>*]
|
22
|
-
const NEXT_TOKEN_M = /^[{*]
|
23
|
-
const TEMPLATE_OPEN_PAREN = /\$\{
|
24
|
-
const TEMPLATE_CLOSE_PAREN = /^\}
|
25
|
-
const CHECK_TYPE = /^(?:JSXElement|RegularExpression|String|Template)
|
19
|
+
const PREV_TOKEN = /^[)\]}>]$/u;
|
20
|
+
const NEXT_TOKEN = /^(?:[([{<~!]|\+\+?|--?)$/u;
|
21
|
+
const PREV_TOKEN_M = /^[)\]}>*]$/u;
|
22
|
+
const NEXT_TOKEN_M = /^[{*]$/u;
|
23
|
+
const TEMPLATE_OPEN_PAREN = /\$\{$/u;
|
24
|
+
const TEMPLATE_CLOSE_PAREN = /^\}/u;
|
25
|
+
const CHECK_TYPE = /^(?:JSXElement|RegularExpression|String|Template)$/u;
|
26
26
|
const KEYS = keywords.concat(["as", "async", "await", "from", "get", "let", "of", "set", "yield"]);
|
27
27
|
|
28
28
|
// check duplications.
|
@@ -38,12 +38,10 @@ module.exports = {
|
|
38
38
|
type: "string"
|
39
39
|
},
|
40
40
|
applyDefaultPatterns: {
|
41
|
-
type: "boolean"
|
42
|
-
default: true
|
41
|
+
type: "boolean"
|
43
42
|
},
|
44
43
|
applyDefaultIgnorePatterns: {
|
45
|
-
type: "boolean"
|
46
|
-
default: true
|
44
|
+
type: "boolean"
|
47
45
|
}
|
48
46
|
},
|
49
47
|
additionalProperties: false
|
@@ -74,13 +72,13 @@ module.exports = {
|
|
74
72
|
if (Object.prototype.hasOwnProperty.call(options, "applyDefaultIgnorePatterns")) {
|
75
73
|
applyDefaultIgnorePatterns = options.applyDefaultIgnorePatterns;
|
76
74
|
} else {
|
77
|
-
applyDefaultIgnorePatterns = options.applyDefaultPatterns;
|
75
|
+
applyDefaultIgnorePatterns = options.applyDefaultPatterns !== false;
|
78
76
|
}
|
79
77
|
}
|
80
78
|
|
81
79
|
const defaultIgnoreRegExp = astUtils.COMMENTS_IGNORE_PATTERN;
|
82
|
-
const fallThroughRegExp = /^\s*falls?\s?through
|
83
|
-
const customIgnoreRegExp = new RegExp(ignorePattern);
|
80
|
+
const fallThroughRegExp = /^\s*falls?\s?through/u;
|
81
|
+
const customIgnoreRegExp = new RegExp(ignorePattern); // eslint-disable-line require-unicode-regexp
|
84
82
|
const sourceCode = context.getSourceCode();
|
85
83
|
|
86
84
|
//--------------------------------------------------------------------------
|
@@ -130,7 +130,7 @@ module.exports = {
|
|
130
130
|
const options = Object.assign({}, context.options[0]);
|
131
131
|
const ignorePattern = options.ignorePattern;
|
132
132
|
const defaultIgnoreRegExp = astUtils.COMMENTS_IGNORE_PATTERN;
|
133
|
-
const customIgnoreRegExp = new RegExp(ignorePattern);
|
133
|
+
const customIgnoreRegExp = new RegExp(ignorePattern); // eslint-disable-line require-unicode-regexp
|
134
134
|
const applyDefaultIgnorePatterns = options.applyDefaultIgnorePatterns !== false;
|
135
135
|
|
136
136
|
options.beforeBlockComment = typeof options.beforeBlockComment !== "undefined" ? options.beforeBlockComment : true;
|
package/lib/rules/max-depth.js
CHANGED
@@ -32,13 +32,11 @@ module.exports = {
|
|
32
32
|
properties: {
|
33
33
|
maximum: {
|
34
34
|
type: "integer",
|
35
|
-
minimum: 0
|
36
|
-
default: 4
|
35
|
+
minimum: 0
|
37
36
|
},
|
38
37
|
max: {
|
39
38
|
type: "integer",
|
40
|
-
minimum: 0
|
41
|
-
default: 4
|
39
|
+
minimum: 0
|
42
40
|
}
|
43
41
|
},
|
44
42
|
additionalProperties: false
|
@@ -61,7 +59,10 @@ module.exports = {
|
|
61
59
|
option = context.options[0];
|
62
60
|
let maxDepth = 4;
|
63
61
|
|
64
|
-
if (
|
62
|
+
if (
|
63
|
+
typeof option === "object" &&
|
64
|
+
(Object.prototype.hasOwnProperty.call(option, "maximum") || Object.prototype.hasOwnProperty.call(option, "max"))
|
65
|
+
) {
|
65
66
|
maxDepth = option.maximum || option.max;
|
66
67
|
}
|
67
68
|
if (typeof option === "number") {
|
package/lib/rules/max-len.js
CHANGED
@@ -103,7 +103,7 @@ module.exports = {
|
|
103
103
|
* too many false positives
|
104
104
|
* - We don't care about matching the entire URL, any small segment is fine
|
105
105
|
*/
|
106
|
-
const URL_REGEXP = /[^:/?#]:\/\/[^?#]
|
106
|
+
const URL_REGEXP = /[^:/?#]:\/\/[^?#]/u;
|
107
107
|
|
108
108
|
const sourceCode = context.getSourceCode();
|
109
109
|
|
@@ -118,7 +118,7 @@ module.exports = {
|
|
118
118
|
function computeLineLength(line, tabWidth) {
|
119
119
|
let extraCharacterCount = 0;
|
120
120
|
|
121
|
-
line.replace(/\t/
|
121
|
+
line.replace(/\t/gu, (match, offset) => {
|
122
122
|
const totalOffset = offset + extraCharacterCount,
|
123
123
|
previousTabStopOffset = tabWidth ? totalOffset % tabWidth : 0,
|
124
124
|
spaceCount = tabWidth - previousTabStopOffset;
|
@@ -153,7 +153,7 @@ module.exports = {
|
|
153
153
|
let ignorePattern = options.ignorePattern || null;
|
154
154
|
|
155
155
|
if (ignorePattern) {
|
156
|
-
ignorePattern = new RegExp(ignorePattern);
|
156
|
+
ignorePattern = new RegExp(ignorePattern); // eslint-disable-line require-unicode-regexp
|
157
157
|
}
|
158
158
|
|
159
159
|
//--------------------------------------------------------------------------
|
@@ -201,7 +201,7 @@ module.exports = {
|
|
201
201
|
function stripTrailingComment(line, comment) {
|
202
202
|
|
203
203
|
// loc.column is zero-indexed
|
204
|
-
return line.slice(0, comment.loc.start.column).replace(/\s
|
204
|
+
return line.slice(0, comment.loc.start.column).replace(/\s+$/u, "");
|
205
205
|
}
|
206
206
|
|
207
207
|
/**
|
package/lib/rules/max-lines.js
CHANGED
@@ -38,16 +38,13 @@ module.exports = {
|
|
38
38
|
properties: {
|
39
39
|
max: {
|
40
40
|
type: "integer",
|
41
|
-
minimum: 0
|
42
|
-
default: 300
|
41
|
+
minimum: 0
|
43
42
|
},
|
44
43
|
skipComments: {
|
45
|
-
type: "boolean"
|
46
|
-
default: false
|
44
|
+
type: "boolean"
|
47
45
|
},
|
48
46
|
skipBlankLines: {
|
49
|
-
type: "boolean"
|
50
|
-
default: false
|
47
|
+
type: "boolean"
|
51
48
|
}
|
52
49
|
},
|
53
50
|
additionalProperties: false
|
@@ -64,7 +61,7 @@ module.exports = {
|
|
64
61
|
const option = context.options[0];
|
65
62
|
let max = 300;
|
66
63
|
|
67
|
-
if (typeof option === "object") {
|
64
|
+
if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "max")) {
|
68
65
|
max = option.max;
|
69
66
|
} else if (typeof option === "number") {
|
70
67
|
max = option;
|