eslint 4.10.0 → 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 +36 -22
- package/conf/default-cli-options.js +5 -3
- package/lib/ast-utils.js +81 -41
- package/lib/cli-engine.js +27 -12
- package/lib/code-path-analysis/code-path-analyzer.js +8 -4
- package/lib/code-path-analysis/code-path-segment.js +4 -2
- package/lib/code-path-analysis/code-path-state.js +4 -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/junit.js +21 -15
- package/lib/formatters/tap.js +5 -3
- package/lib/ignored-paths.js +4 -2
- package/lib/linter.js +16 -10
- package/lib/rules/.eslintrc.yml +2 -2
- package/lib/rules/array-bracket-newline.js +20 -20
- 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/brace-style.js +14 -14
- 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 +5 -5
- package/lib/rules/func-call-spacing.js +4 -2
- package/lib/rules/getter-return.js +2 -1
- package/lib/rules/indent-legacy.js +20 -12
- package/lib/rules/indent.js +77 -73
- package/lib/rules/key-spacing.js +5 -3
- package/lib/rules/lines-around-directive.js +16 -12
- package/lib/rules/max-statements-per-line.js +5 -3
- package/lib/rules/newline-after-var.js +8 -6
- package/lib/rules/newline-before-return.js +9 -7
- 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-else-return.js +17 -11
- package/lib/rules/no-empty-character-class.js +11 -11
- package/lib/rules/no-extra-parens.js +16 -8
- 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-loop-func.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-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 +13 -7
- package/lib/rules/no-unreachable.js +4 -2
- package/lib/rules/no-use-before-define.js +13 -11
- package/lib/rules/no-useless-call.js +1 -25
- package/lib/rules/no-useless-escape.js +23 -22
- package/lib/rules/no-useless-return.js +14 -8
- 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 +41 -33
- package/lib/rules/operator-assignment.js +9 -9
- package/lib/rules/operator-linebreak.js +12 -10
- package/lib/rules/padding-line-between-statements.js +4 -2
- 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/semi-style.js +44 -19
- package/lib/rules/semi.js +5 -3
- package/lib/rules/sort-imports.js +5 -3
- package/lib/rules/space-unary-ops.js +61 -61
- package/lib/rules/strict.js +8 -8
- 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 +43 -34
- 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/glob.js +1 -1
- package/lib/util/naming.js +112 -0
- package/lib/util/node-event-generator.js +10 -10
- package/lib/util/safe-emitter.js +1 -1
- package/lib/util/source-code-fixer.js +4 -2
- package/lib/util/source-code.js +2 -1
- package/package.json +6 -5
@@ -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]);
|
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
|
|
@@ -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 }));
|
@@ -55,11 +55,11 @@ module.exports = {
|
|
55
55
|
}
|
56
56
|
|
57
57
|
/**
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
58
|
+
* Check if the property is valid dot notation
|
59
|
+
* @param {ASTNode} node The dot notation node
|
60
|
+
* @param {string} value Value which is to be checked
|
61
|
+
* @returns {void}
|
62
|
+
*/
|
63
63
|
function checkComputedProperty(node, value) {
|
64
64
|
if (
|
65
65
|
validIdentifier.test(value) &&
|
@@ -118,8 +118,10 @@ module.exports = {
|
|
118
118
|
message: "Unexpected space between function name and paren.",
|
119
119
|
fix(fixer) {
|
120
120
|
|
121
|
-
|
122
|
-
|
121
|
+
/*
|
122
|
+
* Only autofix if there is no newline
|
123
|
+
* https://github.com/eslint/eslint/issues/7787
|
124
|
+
*/
|
123
125
|
if (!hasNewline) {
|
124
126
|
return fixer.removeRange([prevToken.range[1], parenToken.range[0]]);
|
125
127
|
}
|
@@ -102,7 +102,8 @@ module.exports = {
|
|
102
102
|
}
|
103
103
|
}
|
104
104
|
|
105
|
-
/**
|
105
|
+
/**
|
106
|
+
* Checks whether a node means a getter function.
|
106
107
|
* @param {ASTNode} node - a node to check.
|
107
108
|
* @returns {boolean} if node means a getter, return true; else return false.
|
108
109
|
*/
|
@@ -274,8 +274,10 @@ module.exports = {
|
|
274
274
|
foundStatement = `${actualSpaces} ${foundSpacesWord} and ${actualTabs} ${foundTabsWord}`; // e.g. "1 space and 2 tabs"
|
275
275
|
} else if (actualSpaces > 0) {
|
276
276
|
|
277
|
-
|
278
|
-
|
277
|
+
/*
|
278
|
+
* Abbreviate the message if the expected indentation is also spaces.
|
279
|
+
* e.g. 'Expected 4 spaces but found 2' rather than 'Expected 4 spaces but found 2 spaces'
|
280
|
+
*/
|
279
281
|
foundStatement = indentType === "space" ? actualSpaces : `${actualSpaces} ${foundSpacesWord}`;
|
280
282
|
} else if (actualTabs > 0) {
|
281
283
|
foundStatement = indentType === "tab" ? actualTabs : `${actualTabs} ${foundTabsWord}`;
|
@@ -323,8 +325,8 @@ module.exports = {
|
|
323
325
|
* @param {ASTNode|Token} node Node to examine
|
324
326
|
* @param {boolean} [byLastLine=false] get indent of node's last line
|
325
327
|
* @returns {Object} The node's indent. Contains keys `space` and `tab`, representing the indent of each character. Also
|
326
|
-
contains keys `goodChar` and `badChar`, where `goodChar` is the amount of the user's desired indentation character, and
|
327
|
-
`badChar` is the amount of the other indentation character.
|
328
|
+
* contains keys `goodChar` and `badChar`, where `goodChar` is the amount of the user's desired indentation character, and
|
329
|
+
* `badChar` is the amount of the other indentation character.
|
328
330
|
*/
|
329
331
|
function getNodeIndent(node, byLastLine) {
|
330
332
|
const token = byLastLine ? sourceCode.getLastToken(node) : sourceCode.getFirstToken(node);
|
@@ -445,8 +447,10 @@ module.exports = {
|
|
445
447
|
*/
|
446
448
|
function checkLastReturnStatementLineIndent(node, firstLineIndent) {
|
447
449
|
|
448
|
-
|
449
|
-
|
450
|
+
/*
|
451
|
+
* in case if return statement ends with ');' we have traverse back to ')'
|
452
|
+
* otherwise we'll measure indent for ';' and replace ')'
|
453
|
+
*/
|
450
454
|
const lastToken = sourceCode.getLastToken(node, astUtils.isClosingParenToken);
|
451
455
|
const textBeforeClosingParenthesis = sourceCode.getText(lastToken, lastToken.loc.start.column).slice(0, -1);
|
452
456
|
|
@@ -645,8 +649,10 @@ module.exports = {
|
|
645
649
|
}
|
646
650
|
}
|
647
651
|
|
648
|
-
|
649
|
-
|
652
|
+
/*
|
653
|
+
* function body indent should be indent + indent size, unless this
|
654
|
+
* is a FunctionDeclaration, FunctionExpression, or outer IIFE and the corresponding options are enabled.
|
655
|
+
*/
|
650
656
|
let functionOffset = indentSize;
|
651
657
|
|
652
658
|
if (options.outerIIFEBody !== null && isOuterIIFE(calleeNode)) {
|
@@ -1027,10 +1033,12 @@ module.exports = {
|
|
1027
1033
|
return;
|
1028
1034
|
}
|
1029
1035
|
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1036
|
+
/*
|
1037
|
+
* The typical layout of variable declarations and assignments
|
1038
|
+
* alter the expectation of correct indentation. Skip them.
|
1039
|
+
* TODO: Add appropriate configuration options for variable
|
1040
|
+
* declarations and assignments.
|
1041
|
+
*/
|
1034
1042
|
if (getParentNodeByType(node, "VariableDeclarator", ["FunctionExpression", "ArrowFunctionExpression"])) {
|
1035
1043
|
return;
|
1036
1044
|
}
|