eslint 5.1.0 → 5.5.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 +72 -0
- package/conf/eslint-recommended.js +4 -0
- package/lib/cli-engine.js +38 -78
- package/lib/cli.js +1 -1
- package/lib/code-path-analysis/code-path-analyzer.js +1 -1
- package/lib/config/config-initializer.js +8 -8
- package/lib/config.js +1 -1
- package/lib/formatters/codeframe.js +2 -2
- package/lib/ignored-paths.js +125 -37
- package/lib/linter.js +6 -7
- package/lib/rules/array-bracket-newline.js +1 -1
- package/lib/rules/array-bracket-spacing.js +1 -1
- package/lib/rules/array-callback-return.js +1 -1
- package/lib/rules/array-element-newline.js +1 -1
- package/lib/rules/arrow-body-style.js +1 -1
- package/lib/rules/arrow-parens.js +1 -1
- package/lib/rules/arrow-spacing.js +1 -1
- package/lib/rules/block-spacing.js +1 -1
- package/lib/rules/brace-style.js +1 -1
- package/lib/rules/camelcase.js +1 -1
- package/lib/rules/capitalized-comments.js +1 -1
- package/lib/rules/comma-dangle.js +1 -1
- package/lib/rules/comma-spacing.js +1 -1
- package/lib/rules/comma-style.js +2 -2
- package/lib/rules/complexity.js +3 -3
- package/lib/rules/computed-property-spacing.js +1 -1
- package/lib/rules/consistent-return.js +1 -1
- package/lib/rules/curly.js +1 -1
- package/lib/rules/dot-location.js +1 -1
- package/lib/rules/dot-notation.js +1 -1
- package/lib/rules/eqeqeq.js +1 -1
- package/lib/rules/for-direction.js +5 -2
- package/lib/rules/func-call-spacing.js +8 -4
- package/lib/rules/func-name-matching.js +13 -7
- package/lib/rules/func-names.js +8 -4
- package/lib/rules/func-style.js +8 -4
- package/lib/rules/function-paren-newline.js +12 -6
- package/lib/rules/generator-star-spacing.js +18 -9
- package/lib/rules/getter-return.js +8 -6
- package/lib/rules/indent-legacy.js +1 -1
- package/lib/rules/indent.js +43 -7
- package/lib/rules/jsx-quotes.js +1 -1
- package/lib/rules/key-spacing.js +2 -2
- package/lib/rules/keyword-spacing.js +1 -1
- package/lib/rules/line-comment-position.js +3 -3
- package/lib/rules/linebreak-style.js +1 -1
- package/lib/rules/lines-around-comment.js +1 -1
- package/lib/rules/lines-around-directive.js +1 -1
- package/lib/rules/lines-between-class-members.js +1 -1
- package/lib/rules/max-depth.js +2 -2
- package/lib/rules/max-len.js +1 -1
- package/lib/rules/max-lines-per-function.js +1 -1
- package/lib/rules/max-lines.js +2 -2
- package/lib/rules/max-nested-callbacks.js +2 -2
- package/lib/rules/max-params.js +5 -4
- package/lib/rules/max-statements-per-line.js +1 -1
- package/lib/rules/max-statements.js +3 -3
- package/lib/rules/multiline-comment-style.js +1 -1
- package/lib/rules/multiline-ternary.js +1 -1
- package/lib/rules/new-parens.js +1 -1
- package/lib/rules/newline-after-var.js +1 -1
- package/lib/rules/newline-per-chained-call.js +1 -1
- package/lib/rules/no-alert.js +1 -1
- package/lib/rules/no-async-promise-executor.js +33 -0
- package/lib/rules/no-catch-shadow.js +1 -1
- package/lib/rules/no-class-assign.js +1 -1
- package/lib/rules/no-cond-assign.js +1 -1
- package/lib/rules/no-confusing-arrow.js +1 -1
- package/lib/rules/no-console.js +1 -1
- package/lib/rules/no-const-assign.js +1 -1
- package/lib/rules/no-dupe-keys.js +1 -1
- package/lib/rules/no-else-return.js +1 -1
- package/lib/rules/no-empty-function.js +1 -1
- package/lib/rules/no-empty.js +1 -1
- package/lib/rules/no-eval.js +1 -1
- package/lib/rules/no-ex-assign.js +1 -1
- package/lib/rules/no-extend-native.js +1 -1
- package/lib/rules/no-extra-bind.js +1 -1
- package/lib/rules/no-extra-boolean-cast.js +1 -1
- package/lib/rules/no-extra-label.js +1 -1
- package/lib/rules/no-extra-parens.js +2 -2
- package/lib/rules/no-extra-semi.js +1 -1
- package/lib/rules/no-floating-decimal.js +1 -1
- package/lib/rules/no-func-assign.js +1 -1
- package/lib/rules/no-implicit-coercion.js +1 -1
- package/lib/rules/no-inline-comments.js +1 -1
- package/lib/rules/no-invalid-this.js +1 -1
- package/lib/rules/no-irregular-whitespace.js +1 -1
- package/lib/rules/no-label-var.js +1 -1
- package/lib/rules/no-labels.js +1 -1
- package/lib/rules/no-magic-numbers.js +7 -3
- package/lib/rules/no-misleading-character-class.js +189 -0
- package/lib/rules/no-mixed-operators.js +1 -1
- package/lib/rules/no-multi-spaces.js +1 -1
- package/lib/rules/no-multi-str.js +1 -1
- package/lib/rules/no-regex-spaces.js +1 -1
- package/lib/rules/no-restricted-globals.js +1 -1
- package/lib/rules/no-restricted-imports.js +1 -1
- package/lib/rules/no-restricted-modules.js +1 -1
- package/lib/rules/no-restricted-properties.js +1 -1
- package/lib/rules/no-return-assign.js +1 -1
- package/lib/rules/no-return-await.js +1 -1
- package/lib/rules/no-self-assign.js +1 -1
- package/lib/rules/no-sequences.js +1 -1
- package/lib/rules/no-shadow.js +1 -1
- package/lib/rules/no-this-before-super.js +1 -1
- package/lib/rules/no-throw-literal.js +1 -1
- package/lib/rules/no-trailing-spaces.js +1 -1
- package/lib/rules/no-undef-init.js +1 -1
- package/lib/rules/no-unexpected-multiline.js +1 -1
- package/lib/rules/no-unmodified-loop-condition.js +2 -3
- package/lib/rules/no-unneeded-ternary.js +1 -1
- package/lib/rules/no-unsafe-negation.js +1 -1
- package/lib/rules/no-unused-vars.js +1 -1
- package/lib/rules/no-useless-call.js +1 -1
- package/lib/rules/no-useless-computed-key.js +1 -1
- package/lib/rules/no-useless-concat.js +1 -1
- package/lib/rules/no-useless-escape.js +1 -1
- package/lib/rules/no-useless-return.js +2 -11
- package/lib/rules/no-var.js +1 -1
- package/lib/rules/no-warning-comments.js +1 -1
- package/lib/rules/no-whitespace-before-property.js +1 -1
- package/lib/rules/object-curly-newline.js +1 -1
- package/lib/rules/object-curly-spacing.js +1 -1
- package/lib/rules/object-shorthand.js +1 -1
- package/lib/rules/one-var.js +6 -6
- package/lib/rules/operator-assignment.js +1 -1
- package/lib/rules/operator-linebreak.js +1 -1
- package/lib/rules/padded-blocks.js +6 -6
- package/lib/rules/padding-line-between-statements.js +2 -2
- package/lib/rules/prefer-const.js +2 -11
- package/lib/rules/prefer-object-spread.js +9 -3
- package/lib/rules/prefer-promise-reject-errors.js +1 -1
- package/lib/rules/prefer-reflect.js +1 -1
- package/lib/rules/prefer-spread.js +1 -1
- package/lib/rules/prefer-template.js +1 -1
- package/lib/rules/quotes.js +1 -1
- package/lib/rules/radix.js +1 -1
- package/lib/rules/require-atomic-updates.js +239 -0
- package/lib/rules/require-await.js +1 -1
- package/lib/rules/require-unicode-regexp.js +65 -0
- package/lib/rules/semi-spacing.js +3 -3
- package/lib/rules/semi-style.js +1 -1
- package/lib/rules/semi.js +1 -1
- package/lib/rules/sort-keys.js +1 -1
- package/lib/rules/space-before-blocks.js +1 -1
- package/lib/rules/space-before-function-paren.js +1 -1
- package/lib/rules/space-in-parens.js +1 -1
- package/lib/rules/space-unary-ops.js +2 -2
- package/lib/rules/spaced-comment.js +1 -1
- package/lib/rules/strict.js +1 -1
- package/lib/rules/switch-colon-spacing.js +1 -1
- package/lib/rules/symbol-description.js +1 -1
- package/lib/rules/template-curly-spacing.js +1 -1
- package/lib/rules/valid-jsdoc.js +1 -1
- package/lib/rules/wrap-iife.js +1 -1
- package/lib/rules/yoda.js +1 -1
- package/lib/testers/rule-tester.js +8 -10
- package/lib/token-store/index.js +1 -1
- package/lib/{ast-utils.js → util/ast-utils.js} +0 -0
- package/lib/{file-finder.js → util/file-finder.js} +2 -2
- package/lib/util/fix-tracker.js +1 -1
- package/lib/util/{glob-util.js → glob-utils.js} +4 -4
- package/lib/util/lint-result-cache.js +146 -0
- package/lib/{logging.js → util/logging.js} +0 -0
- package/lib/util/naming.js +2 -2
- package/lib/util/node-event-generator.js +3 -3
- package/lib/util/{npm-util.js → npm-utils.js} +1 -1
- package/lib/util/{path-util.js → path-utils.js} +1 -1
- package/lib/util/source-code-fixer.js +1 -1
- package/lib/util/{source-code-util.js → source-code-utils.js} +3 -3
- package/lib/util/source-code.js +1 -1
- package/lib/{timing.js → util/timing.js} +0 -0
- package/lib/util/unicode/index.js +11 -0
- package/lib/util/unicode/is-combining-character.js +13 -0
- package/lib/util/unicode/is-emoji-modifier.js +13 -0
- package/lib/util/unicode/is-regional-indicator-symbol.js +13 -0
- package/lib/util/unicode/is-surrogate-pair.js +14 -0
- package/package.json +14 -15
- package/lib/rules/.eslintrc.yml +0 -4
package/lib/rules/func-names.js
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("../ast-utils");
|
12
|
+
const astUtils = require("../util/ast-utils");
|
13
13
|
|
14
14
|
/**
|
15
15
|
* Checks whether or not a given variable is a function name.
|
@@ -37,7 +37,11 @@ module.exports = {
|
|
37
37
|
{
|
38
38
|
enum: ["always", "as-needed", "never"]
|
39
39
|
}
|
40
|
-
]
|
40
|
+
],
|
41
|
+
messages: {
|
42
|
+
unnamed: "Unexpected unnamed {{name}}.",
|
43
|
+
named: "Unexpected named {{name}}."
|
44
|
+
}
|
41
45
|
},
|
42
46
|
|
43
47
|
create(context) {
|
@@ -96,7 +100,7 @@ module.exports = {
|
|
96
100
|
if (hasName) {
|
97
101
|
context.report({
|
98
102
|
node,
|
99
|
-
|
103
|
+
messageId: "named",
|
100
104
|
data: { name }
|
101
105
|
});
|
102
106
|
}
|
@@ -104,7 +108,7 @@ module.exports = {
|
|
104
108
|
if (!hasName && (asNeeded ? !hasInferredName(node) : !isObjectOrClassMethod(node))) {
|
105
109
|
context.report({
|
106
110
|
node,
|
107
|
-
|
111
|
+
messageId: "unnamed",
|
108
112
|
data: { name }
|
109
113
|
});
|
110
114
|
}
|
package/lib/rules/func-style.js
CHANGED
@@ -30,7 +30,11 @@ module.exports = {
|
|
30
30
|
},
|
31
31
|
additionalProperties: false
|
32
32
|
}
|
33
|
-
]
|
33
|
+
],
|
34
|
+
messages: {
|
35
|
+
expression: "Expected a function expression.",
|
36
|
+
declaration: "Expected a function declaration."
|
37
|
+
}
|
34
38
|
},
|
35
39
|
|
36
40
|
create(context) {
|
@@ -45,7 +49,7 @@ module.exports = {
|
|
45
49
|
stack.push(false);
|
46
50
|
|
47
51
|
if (!enforceDeclarations && node.parent.type !== "ExportDefaultDeclaration") {
|
48
|
-
context.report({ node,
|
52
|
+
context.report({ node, messageId: "expression" });
|
49
53
|
}
|
50
54
|
},
|
51
55
|
"FunctionDeclaration:exit"() {
|
@@ -56,7 +60,7 @@ module.exports = {
|
|
56
60
|
stack.push(false);
|
57
61
|
|
58
62
|
if (enforceDeclarations && node.parent.type === "VariableDeclarator") {
|
59
|
-
context.report({ node: node.parent,
|
63
|
+
context.report({ node: node.parent, messageId: "declaration" });
|
60
64
|
}
|
61
65
|
},
|
62
66
|
"FunctionExpression:exit"() {
|
@@ -79,7 +83,7 @@ module.exports = {
|
|
79
83
|
const hasThisExpr = stack.pop();
|
80
84
|
|
81
85
|
if (enforceDeclarations && !hasThisExpr && node.parent.type === "VariableDeclarator") {
|
82
|
-
context.report({ node: node.parent,
|
86
|
+
context.report({ node: node.parent, messageId: "declaration" });
|
83
87
|
}
|
84
88
|
};
|
85
89
|
}
|
@@ -8,7 +8,7 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const astUtils = require("../ast-utils");
|
11
|
+
const astUtils = require("../util/ast-utils");
|
12
12
|
|
13
13
|
//------------------------------------------------------------------------------
|
14
14
|
// Rule Definition
|
@@ -41,7 +41,13 @@ module.exports = {
|
|
41
41
|
}
|
42
42
|
]
|
43
43
|
}
|
44
|
-
]
|
44
|
+
],
|
45
|
+
messages: {
|
46
|
+
expectedBefore: "Expected newline before ')'.",
|
47
|
+
expectedAfter: "Expected newline after '('.",
|
48
|
+
unexpectedBefore: "Unexpected newline before '('.",
|
49
|
+
unexpectedAfter: "Unexpected newline after ')'."
|
50
|
+
}
|
45
51
|
},
|
46
52
|
|
47
53
|
create(context) {
|
@@ -99,7 +105,7 @@ module.exports = {
|
|
99
105
|
if (hasLeftNewline && !needsNewlines) {
|
100
106
|
context.report({
|
101
107
|
node: leftParen,
|
102
|
-
|
108
|
+
messageId: "unexpectedAfter",
|
103
109
|
fix(fixer) {
|
104
110
|
return sourceCode.getText().slice(leftParen.range[1], tokenAfterLeftParen.range[0]).trim()
|
105
111
|
|
@@ -111,7 +117,7 @@ module.exports = {
|
|
111
117
|
} else if (!hasLeftNewline && needsNewlines) {
|
112
118
|
context.report({
|
113
119
|
node: leftParen,
|
114
|
-
|
120
|
+
messageId: "expectedAfter",
|
115
121
|
fix: fixer => fixer.insertTextAfter(leftParen, "\n")
|
116
122
|
});
|
117
123
|
}
|
@@ -119,7 +125,7 @@ module.exports = {
|
|
119
125
|
if (hasRightNewline && !needsNewlines) {
|
120
126
|
context.report({
|
121
127
|
node: rightParen,
|
122
|
-
|
128
|
+
messageId: "unexpectedBefore",
|
123
129
|
fix(fixer) {
|
124
130
|
return sourceCode.getText().slice(tokenBeforeRightParen.range[1], rightParen.range[0]).trim()
|
125
131
|
|
@@ -131,7 +137,7 @@ module.exports = {
|
|
131
137
|
} else if (!hasRightNewline && needsNewlines) {
|
132
138
|
context.report({
|
133
139
|
node: rightParen,
|
134
|
-
|
140
|
+
messageId: "expectedBefore",
|
135
141
|
fix: fixer => fixer.insertTextBefore(rightParen, "\n")
|
136
142
|
});
|
137
143
|
}
|
@@ -55,7 +55,13 @@ module.exports = {
|
|
55
55
|
}
|
56
56
|
]
|
57
57
|
}
|
58
|
-
]
|
58
|
+
],
|
59
|
+
messages: {
|
60
|
+
missingBefore: "Missing space before *.",
|
61
|
+
missingAfter: "Missing space after *.",
|
62
|
+
unexpectedBefore: "Unexpected space before *.",
|
63
|
+
unexpectedAfter: "Unexpected space after *."
|
64
|
+
}
|
59
65
|
},
|
60
66
|
|
61
67
|
create(context) {
|
@@ -119,6 +125,15 @@ module.exports = {
|
|
119
125
|
);
|
120
126
|
}
|
121
127
|
|
128
|
+
/**
|
129
|
+
* capitalize a given string.
|
130
|
+
* @param {string} str the given string.
|
131
|
+
* @returns {string} the capitalized string.
|
132
|
+
*/
|
133
|
+
function capitalize(str) {
|
134
|
+
return str[0].toUpperCase() + str.slice(1);
|
135
|
+
}
|
136
|
+
|
122
137
|
/**
|
123
138
|
* Checks the spacing between two tokens before or after the star token.
|
124
139
|
*
|
@@ -135,17 +150,11 @@ module.exports = {
|
|
135
150
|
const after = leftToken.value === "*";
|
136
151
|
const spaceRequired = modes[kind][side];
|
137
152
|
const node = after ? leftToken : rightToken;
|
138
|
-
const
|
139
|
-
const message = "{{type}} space {{side}} *.";
|
140
|
-
const data = {
|
141
|
-
type,
|
142
|
-
side
|
143
|
-
};
|
153
|
+
const messageId = `${spaceRequired ? "missing" : "unexpected"}${capitalize(side)}`;
|
144
154
|
|
145
155
|
context.report({
|
146
156
|
node,
|
147
|
-
|
148
|
-
data,
|
157
|
+
messageId,
|
149
158
|
fix(fixer) {
|
150
159
|
if (spaceRequired) {
|
151
160
|
if (after) {
|
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("../ast-utils");
|
12
|
+
const astUtils = require("../util/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Helpers
|
@@ -61,7 +61,11 @@ module.exports = {
|
|
61
61
|
},
|
62
62
|
additionalProperties: false
|
63
63
|
}
|
64
|
-
]
|
64
|
+
],
|
65
|
+
messages: {
|
66
|
+
expected: "Expected to return a value in {{name}}.",
|
67
|
+
expectedAlways: "Expected {{name}} to always return a value."
|
68
|
+
}
|
65
69
|
},
|
66
70
|
|
67
71
|
create(context) {
|
@@ -93,9 +97,7 @@ module.exports = {
|
|
93
97
|
context.report({
|
94
98
|
node,
|
95
99
|
loc: getId(node).loc.start,
|
96
|
-
|
97
|
-
? "Expected {{name}} to always return a value."
|
98
|
-
: "Expected to return a value in {{name}}.",
|
100
|
+
messageId: funcInfo.hasReturn ? "expectedAlways" : "expected",
|
99
101
|
data: {
|
100
102
|
name: astUtils.getFunctionNameWithKind(funcInfo.node)
|
101
103
|
}
|
@@ -161,7 +163,7 @@ module.exports = {
|
|
161
163
|
if (!options.allowImplicit && !node.argument) {
|
162
164
|
context.report({
|
163
165
|
node,
|
164
|
-
|
166
|
+
messageId: "expected",
|
165
167
|
data: {
|
166
168
|
name: astUtils.getFunctionNameWithKind(funcInfo.node)
|
167
169
|
}
|
@@ -12,7 +12,7 @@
|
|
12
12
|
// Requirements
|
13
13
|
//------------------------------------------------------------------------------
|
14
14
|
|
15
|
-
const astUtils = require("../ast-utils");
|
15
|
+
const astUtils = require("../util/ast-utils");
|
16
16
|
|
17
17
|
//------------------------------------------------------------------------------
|
18
18
|
// Rule Definition
|
package/lib/rules/indent.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* @fileoverview This
|
2
|
+
* @fileoverview This rule sets a specific indentation style and width for your code
|
3
3
|
*
|
4
4
|
* @author Teddy Katz
|
5
5
|
* @author Vitaly Puzrin
|
@@ -13,7 +13,7 @@
|
|
13
13
|
//------------------------------------------------------------------------------
|
14
14
|
|
15
15
|
const lodash = require("lodash");
|
16
|
-
const astUtils = require("../ast-utils");
|
16
|
+
const astUtils = require("../util/ast-utils");
|
17
17
|
const createTree = require("functional-red-black-tree");
|
18
18
|
|
19
19
|
//------------------------------------------------------------------------------
|
@@ -855,7 +855,11 @@ module.exports = {
|
|
855
855
|
previousElement &&
|
856
856
|
previousElementLastToken.loc.end.line - countTrailingLinebreaks(previousElementLastToken.value) > startToken.loc.end.line
|
857
857
|
) {
|
858
|
-
offsets.setDesiredOffsets(
|
858
|
+
offsets.setDesiredOffsets(
|
859
|
+
[previousElement.range[1], element.range[1]],
|
860
|
+
firstTokenOfPreviousElement,
|
861
|
+
0
|
862
|
+
);
|
859
863
|
}
|
860
864
|
}
|
861
865
|
});
|
@@ -997,6 +1001,31 @@ module.exports = {
|
|
997
1001
|
return !node || node.loc.start.line === token.loc.start.line;
|
998
1002
|
}
|
999
1003
|
|
1004
|
+
/**
|
1005
|
+
* Check whether there are any blank (whitespace-only) lines between
|
1006
|
+
* two tokens on separate lines.
|
1007
|
+
* @param {Token} firstToken The first token.
|
1008
|
+
* @param {Token} secondToken The second token.
|
1009
|
+
* @returns {boolean} `true` if the tokens are on separate lines and
|
1010
|
+
* there exists a blank line between them, `false` otherwise.
|
1011
|
+
*/
|
1012
|
+
function hasBlankLinesBetween(firstToken, secondToken) {
|
1013
|
+
const firstTokenLine = firstToken.loc.end.line;
|
1014
|
+
const secondTokenLine = secondToken.loc.start.line;
|
1015
|
+
|
1016
|
+
if (firstTokenLine === secondTokenLine || firstTokenLine === secondTokenLine - 1) {
|
1017
|
+
return false;
|
1018
|
+
}
|
1019
|
+
|
1020
|
+
for (let line = firstTokenLine + 1; line < secondTokenLine; ++line) {
|
1021
|
+
if (!tokenInfo.firstTokensByLineNumber.has(line)) {
|
1022
|
+
return true;
|
1023
|
+
}
|
1024
|
+
}
|
1025
|
+
|
1026
|
+
return false;
|
1027
|
+
}
|
1028
|
+
|
1000
1029
|
const ignoredNodeFirstTokens = new Set();
|
1001
1030
|
|
1002
1031
|
const baseOffsetListeners = {
|
@@ -1304,7 +1333,9 @@ module.exports = {
|
|
1304
1333
|
node.expressions.forEach((expression, index) => {
|
1305
1334
|
const previousQuasi = node.quasis[index];
|
1306
1335
|
const nextQuasi = node.quasis[index + 1];
|
1307
|
-
const tokenToAlignFrom = previousQuasi.loc.start.line === previousQuasi.loc.end.line
|
1336
|
+
const tokenToAlignFrom = previousQuasi.loc.start.line === previousQuasi.loc.end.line
|
1337
|
+
? sourceCode.getFirstToken(previousQuasi)
|
1338
|
+
: null;
|
1308
1339
|
|
1309
1340
|
offsets.setDesiredOffsets([previousQuasi.range[1], nextQuasi.range[0]], tokenToAlignFrom, 1);
|
1310
1341
|
offsets.setDesiredOffset(sourceCode.getFirstToken(nextQuasi), tokenToAlignFrom, 0);
|
@@ -1312,7 +1343,9 @@ module.exports = {
|
|
1312
1343
|
},
|
1313
1344
|
|
1314
1345
|
VariableDeclaration(node) {
|
1315
|
-
const variableIndent =
|
1346
|
+
const variableIndent = Object.prototype.hasOwnProperty.call(options.VariableDeclarator, node.kind)
|
1347
|
+
? options.VariableDeclarator[node.kind]
|
1348
|
+
: DEFAULT_VARIABLE_INDENT;
|
1316
1349
|
|
1317
1350
|
if (node.declarations[node.declarations.length - 1].loc.start.line > node.loc.start.line) {
|
1318
1351
|
|
@@ -1536,10 +1569,13 @@ module.exports = {
|
|
1536
1569
|
const tokenBefore = precedingTokens.get(firstTokenOfLine);
|
1537
1570
|
const tokenAfter = tokenBefore ? sourceCode.getTokenAfter(tokenBefore) : sourceCode.ast.tokens[0];
|
1538
1571
|
|
1572
|
+
const mayAlignWithBefore = tokenBefore && !hasBlankLinesBetween(tokenBefore, firstTokenOfLine);
|
1573
|
+
const mayAlignWithAfter = tokenAfter && !hasBlankLinesBetween(firstTokenOfLine, tokenAfter);
|
1574
|
+
|
1539
1575
|
// If a comment matches the expected indentation of the token immediately before or after, don't report it.
|
1540
1576
|
if (
|
1541
|
-
|
1542
|
-
|
1577
|
+
mayAlignWithBefore && validateTokenIndent(firstTokenOfLine, offsets.getDesiredIndent(tokenBefore)) ||
|
1578
|
+
mayAlignWithAfter && validateTokenIndent(firstTokenOfLine, offsets.getDesiredIndent(tokenAfter))
|
1543
1579
|
) {
|
1544
1580
|
return;
|
1545
1581
|
}
|
package/lib/rules/jsx-quotes.js
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("../ast-utils");
|
12
|
+
const astUtils = require("../util/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Constants
|
package/lib/rules/key-spacing.js
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const astUtils = require("../ast-utils");
|
11
|
+
const astUtils = require("../util/ast-utils");
|
12
12
|
|
13
13
|
//------------------------------------------------------------------------------
|
14
14
|
// Helpers
|
@@ -540,7 +540,7 @@ module.exports = {
|
|
540
540
|
const length = properties.length,
|
541
541
|
widths = properties.map(getKeyWidth), // Width of keys, including quotes
|
542
542
|
align = alignmentOptions.on; // "value" or "colon"
|
543
|
-
let targetWidth = Math.max
|
543
|
+
let targetWidth = Math.max(...widths),
|
544
544
|
beforeColon, afterColon, mode;
|
545
545
|
|
546
546
|
if (alignmentOptions && length > 1) { // When aligning values within a group, use the alignment configuration.
|
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("../ast-utils"),
|
12
|
+
const astUtils = require("../util/ast-utils"),
|
13
13
|
keywords = require("../util/keywords");
|
14
14
|
|
15
15
|
//------------------------------------------------------------------------------
|
@@ -4,7 +4,7 @@
|
|
4
4
|
*/
|
5
5
|
"use strict";
|
6
6
|
|
7
|
-
const astUtils = require("../ast-utils");
|
7
|
+
const astUtils = require("../util/ast-utils");
|
8
8
|
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
// Rule Definition
|
@@ -59,10 +59,10 @@ module.exports = {
|
|
59
59
|
above = !options || options === "above";
|
60
60
|
|
61
61
|
} else {
|
62
|
-
above = options.position === "above";
|
62
|
+
above = !options.position || options.position === "above";
|
63
63
|
ignorePattern = options.ignorePattern;
|
64
64
|
|
65
|
-
if (
|
65
|
+
if (Object.prototype.hasOwnProperty.call(options, "applyDefaultIgnorePatterns")) {
|
66
66
|
applyDefaultIgnorePatterns = options.applyDefaultIgnorePatterns !== false;
|
67
67
|
} else {
|
68
68
|
applyDefaultIgnorePatterns = options.applyDefaultPatterns !== false;
|
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("../ast-utils");
|
12
|
+
const astUtils = require("../util/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Rule Definition
|
@@ -9,7 +9,7 @@
|
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
11
|
const lodash = require("lodash"),
|
12
|
-
astUtils = require("../ast-utils");
|
12
|
+
astUtils = require("../util/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Helpers
|
package/lib/rules/max-depth.js
CHANGED
@@ -54,10 +54,10 @@ module.exports = {
|
|
54
54
|
option = context.options[0];
|
55
55
|
let maxDepth = 4;
|
56
56
|
|
57
|
-
if (typeof option === "object" &&
|
57
|
+
if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "maximum") && typeof option.maximum === "number") {
|
58
58
|
maxDepth = option.maximum;
|
59
59
|
}
|
60
|
-
if (typeof option === "object" &&
|
60
|
+
if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "max") && typeof option.max === "number") {
|
61
61
|
maxDepth = option.max;
|
62
62
|
}
|
63
63
|
if (typeof option === "number") {
|
package/lib/rules/max-len.js
CHANGED
@@ -266,7 +266,7 @@ module.exports = {
|
|
266
266
|
// list of comments to ignore
|
267
267
|
comments = ignoreComments || maxCommentLength || ignoreTrailingComments ? sourceCode.getAllComments() : [];
|
268
268
|
|
269
|
-
|
269
|
+
// we iterate over comments in parallel with the lines
|
270
270
|
let commentsIndex = 0;
|
271
271
|
|
272
272
|
const strings = getAllStrings();
|
@@ -8,7 +8,7 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const astUtils = require("../ast-utils");
|
11
|
+
const astUtils = require("../util/ast-utils");
|
12
12
|
|
13
13
|
//------------------------------------------------------------------------------
|
14
14
|
// Constants
|
package/lib/rules/max-lines.js
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
11
|
const lodash = require("lodash");
|
12
|
-
const astUtils = require("../ast-utils");
|
12
|
+
const astUtils = require("../util/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Rule Definition
|
@@ -56,7 +56,7 @@ module.exports = {
|
|
56
56
|
const option = context.options[0];
|
57
57
|
let max = 300;
|
58
58
|
|
59
|
-
if (typeof option === "object" &&
|
59
|
+
if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "max") && typeof option.max === "number") {
|
60
60
|
max = option.max;
|
61
61
|
}
|
62
62
|
|
@@ -52,10 +52,10 @@ module.exports = {
|
|
52
52
|
const option = context.options[0];
|
53
53
|
let THRESHOLD = 10;
|
54
54
|
|
55
|
-
if (typeof option === "object" &&
|
55
|
+
if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "maximum") && typeof option.maximum === "number") {
|
56
56
|
THRESHOLD = option.maximum;
|
57
57
|
}
|
58
|
-
if (typeof option === "object" &&
|
58
|
+
if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "max") && typeof option.max === "number") {
|
59
59
|
THRESHOLD = option.max;
|
60
60
|
}
|
61
61
|
if (typeof option === "number") {
|
package/lib/rules/max-params.js
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
|
12
12
|
const lodash = require("lodash");
|
13
13
|
|
14
|
-
const astUtils = require("../ast-utils");
|
14
|
+
const astUtils = require("../util/ast-utils");
|
15
15
|
|
16
16
|
//------------------------------------------------------------------------------
|
17
17
|
// Rule Definition
|
@@ -53,14 +53,14 @@ module.exports = {
|
|
53
53
|
},
|
54
54
|
|
55
55
|
create(context) {
|
56
|
-
|
56
|
+
const sourceCode = context.getSourceCode();
|
57
57
|
const option = context.options[0];
|
58
58
|
let numParams = 3;
|
59
59
|
|
60
|
-
if (typeof option === "object" &&
|
60
|
+
if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "maximum") && typeof option.maximum === "number") {
|
61
61
|
numParams = option.maximum;
|
62
62
|
}
|
63
|
-
if (typeof option === "object" &&
|
63
|
+
if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "max") && typeof option.max === "number") {
|
64
64
|
numParams = option.max;
|
65
65
|
}
|
66
66
|
if (typeof option === "number") {
|
@@ -76,6 +76,7 @@ module.exports = {
|
|
76
76
|
function checkFunction(node) {
|
77
77
|
if (node.params.length > numParams) {
|
78
78
|
context.report({
|
79
|
+
loc: astUtils.getFunctionHeadLoc(node, sourceCode),
|
79
80
|
node,
|
80
81
|
message: "{{name}} has too many parameters ({{count}}). Maximum allowed is {{max}}.",
|
81
82
|
data: {
|
@@ -8,7 +8,7 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const astUtils = require("../ast-utils");
|
11
|
+
const astUtils = require("../util/ast-utils");
|
12
12
|
|
13
13
|
//------------------------------------------------------------------------------
|
14
14
|
// Rule Definition
|
@@ -11,7 +11,7 @@
|
|
11
11
|
|
12
12
|
const lodash = require("lodash");
|
13
13
|
|
14
|
-
const astUtils = require("../ast-utils");
|
14
|
+
const astUtils = require("../util/ast-utils");
|
15
15
|
|
16
16
|
//------------------------------------------------------------------------------
|
17
17
|
// Rule Definition
|
@@ -73,10 +73,10 @@ module.exports = {
|
|
73
73
|
topLevelFunctions = [];
|
74
74
|
let maxStatements = 10;
|
75
75
|
|
76
|
-
if (typeof option === "object" &&
|
76
|
+
if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "maximum") && typeof option.maximum === "number") {
|
77
77
|
maxStatements = option.maximum;
|
78
78
|
}
|
79
|
-
if (typeof option === "object" &&
|
79
|
+
if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "max") && typeof option.max === "number") {
|
80
80
|
maxStatements = option.max;
|
81
81
|
}
|
82
82
|
if (typeof option === "number") {
|
package/lib/rules/new-parens.js
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("../ast-utils");
|
12
|
+
const astUtils = require("../util/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Helpers
|
@@ -10,7 +10,7 @@
|
|
10
10
|
// Requirements
|
11
11
|
//------------------------------------------------------------------------------
|
12
12
|
|
13
|
-
const astUtils = require("../ast-utils");
|
13
|
+
const astUtils = require("../util/ast-utils");
|
14
14
|
|
15
15
|
//------------------------------------------------------------------------------
|
16
16
|
// Rule Definition
|
package/lib/rules/no-alert.js
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const getPropertyName = require("../ast-utils").getStaticPropertyName;
|
11
|
+
const getPropertyName = require("../util/ast-utils").getStaticPropertyName;
|
12
12
|
|
13
13
|
//------------------------------------------------------------------------------
|
14
14
|
// Helpers
|