eslint 3.14.0 → 3.16.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 +68 -0
- package/README.md +1 -1
- package/conf/{eslint.json → eslint-recommended.js} +86 -71
- package/lib/ast-utils.js +192 -24
- package/lib/cli.js +2 -2
- package/lib/code-path-analysis/code-path-state.js +2 -2
- package/lib/config/autoconfig.js +3 -3
- package/lib/config/config-file.js +31 -24
- package/lib/config/config-initializer.js +1 -1
- package/lib/config/config-validator.js +6 -6
- package/lib/config.js +3 -2
- package/lib/eslint.js +18 -18
- package/lib/formatters/checkstyle.js +2 -2
- package/lib/formatters/compact.js +2 -2
- package/lib/formatters/junit.js +2 -2
- package/lib/formatters/tap.js +2 -2
- package/lib/formatters/unix.js +2 -2
- package/lib/formatters/visualstudio.js +2 -2
- package/lib/rules/arrow-body-style.js +7 -4
- package/lib/rules/arrow-spacing.js +7 -6
- package/lib/rules/block-spacing.js +2 -2
- package/lib/rules/brace-style.js +42 -22
- package/lib/rules/capitalized-comments.js +6 -6
- package/lib/rules/comma-spacing.js +16 -16
- package/lib/rules/consistent-return.js +1 -1
- package/lib/rules/constructor-super.js +3 -3
- package/lib/rules/curly.js +11 -7
- package/lib/rules/default-case.js +3 -3
- package/lib/rules/eqeqeq.js +15 -6
- package/lib/rules/func-call-spacing.js +10 -13
- package/lib/rules/func-name-matching.js +1 -1
- package/lib/rules/generator-star-spacing.js +18 -19
- package/lib/rules/global-require.js +2 -2
- package/lib/rules/id-blacklist.js +2 -2
- package/lib/rules/id-length.js +3 -3
- package/lib/rules/id-match.js +2 -2
- package/lib/rules/indent.js +21 -20
- package/lib/rules/key-spacing.js +20 -23
- package/lib/rules/keyword-spacing.js +2 -13
- package/lib/rules/line-comment-position.js +1 -1
- package/lib/rules/linebreak-style.js +7 -1
- package/lib/rules/lines-around-comment.js +4 -4
- package/lib/rules/lines-around-directive.js +3 -3
- package/lib/rules/max-lines.js +2 -2
- package/lib/rules/max-statements-per-line.js +7 -6
- package/lib/rules/new-cap.js +2 -2
- package/lib/rules/newline-after-var.js +7 -2
- package/lib/rules/newline-before-return.js +2 -2
- package/lib/rules/newline-per-chained-call.js +3 -1
- package/lib/rules/no-cond-assign.js +3 -3
- package/lib/rules/no-extend-native.js +3 -3
- package/lib/rules/no-extra-bind.js +3 -4
- package/lib/rules/no-extra-boolean-cast.js +8 -0
- package/lib/rules/no-extra-parens.js +29 -8
- package/lib/rules/no-inner-declarations.js +4 -4
- package/lib/rules/no-irregular-whitespace.js +7 -1
- package/lib/rules/no-lone-blocks.js +10 -10
- package/lib/rules/no-mixed-operators.js +1 -7
- package/lib/rules/no-mixed-requires.js +4 -4
- package/lib/rules/no-multi-spaces.js +4 -1
- package/lib/rules/no-multi-str.js +7 -3
- package/lib/rules/no-redeclare.js +7 -7
- package/lib/rules/no-return-assign.js +7 -14
- package/lib/rules/no-sequences.js +7 -6
- package/lib/rules/no-trailing-spaces.js +8 -2
- package/lib/rules/no-undefined.js +45 -6
- package/lib/rules/no-unexpected-multiline.js +9 -8
- package/lib/rules/no-unneeded-ternary.js +5 -1
- package/lib/rules/no-unused-labels.js +17 -2
- package/lib/rules/no-unused-vars.js +34 -19
- package/lib/rules/no-use-before-define.js +33 -29
- package/lib/rules/no-useless-computed-key.js +8 -3
- package/lib/rules/no-useless-concat.js +10 -7
- package/lib/rules/no-useless-escape.js +1 -1
- package/lib/rules/no-useless-return.js +1 -7
- package/lib/rules/no-var.js +11 -0
- package/lib/rules/no-whitespace-before-property.js +5 -16
- package/lib/rules/object-curly-newline.js +2 -2
- package/lib/rules/object-curly-spacing.js +7 -25
- package/lib/rules/object-property-newline.js +3 -3
- package/lib/rules/object-shorthand.js +10 -10
- package/lib/rules/operator-assignment.js +2 -2
- package/lib/rules/operator-linebreak.js +8 -10
- package/lib/rules/padded-blocks.js +7 -4
- package/lib/rules/prefer-spread.js +1 -1
- package/lib/rules/prefer-template.js +1 -1
- package/lib/rules/quotes.js +10 -6
- package/lib/rules/semi-spacing.js +4 -0
- package/lib/rules/sort-imports.js +4 -4
- package/lib/rules/sort-vars.js +2 -2
- package/lib/rules/space-before-function-paren.js +8 -5
- package/lib/rules/space-in-parens.js +8 -8
- package/lib/rules/spaced-comment.js +10 -10
- package/lib/rules/strict.js +2 -2
- package/lib/rules/template-tag-spacing.js +77 -0
- package/lib/rules/unicode-bom.js +1 -1
- package/lib/rules/wrap-iife.js +5 -5
- package/lib/rules/yoda.js +2 -7
- package/lib/rules.js +2 -2
- package/lib/testers/rule-tester.js +25 -18
- package/lib/token-store/backward-token-comment-cursor.js +57 -0
- package/lib/token-store/backward-token-cursor.js +56 -0
- package/lib/token-store/cursor.js +76 -0
- package/lib/token-store/cursors.js +92 -0
- package/lib/token-store/decorative-cursor.js +39 -0
- package/lib/token-store/filter-cursor.js +43 -0
- package/lib/token-store/forward-token-comment-cursor.js +57 -0
- package/lib/token-store/forward-token-cursor.js +61 -0
- package/lib/token-store/index.js +604 -0
- package/lib/token-store/limit-cursor.js +40 -0
- package/lib/token-store/padded-token-cursor.js +38 -0
- package/lib/token-store/skip-cursor.js +42 -0
- package/lib/token-store/utils.js +100 -0
- package/lib/util/glob.js +1 -1
- package/lib/util/source-code-fixer.js +46 -44
- package/lib/util/source-code.js +35 -19
- package/messages/extend-config-missing.txt +3 -0
- package/package.json +3 -3
- package/lib/token-store.js +0 -203
package/lib/rules/eqeqeq.js
CHANGED
@@ -5,6 +5,12 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
//------------------------------------------------------------------------------
|
9
|
+
// Requirements
|
10
|
+
//------------------------------------------------------------------------------
|
11
|
+
|
12
|
+
const astUtils = require("../ast-utils");
|
13
|
+
|
8
14
|
//------------------------------------------------------------------------------
|
9
15
|
// Rule Definition
|
10
16
|
//------------------------------------------------------------------------------
|
@@ -57,9 +63,9 @@ module.exports = {
|
|
57
63
|
const options = context.options[1] || {};
|
58
64
|
const sourceCode = context.getSourceCode();
|
59
65
|
|
60
|
-
const nullOption = (config === "always")
|
61
|
-
options.null || "always"
|
62
|
-
"ignore";
|
66
|
+
const nullOption = (config === "always")
|
67
|
+
? options.null || "always"
|
68
|
+
: "ignore";
|
63
69
|
const enforceRuleForNull = (nullOption === "always");
|
64
70
|
const enforceInverseRuleForNull = (nullOption === "never");
|
65
71
|
|
@@ -100,8 +106,7 @@ module.exports = {
|
|
100
106
|
* @private
|
101
107
|
*/
|
102
108
|
function isNullCheck(node) {
|
103
|
-
return (node.right
|
104
|
-
(node.left.type === "Literal" && node.left.value === null);
|
109
|
+
return astUtils.isNullLiteral(node.right) || astUtils.isNullLiteral(node.left);
|
105
110
|
}
|
106
111
|
|
107
112
|
/**
|
@@ -134,7 +139,11 @@ module.exports = {
|
|
134
139
|
|
135
140
|
// If the comparison is a `typeof` comparison or both sides are literals with the same type, then it's safe to fix.
|
136
141
|
if (isTypeOfBinary(node) || areLiteralsAndSameType(node)) {
|
137
|
-
const operatorToken = sourceCode.
|
142
|
+
const operatorToken = sourceCode.getFirstTokenBetween(
|
143
|
+
node.left,
|
144
|
+
node.right,
|
145
|
+
token => token.value === node.operator
|
146
|
+
);
|
138
147
|
|
139
148
|
return fixer.replaceText(operatorToken, expectedOperator);
|
140
149
|
}
|
@@ -5,6 +5,12 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
//------------------------------------------------------------------------------
|
9
|
+
// Requirements
|
10
|
+
//------------------------------------------------------------------------------
|
11
|
+
|
12
|
+
const astUtils = require("../ast-utils");
|
13
|
+
|
8
14
|
//------------------------------------------------------------------------------
|
9
15
|
// Rule Definition
|
10
16
|
//------------------------------------------------------------------------------
|
@@ -67,19 +73,10 @@ module.exports = {
|
|
67
73
|
* @private
|
68
74
|
*/
|
69
75
|
function checkSpacing(node) {
|
76
|
+
const lastToken = sourceCode.getLastToken(node);
|
70
77
|
const lastCalleeToken = sourceCode.getLastToken(node.callee);
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
// advances to an open parenthesis.
|
75
|
-
while (
|
76
|
-
parenToken &&
|
77
|
-
parenToken.range[1] < node.range[1] &&
|
78
|
-
parenToken.value !== "("
|
79
|
-
) {
|
80
|
-
prevToken = parenToken;
|
81
|
-
parenToken = sourceCode.getTokenAfter(parenToken);
|
82
|
-
}
|
78
|
+
const parenToken = sourceCode.getFirstTokenBetween(lastCalleeToken, lastToken, astUtils.isOpeningParenToken);
|
79
|
+
const prevToken = parenToken && sourceCode.getTokenBefore(parenToken);
|
83
80
|
|
84
81
|
// Parens in NewExpression are optional
|
85
82
|
if (!(parenToken && parenToken.range[1] < node.range[1])) {
|
@@ -88,7 +85,7 @@ module.exports = {
|
|
88
85
|
|
89
86
|
const textBetweenTokens = text.slice(prevToken.range[1], parenToken.range[0]).replace(/\/\*.*?\*\//g, "");
|
90
87
|
const hasWhitespace = /\s/.test(textBetweenTokens);
|
91
|
-
const hasNewline = hasWhitespace &&
|
88
|
+
const hasNewline = hasWhitespace && astUtils.LINEBREAK_MATCHER.test(textBetweenTokens);
|
92
89
|
|
93
90
|
/*
|
94
91
|
* never allowNewlines hasWhitespace hasNewline message
|
@@ -155,7 +155,7 @@ module.exports = {
|
|
155
155
|
return;
|
156
156
|
}
|
157
157
|
|
158
|
-
const isProp = node.left.type === "MemberExpression"
|
158
|
+
const isProp = node.left.type === "MemberExpression";
|
159
159
|
const name = isProp ? astUtils.getStaticPropertyName(node.left) : node.left.name;
|
160
160
|
|
161
161
|
if (node.right.id && isIdentifier(name) && shouldWarn(name, node.right.id.name)) {
|
@@ -55,21 +55,26 @@ module.exports = {
|
|
55
55
|
const sourceCode = context.getSourceCode();
|
56
56
|
|
57
57
|
/**
|
58
|
-
*
|
58
|
+
* Checks if the given token is a star token or not.
|
59
59
|
*
|
60
|
-
* @param {
|
61
|
-
*
|
62
|
-
* MethodDefinition.
|
63
|
-
* @returns {Token} `*` token.
|
60
|
+
* @param {Token} token - The token to check.
|
61
|
+
* @returns {boolean} `true` if the token is a star token.
|
64
62
|
*/
|
65
|
-
function
|
66
|
-
|
67
|
-
|
68
|
-
while (token.value !== "*") {
|
69
|
-
token = sourceCode.getTokenAfter(token);
|
70
|
-
}
|
63
|
+
function isStarToken(token) {
|
64
|
+
return token.value === "*" && token.type === "Punctuator";
|
65
|
+
}
|
71
66
|
|
72
|
-
|
67
|
+
/**
|
68
|
+
* Gets the generator star token of the given function node.
|
69
|
+
*
|
70
|
+
* @param {ASTNode} node - The function node to get.
|
71
|
+
* @returns {Token} Found star token.
|
72
|
+
*/
|
73
|
+
function getStarToken(node) {
|
74
|
+
return sourceCode.getFirstToken(
|
75
|
+
(node.parent.method || node.parent.type === "MethodDefinition") ? node.parent : node,
|
76
|
+
isStarToken
|
77
|
+
);
|
73
78
|
}
|
74
79
|
|
75
80
|
/**
|
@@ -116,17 +121,11 @@ module.exports = {
|
|
116
121
|
* @returns {void}
|
117
122
|
*/
|
118
123
|
function checkFunction(node) {
|
119
|
-
let starToken;
|
120
|
-
|
121
124
|
if (!node.generator) {
|
122
125
|
return;
|
123
126
|
}
|
124
127
|
|
125
|
-
|
126
|
-
starToken = getStarToken(node.parent);
|
127
|
-
} else {
|
128
|
-
starToken = getStarToken(node);
|
129
|
-
}
|
128
|
+
const starToken = getStarToken(node);
|
130
129
|
|
131
130
|
// Only check before when preceded by `function`|`static` keyword
|
132
131
|
const prevToken = sourceCode.getTokenBefore(starToken);
|
@@ -55,8 +55,8 @@ module.exports = {
|
|
55
55
|
* @returns {boolean} whether an error should be reported or not
|
56
56
|
*/
|
57
57
|
function shouldReport(effectiveParent, name) {
|
58
|
-
return effectiveParent.type !== "CallExpression"
|
59
|
-
|
58
|
+
return effectiveParent.type !== "CallExpression" &&
|
59
|
+
effectiveParent.type !== "NewExpression" &&
|
60
60
|
isInvalid(name);
|
61
61
|
}
|
62
62
|
|
package/lib/rules/id-length.js
CHANGED
@@ -104,9 +104,9 @@ module.exports = {
|
|
104
104
|
if (isValidExpression && (isValidExpression === true || isValidExpression(parent, node))) {
|
105
105
|
context.report({
|
106
106
|
node,
|
107
|
-
message: isShort
|
108
|
-
"Identifier name '{{name}}' is too short (< {{min}})."
|
109
|
-
"Identifier name '{{name}}' is too long (> {{max}}).",
|
107
|
+
message: isShort
|
108
|
+
? "Identifier name '{{name}}' is too short (< {{min}})."
|
109
|
+
: "Identifier name '{{name}}' is too long (> {{max}}).",
|
110
110
|
data: { name, min: minLength, max: maxLength }
|
111
111
|
});
|
112
112
|
}
|
package/lib/rules/id-match.js
CHANGED
@@ -63,8 +63,8 @@ module.exports = {
|
|
63
63
|
* @returns {boolean} whether an error should be reported or not
|
64
64
|
*/
|
65
65
|
function shouldReport(effectiveParent, name) {
|
66
|
-
return effectiveParent.type !== "CallExpression"
|
67
|
-
|
66
|
+
return effectiveParent.type !== "CallExpression" &&
|
67
|
+
effectiveParent.type !== "NewExpression" &&
|
68
68
|
isInvalid(name);
|
69
69
|
}
|
70
70
|
|
package/lib/rules/indent.js
CHANGED
@@ -8,6 +8,12 @@
|
|
8
8
|
|
9
9
|
"use strict";
|
10
10
|
|
11
|
+
//------------------------------------------------------------------------------
|
12
|
+
// Requirements
|
13
|
+
//------------------------------------------------------------------------------
|
14
|
+
|
15
|
+
const astUtils = require("../ast-utils");
|
16
|
+
|
11
17
|
//------------------------------------------------------------------------------
|
12
18
|
// Rule Definition
|
13
19
|
//------------------------------------------------------------------------------
|
@@ -435,15 +441,10 @@ module.exports = {
|
|
435
441
|
* @returns {void}
|
436
442
|
*/
|
437
443
|
function checkLastReturnStatementLineIndent(node, firstLineIndent) {
|
438
|
-
const nodeLastToken = sourceCode.getLastToken(node);
|
439
|
-
let lastToken = nodeLastToken;
|
440
444
|
|
441
445
|
// in case if return statement ends with ');' we have traverse back to ')'
|
442
446
|
// otherwise we'll measure indent for ';' and replace ')'
|
443
|
-
|
444
|
-
lastToken = sourceCode.getTokenBefore(lastToken);
|
445
|
-
}
|
446
|
-
|
447
|
+
const lastToken = sourceCode.getLastToken(node, astUtils.isClosingParenToken);
|
447
448
|
const textBeforeClosingParenthesis = sourceCode.getText(lastToken, lastToken.loc.start.column).slice(0, -1);
|
448
449
|
|
449
450
|
if (textBeforeClosingParenthesis.trim()) {
|
@@ -691,9 +692,9 @@ module.exports = {
|
|
691
692
|
function isFirstArrayElementOnSameLine(node) {
|
692
693
|
if (node.type === "ArrayExpression" && node.elements[0]) {
|
693
694
|
return node.elements[0].loc.start.line === node.loc.start.line && node.elements[0].type === "ObjectExpression";
|
694
|
-
} else {
|
695
|
-
return false;
|
696
695
|
}
|
696
|
+
return false;
|
697
|
+
|
697
698
|
}
|
698
699
|
|
699
700
|
/**
|
@@ -729,7 +730,7 @@ module.exports = {
|
|
729
730
|
} else if (parent.type === "ObjectExpression" || parent.type === "ArrayExpression") {
|
730
731
|
const parentElements = node.parent.type === "ObjectExpression" ? node.parent.properties : node.parent.elements;
|
731
732
|
|
732
|
-
if (parentElements[0].loc.start.line === parent.loc.start.line && parentElements[0].loc.end.line !== parent.loc.start.line) {
|
733
|
+
if (parentElements[0] && parentElements[0].loc.start.line === parent.loc.start.line && parentElements[0].loc.end.line !== parent.loc.start.line) {
|
733
734
|
|
734
735
|
/*
|
735
736
|
* If the first element of the array spans multiple lines, don't increase the expected indentation of the rest.
|
@@ -936,20 +937,20 @@ module.exports = {
|
|
936
937
|
|
937
938
|
if (caseIndentStore[switchNode.loc.start.line]) {
|
938
939
|
return caseIndentStore[switchNode.loc.start.line];
|
940
|
+
}
|
941
|
+
if (typeof switchIndent === "undefined") {
|
942
|
+
switchIndent = getNodeIndent(switchNode).goodChar;
|
943
|
+
}
|
944
|
+
|
945
|
+
if (switchNode.cases.length > 0 && options.SwitchCase === 0) {
|
946
|
+
caseIndent = switchIndent;
|
939
947
|
} else {
|
940
|
-
|
941
|
-
|
942
|
-
}
|
948
|
+
caseIndent = switchIndent + (indentSize * options.SwitchCase);
|
949
|
+
}
|
943
950
|
|
944
|
-
|
945
|
-
|
946
|
-
} else {
|
947
|
-
caseIndent = switchIndent + (indentSize * options.SwitchCase);
|
948
|
-
}
|
951
|
+
caseIndentStore[switchNode.loc.start.line] = caseIndent;
|
952
|
+
return caseIndent;
|
949
953
|
|
950
|
-
caseIndentStore[switchNode.loc.start.line] = caseIndent;
|
951
|
-
return caseIndent;
|
952
|
-
}
|
953
954
|
}
|
954
955
|
|
955
956
|
/**
|
package/lib/rules/key-spacing.js
CHANGED
@@ -4,6 +4,12 @@
|
|
4
4
|
*/
|
5
5
|
"use strict";
|
6
6
|
|
7
|
+
//------------------------------------------------------------------------------
|
8
|
+
// Requirements
|
9
|
+
//------------------------------------------------------------------------------
|
10
|
+
|
11
|
+
const astUtils = require("../ast-utils");
|
12
|
+
|
7
13
|
//------------------------------------------------------------------------------
|
8
14
|
// Helpers
|
9
15
|
//------------------------------------------------------------------------------
|
@@ -15,7 +21,7 @@
|
|
15
21
|
* @returns {boolean} True if str contains a line terminator.
|
16
22
|
*/
|
17
23
|
function containsLineTerminator(str) {
|
18
|
-
return
|
24
|
+
return astUtils.LINEBREAK_MATCHER.test(str);
|
19
25
|
}
|
20
26
|
|
21
27
|
/**
|
@@ -364,14 +370,9 @@ module.exports = {
|
|
364
370
|
* @returns {ASTNode} The last token before a colon punctuator.
|
365
371
|
*/
|
366
372
|
function getLastTokenBeforeColon(node) {
|
367
|
-
|
373
|
+
const colonToken = sourceCode.getTokenAfter(node, astUtils.isColonToken);
|
368
374
|
|
369
|
-
|
370
|
-
prevNode = node;
|
371
|
-
node = sourceCode.getTokenAfter(node);
|
372
|
-
}
|
373
|
-
|
374
|
-
return prevNode;
|
375
|
+
return sourceCode.getTokenBefore(colonToken);
|
375
376
|
}
|
376
377
|
|
377
378
|
/**
|
@@ -381,12 +382,7 @@ module.exports = {
|
|
381
382
|
* @returns {ASTNode} The colon punctuator.
|
382
383
|
*/
|
383
384
|
function getNextColon(node) {
|
384
|
-
|
385
|
-
while (node && (node.type !== "Punctuator" || node.value !== ":")) {
|
386
|
-
node = sourceCode.getTokenAfter(node);
|
387
|
-
}
|
388
|
-
|
389
|
-
return node;
|
385
|
+
return sourceCode.getTokenAfter(node, astUtils.isColonToken);
|
390
386
|
}
|
391
387
|
|
392
388
|
/**
|
@@ -417,8 +413,8 @@ module.exports = {
|
|
417
413
|
function report(property, side, whitespace, expected, mode) {
|
418
414
|
const diff = whitespace.length - expected,
|
419
415
|
nextColon = getNextColon(property.key),
|
420
|
-
tokenBeforeColon = sourceCode.
|
421
|
-
tokenAfterColon = sourceCode.
|
416
|
+
tokenBeforeColon = sourceCode.getTokenBefore(nextColon, { includeComments: true }),
|
417
|
+
tokenAfterColon = sourceCode.getTokenAfter(nextColon, { includeComments: true }),
|
422
418
|
isKeySide = side === "key",
|
423
419
|
locStart = isKeySide ? tokenBeforeColon.loc.start : tokenAfterColon.loc.start,
|
424
420
|
isExtra = diff > 0,
|
@@ -628,15 +624,16 @@ module.exports = {
|
|
628
624
|
}
|
629
625
|
};
|
630
626
|
|
631
|
-
}
|
627
|
+
}
|
628
|
+
|
629
|
+
// Obey beforeColon and afterColon in each property as configured
|
630
|
+
return {
|
631
|
+
Property(node) {
|
632
|
+
verifySpacing(node, isSingleLine(node.parent) ? singleLineOptions : multiLineOptions);
|
633
|
+
}
|
634
|
+
};
|
632
635
|
|
633
|
-
return {
|
634
|
-
Property(node) {
|
635
|
-
verifySpacing(node, isSingleLine(node.parent) ? singleLineOptions : multiLineOptions);
|
636
|
-
}
|
637
|
-
};
|
638
636
|
|
639
|
-
}
|
640
637
|
|
641
638
|
}
|
642
639
|
};
|
@@ -342,11 +342,7 @@ module.exports = {
|
|
342
342
|
*/
|
343
343
|
function checkSpacingAroundTokenBefore(node) {
|
344
344
|
if (node) {
|
345
|
-
|
346
|
-
|
347
|
-
while (token.type !== "Keyword") {
|
348
|
-
token = sourceCode.getTokenBefore(token);
|
349
|
-
}
|
345
|
+
const token = sourceCode.getTokenBefore(node, astUtils.isKeywordToken);
|
350
346
|
|
351
347
|
checkSpacingAround(token);
|
352
348
|
}
|
@@ -439,14 +435,7 @@ module.exports = {
|
|
439
435
|
*/
|
440
436
|
function checkSpacingForForOfStatement(node) {
|
441
437
|
checkSpacingAroundFirstToken(node);
|
442
|
-
|
443
|
-
// `of` is not a keyword token.
|
444
|
-
let token = sourceCode.getTokenBefore(node.right);
|
445
|
-
|
446
|
-
while (token.value !== "of") {
|
447
|
-
token = sourceCode.getTokenBefore(token);
|
448
|
-
}
|
449
|
-
checkSpacingAround(token);
|
438
|
+
checkSpacingAround(sourceCode.getTokenBefore(node.right, astUtils.isNotOpeningParenToken));
|
450
439
|
}
|
451
440
|
|
452
441
|
/**
|
@@ -77,7 +77,7 @@ module.exports = {
|
|
77
77
|
return;
|
78
78
|
}
|
79
79
|
|
80
|
-
const previous = sourceCode.
|
80
|
+
const previous = sourceCode.getTokenBefore(node, { includeComments: true });
|
81
81
|
const isOnSameLine = previous && previous.loc.end.line === node.loc.start.line;
|
82
82
|
|
83
83
|
if (above) {
|
@@ -5,6 +5,12 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
//------------------------------------------------------------------------------
|
9
|
+
// Requirements
|
10
|
+
//------------------------------------------------------------------------------
|
11
|
+
|
12
|
+
const astUtils = require("../ast-utils");
|
13
|
+
|
8
14
|
//------------------------------------------------------------------------------
|
9
15
|
// Rule Definition
|
10
16
|
//------------------------------------------------------------------------------
|
@@ -60,7 +66,7 @@ module.exports = {
|
|
60
66
|
expectedLF = linebreakStyle === "unix",
|
61
67
|
expectedLFChars = expectedLF ? "\n" : "\r\n",
|
62
68
|
source = sourceCode.getText(),
|
63
|
-
pattern =
|
69
|
+
pattern = astUtils.createGlobalLinebreakMatcher();
|
64
70
|
let match;
|
65
71
|
|
66
72
|
let i = 0;
|
@@ -139,7 +139,7 @@ module.exports = {
|
|
139
139
|
|
140
140
|
token = node;
|
141
141
|
do {
|
142
|
-
token = sourceCode.
|
142
|
+
token = sourceCode.getTokenBefore(token, { includeComments: true });
|
143
143
|
} while (isCommentNodeType(token));
|
144
144
|
|
145
145
|
if (token && astUtils.isTokenOnSameLine(token, node)) {
|
@@ -148,7 +148,7 @@ module.exports = {
|
|
148
148
|
|
149
149
|
token = node;
|
150
150
|
do {
|
151
|
-
token = sourceCode.
|
151
|
+
token = sourceCode.getTokenAfter(token, { includeComments: true });
|
152
152
|
} while (isCommentNodeType(token));
|
153
153
|
|
154
154
|
if (token && astUtils.isTokenOnSameLine(node, token)) {
|
@@ -300,8 +300,8 @@ module.exports = {
|
|
300
300
|
return;
|
301
301
|
}
|
302
302
|
|
303
|
-
const previousTokenOrComment = sourceCode.
|
304
|
-
const nextTokenOrComment = sourceCode.
|
303
|
+
const previousTokenOrComment = sourceCode.getTokenBefore(node, { includeComments: true });
|
304
|
+
const nextTokenOrComment = sourceCode.getTokenAfter(node, { includeComments: true });
|
305
305
|
|
306
306
|
// check for newline before
|
307
307
|
if (!exceptionStartAllowed && before && !lodash.includes(commentAndEmptyLines, prevLineNum) &&
|
@@ -57,7 +57,7 @@ module.exports = {
|
|
57
57
|
* @returns {boolean} Whether or not the passed in node is preceded by a blank newline.
|
58
58
|
*/
|
59
59
|
function hasNewlineBefore(node) {
|
60
|
-
const tokenBefore = sourceCode.
|
60
|
+
const tokenBefore = sourceCode.getTokenBefore(node, { includeComments: true });
|
61
61
|
const tokenLineBefore = tokenBefore ? tokenBefore.loc.end.line : 0;
|
62
62
|
|
63
63
|
return node.loc.start.line - tokenLineBefore >= 2;
|
@@ -86,7 +86,7 @@ module.exports = {
|
|
86
86
|
*/
|
87
87
|
function hasNewlineAfter(node) {
|
88
88
|
const lastToken = getLastTokenOnLine(node);
|
89
|
-
const tokenAfter = sourceCode.
|
89
|
+
const tokenAfter = sourceCode.getTokenAfter(lastToken, { includeComments: true });
|
90
90
|
|
91
91
|
return tokenAfter.loc.start.line - lastToken.loc.end.line >= 2;
|
92
92
|
}
|
@@ -131,7 +131,7 @@ module.exports = {
|
|
131
131
|
}
|
132
132
|
|
133
133
|
const firstDirective = directives[0];
|
134
|
-
const hasTokenOrCommentBefore = !!sourceCode.
|
134
|
+
const hasTokenOrCommentBefore = !!sourceCode.getTokenBefore(firstDirective, { includeComments: true });
|
135
135
|
|
136
136
|
// Only check before the first directive if it is preceded by a comment or if it is at the top of
|
137
137
|
// the file and expectLineBefore is set to "never". This is to not force a newline at the top of
|
package/lib/rules/max-lines.js
CHANGED
@@ -90,7 +90,7 @@ module.exports = {
|
|
90
90
|
|
91
91
|
token = comment;
|
92
92
|
do {
|
93
|
-
token = sourceCode.
|
93
|
+
token = sourceCode.getTokenBefore(token, { includeComments: true });
|
94
94
|
} while (isCommentNodeType(token));
|
95
95
|
|
96
96
|
if (token && astUtils.isTokenOnSameLine(token, comment)) {
|
@@ -99,7 +99,7 @@ module.exports = {
|
|
99
99
|
|
100
100
|
token = comment;
|
101
101
|
do {
|
102
|
-
token = sourceCode.
|
102
|
+
token = sourceCode.getTokenAfter(token, { includeComments: true });
|
103
103
|
} while (isCommentNodeType(token));
|
104
104
|
|
105
105
|
if (token && astUtils.isTokenOnSameLine(comment, token)) {
|
@@ -4,6 +4,12 @@
|
|
4
4
|
*/
|
5
5
|
"use strict";
|
6
6
|
|
7
|
+
//------------------------------------------------------------------------------
|
8
|
+
// Requirements
|
9
|
+
//------------------------------------------------------------------------------
|
10
|
+
|
11
|
+
const astUtils = require("../ast-utils");
|
12
|
+
|
7
13
|
//------------------------------------------------------------------------------
|
8
14
|
// Rule Definition
|
9
15
|
//------------------------------------------------------------------------------
|
@@ -74,12 +80,7 @@ module.exports = {
|
|
74
80
|
* @returns {Token} The actual last token.
|
75
81
|
*/
|
76
82
|
function getActualLastToken(node) {
|
77
|
-
|
78
|
-
|
79
|
-
if (lastToken.value === ";") {
|
80
|
-
lastToken = sourceCode.getTokenBefore(lastToken);
|
81
|
-
}
|
82
|
-
return lastToken;
|
83
|
+
return sourceCode.getLastToken(node, astUtils.isNotSemicolonToken);
|
83
84
|
}
|
84
85
|
|
85
86
|
/**
|
package/lib/rules/new-cap.js
CHANGED
@@ -5,6 +5,12 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
//------------------------------------------------------------------------------
|
9
|
+
// Requirements
|
10
|
+
//------------------------------------------------------------------------------
|
11
|
+
|
12
|
+
const astUtils = require("../ast-utils");
|
13
|
+
|
8
14
|
//------------------------------------------------------------------------------
|
9
15
|
// Rule Definition
|
10
16
|
//------------------------------------------------------------------------------
|
@@ -201,8 +207,7 @@ module.exports = {
|
|
201
207
|
message: NEVER_MESSAGE,
|
202
208
|
data: { identifier: node.name },
|
203
209
|
fix(fixer) {
|
204
|
-
const
|
205
|
-
const linesBetween = sourceCode.getText().slice(lastToken.range[1], nextToken.range[0]).split(NEWLINE_REGEX);
|
210
|
+
const linesBetween = sourceCode.getText().slice(lastToken.range[1], nextToken.range[0]).split(astUtils.LINEBREAK_MATCHER);
|
206
211
|
|
207
212
|
return fixer.replaceTextRange([lastToken.range[1], nextToken.range[0]], `${linesBetween.slice(0, -1).join("")}\n${linesBetween[linesBetween.length - 1]}`);
|
208
213
|
}
|
@@ -60,9 +60,9 @@ module.exports = {
|
|
60
60
|
return isPrecededByTokens(node, ["do"]);
|
61
61
|
} else if (parentType === "SwitchCase") {
|
62
62
|
return isPrecededByTokens(node, [":"]);
|
63
|
-
} else {
|
64
|
-
return isPrecededByTokens(node, [")"]);
|
65
63
|
}
|
64
|
+
return isPrecededByTokens(node, [")"]);
|
65
|
+
|
66
66
|
}
|
67
67
|
|
68
68
|
/**
|
@@ -6,6 +6,8 @@
|
|
6
6
|
|
7
7
|
"use strict";
|
8
8
|
|
9
|
+
const astUtils = require("../ast-utils");
|
10
|
+
|
9
11
|
//------------------------------------------------------------------------------
|
10
12
|
// Rule Definition
|
11
13
|
//------------------------------------------------------------------------------
|
@@ -47,7 +49,7 @@ module.exports = {
|
|
47
49
|
*/
|
48
50
|
function getPropertyText(node) {
|
49
51
|
const prefix = node.computed ? "[" : ".";
|
50
|
-
const lines = sourceCode.getText(node.property).split(
|
52
|
+
const lines = sourceCode.getText(node.property).split(astUtils.LINEBREAK_MATCHER);
|
51
53
|
const suffix = node.computed && lines.length === 1 ? "]" : "";
|
52
54
|
|
53
55
|
return prefix + lines[0] + suffix;
|
@@ -101,9 +101,9 @@ module.exports = {
|
|
101
101
|
function testForAssign(node) {
|
102
102
|
if (node.test &&
|
103
103
|
(node.test.type === "AssignmentExpression") &&
|
104
|
-
(node.type === "ForStatement"
|
105
|
-
!isParenthesised(node.test)
|
106
|
-
!isParenthesisedTwice(node.test)
|
104
|
+
(node.type === "ForStatement"
|
105
|
+
? !isParenthesised(node.test)
|
106
|
+
: !isParenthesisedTwice(node.test)
|
107
107
|
)
|
108
108
|
) {
|
109
109
|
|
@@ -60,9 +60,9 @@ module.exports = {
|
|
60
60
|
return;
|
61
61
|
}
|
62
62
|
|
63
|
-
const affectsProto = lhs.object.computed
|
64
|
-
lhs.object.property.type === "Literal" && lhs.object.property.value === "prototype"
|
65
|
-
lhs.object.property.name === "prototype";
|
63
|
+
const affectsProto = lhs.object.computed
|
64
|
+
? lhs.object.property.type === "Literal" && lhs.object.property.value === "prototype"
|
65
|
+
: lhs.object.property.name === "prototype";
|
66
66
|
|
67
67
|
if (!affectsProto) {
|
68
68
|
return;
|