eslint 6.5.0 → 6.7.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 +115 -0
- package/README.md +10 -9
- package/conf/config-schema.js +1 -0
- package/conf/default-cli-options.js +1 -1
- package/lib/cli-engine/cascading-config-array-factory.js +40 -14
- package/lib/cli-engine/cli-engine.js +49 -21
- package/lib/cli-engine/config-array/config-array.js +13 -4
- package/lib/cli-engine/config-array/config-dependency.js +2 -0
- package/lib/cli-engine/config-array/extracted-config.js +27 -0
- package/lib/cli-engine/config-array/ignore-pattern.js +231 -0
- package/lib/cli-engine/config-array/index.js +2 -0
- package/lib/cli-engine/config-array/override-tester.js +2 -0
- package/lib/cli-engine/config-array-factory.js +120 -2
- package/lib/cli-engine/file-enumerator.js +51 -30
- package/lib/cli-engine/formatters/html.js +1 -0
- package/lib/init/autoconfig.js +1 -11
- package/lib/init/config-file.js +0 -1
- package/lib/init/config-initializer.js +4 -4
- package/lib/init/config-rule.js +1 -5
- package/lib/init/npm-utils.js +0 -5
- package/lib/linter/code-path-analysis/code-path-analyzer.js +24 -38
- package/lib/linter/code-path-analysis/code-path-segment.js +17 -25
- package/lib/linter/code-path-analysis/code-path-state.js +40 -81
- package/lib/linter/code-path-analysis/code-path.js +10 -11
- package/lib/linter/code-path-analysis/debug-helpers.js +8 -12
- package/lib/linter/code-path-analysis/fork-context.js +23 -34
- package/lib/linter/code-path-analysis/id-generator.js +2 -2
- package/lib/linter/linter.js +121 -95
- package/lib/linter/node-event-generator.js +3 -2
- package/lib/linter/report-translator.js +73 -7
- package/lib/rule-tester/rule-tester.js +46 -14
- package/lib/rules/accessor-pairs.js +8 -8
- package/lib/rules/array-bracket-newline.js +12 -15
- package/lib/rules/array-bracket-spacing.js +12 -12
- package/lib/rules/array-callback-return.js +6 -11
- package/lib/rules/array-element-newline.js +5 -8
- package/lib/rules/arrow-parens.js +0 -1
- package/lib/rules/block-scoped-var.js +3 -3
- package/lib/rules/block-spacing.js +4 -4
- package/lib/rules/camelcase.js +19 -6
- package/lib/rules/capitalized-comments.js +0 -7
- package/lib/rules/class-methods-use-this.js +3 -3
- package/lib/rules/comma-dangle.js +20 -25
- package/lib/rules/comma-spacing.js +1 -1
- package/lib/rules/computed-property-spacing.js +14 -14
- package/lib/rules/consistent-return.js +4 -5
- package/lib/rules/consistent-this.js +5 -5
- package/lib/rules/constructor-super.js +14 -16
- package/lib/rules/curly.js +12 -9
- package/lib/rules/default-param-last.js +1 -0
- package/lib/rules/dot-location.js +11 -12
- package/lib/rules/func-names.js +6 -6
- package/lib/rules/function-call-argument-newline.js +8 -6
- package/lib/rules/generator-star-spacing.js +4 -9
- package/lib/rules/getter-return.js +4 -7
- package/lib/rules/grouped-accessor-pairs.js +224 -0
- package/lib/rules/indent.js +13 -2
- package/lib/rules/index.js +5 -0
- package/lib/rules/init-declarations.js +2 -2
- package/lib/rules/jsx-quotes.js +1 -1
- package/lib/rules/keyword-spacing.js +32 -56
- package/lib/rules/lines-around-directive.js +1 -1
- package/lib/rules/max-len.js +0 -5
- package/lib/rules/max-statements-per-line.js +3 -7
- package/lib/rules/multiline-comment-style.js +237 -106
- package/lib/rules/multiline-ternary.js +3 -3
- package/lib/rules/newline-after-var.js +6 -7
- package/lib/rules/newline-before-return.js +8 -9
- package/lib/rules/newline-per-chained-call.js +2 -4
- package/lib/rules/no-class-assign.js +2 -2
- package/lib/rules/no-compare-neg-zero.js +1 -2
- package/lib/rules/no-cond-assign.js +14 -4
- package/lib/rules/no-confusing-arrow.js +2 -2
- package/lib/rules/no-console.js +4 -8
- package/lib/rules/no-const-assign.js +1 -1
- package/lib/rules/no-constructor-return.js +62 -0
- package/lib/rules/no-dupe-args.js +1 -1
- package/lib/rules/no-dupe-class-members.js +3 -4
- package/lib/rules/no-dupe-else-if.js +122 -0
- package/lib/rules/no-dupe-keys.js +6 -5
- package/lib/rules/no-duplicate-imports.js +14 -18
- package/lib/rules/no-else-return.js +0 -8
- package/lib/rules/no-empty-function.js +2 -4
- package/lib/rules/no-eval.js +10 -18
- package/lib/rules/no-ex-assign.js +1 -1
- package/lib/rules/no-extra-bind.js +5 -12
- package/lib/rules/no-extra-boolean-cast.js +0 -2
- package/lib/rules/no-extra-label.js +4 -9
- package/lib/rules/no-extra-parens.js +17 -15
- package/lib/rules/no-extra-semi.js +5 -6
- package/lib/rules/no-fallthrough.js +6 -6
- package/lib/rules/no-func-assign.js +3 -3
- package/lib/rules/no-global-assign.js +4 -4
- package/lib/rules/no-implicit-coercion.js +10 -10
- package/lib/rules/no-implicit-globals.js +90 -8
- package/lib/rules/no-implied-eval.js +0 -1
- package/lib/rules/no-inline-comments.js +25 -11
- package/lib/rules/no-invalid-this.js +17 -5
- package/lib/rules/no-labels.js +3 -6
- package/lib/rules/no-lone-blocks.js +1 -1
- package/lib/rules/no-loop-func.js +6 -11
- package/lib/rules/no-magic-numbers.js +6 -6
- package/lib/rules/no-misleading-character-class.js +14 -7
- package/lib/rules/no-mixed-operators.js +13 -22
- package/lib/rules/no-mixed-requires.js +0 -1
- package/lib/rules/no-multi-spaces.js +1 -1
- package/lib/rules/no-native-reassign.js +4 -4
- package/lib/rules/no-octal-escape.js +1 -1
- package/lib/rules/no-param-reassign.js +28 -7
- package/lib/rules/no-redeclare.js +1 -1
- package/lib/rules/no-regex-spaces.js +0 -1
- package/lib/rules/no-restricted-imports.js +11 -11
- package/lib/rules/no-self-assign.js +12 -13
- package/lib/rules/no-sequences.js +3 -3
- package/lib/rules/no-setter-return.js +227 -0
- package/lib/rules/no-shadow.js +1 -4
- package/lib/rules/no-tabs.js +8 -2
- package/lib/rules/no-this-before-super.js +12 -13
- package/lib/rules/no-trailing-spaces.js +19 -7
- package/lib/rules/no-underscore-dangle.js +23 -4
- package/lib/rules/no-unmodified-loop-condition.js +16 -29
- package/lib/rules/no-unneeded-ternary.js +3 -3
- package/lib/rules/no-unreachable.js +7 -7
- package/lib/rules/no-unsafe-finally.js +4 -7
- package/lib/rules/no-unsafe-negation.js +32 -9
- package/lib/rules/no-unused-expressions.js +11 -7
- package/lib/rules/no-unused-labels.js +3 -6
- package/lib/rules/no-unused-vars.js +22 -29
- package/lib/rules/no-use-before-define.js +10 -15
- package/lib/rules/no-useless-call.js +4 -4
- package/lib/rules/no-useless-computed-key.js +60 -33
- package/lib/rules/no-useless-concat.js +4 -4
- package/lib/rules/no-useless-constructor.js +14 -22
- package/lib/rules/no-useless-escape.js +29 -8
- package/lib/rules/no-useless-rename.js +15 -7
- package/lib/rules/no-useless-return.js +8 -15
- package/lib/rules/no-var.js +12 -25
- package/lib/rules/no-warning-comments.js +0 -1
- package/lib/rules/no-whitespace-before-property.js +3 -3
- package/lib/rules/object-curly-newline.js +7 -10
- package/lib/rules/object-curly-spacing.js +21 -22
- package/lib/rules/object-shorthand.js +1 -1
- package/lib/rules/one-var-declaration-per-line.js +2 -2
- package/lib/rules/operator-assignment.js +33 -3
- package/lib/rules/padded-blocks.js +1 -1
- package/lib/rules/padding-line-between-statements.js +0 -16
- package/lib/rules/prefer-arrow-callback.js +6 -6
- package/lib/rules/prefer-const.js +27 -28
- package/lib/rules/prefer-destructuring.js +1 -7
- package/lib/rules/prefer-exponentiation-operator.js +189 -0
- package/lib/rules/prefer-named-capture-group.js +0 -1
- package/lib/rules/prefer-numeric-literals.js +32 -4
- package/lib/rules/prefer-object-spread.js +7 -7
- package/lib/rules/prefer-rest-params.js +3 -6
- package/lib/rules/prefer-spread.js +4 -4
- package/lib/rules/prefer-template.js +5 -6
- package/lib/rules/quote-props.js +1 -1
- package/lib/rules/quotes.js +5 -6
- package/lib/rules/radix.js +5 -10
- package/lib/rules/require-await.js +10 -5
- package/lib/rules/require-yield.js +2 -2
- package/lib/rules/rest-spread-spacing.js +1 -1
- package/lib/rules/semi.js +6 -3
- package/lib/rules/sort-imports.js +3 -4
- package/lib/rules/sort-keys.js +1 -3
- package/lib/rules/space-before-blocks.js +1 -2
- package/lib/rules/space-in-parens.js +4 -4
- package/lib/rules/space-infix-ops.js +6 -6
- package/lib/rules/spaced-comment.js +20 -22
- package/lib/rules/strict.js +2 -4
- package/lib/rules/symbol-description.js +1 -2
- package/lib/rules/template-curly-spacing.js +2 -2
- package/lib/rules/use-isnan.js +40 -3
- package/lib/rules/utils/ast-utils.js +84 -85
- package/lib/rules/utils/fix-tracker.js +0 -6
- package/lib/rules/utils/lazy-loading-rule-map.js +0 -1
- package/lib/rules/vars-on-top.js +11 -11
- package/lib/shared/config-ops.js +2 -2
- package/lib/shared/runtime-info.js +8 -8
- package/lib/shared/traverser.js +2 -0
- package/lib/shared/types.js +9 -0
- package/lib/source-code/source-code.js +62 -17
- package/lib/source-code/token-store/backward-token-comment-cursor.js +5 -5
- package/lib/source-code/token-store/backward-token-cursor.js +5 -5
- package/lib/source-code/token-store/cursors.js +17 -19
- package/lib/source-code/token-store/decorative-cursor.js +1 -1
- package/lib/source-code/token-store/filter-cursor.js +2 -2
- package/lib/source-code/token-store/forward-token-comment-cursor.js +5 -5
- package/lib/source-code/token-store/forward-token-cursor.js +5 -5
- package/lib/source-code/token-store/index.js +86 -92
- package/lib/source-code/token-store/limit-cursor.js +2 -2
- package/lib/source-code/token-store/padded-token-cursor.js +7 -7
- package/lib/source-code/token-store/skip-cursor.js +2 -2
- package/lib/source-code/token-store/utils.js +9 -13
- package/package.json +9 -7
- package/lib/cli-engine/ignored-paths.js +0 -362
@@ -5,6 +5,12 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
//------------------------------------------------------------------------------
|
9
|
+
// Requirements
|
10
|
+
//------------------------------------------------------------------------------
|
11
|
+
|
12
|
+
const astUtils = require("./utils/ast-utils");
|
13
|
+
|
8
14
|
//------------------------------------------------------------------------------
|
9
15
|
// Helpers
|
10
16
|
//------------------------------------------------------------------------------
|
@@ -94,13 +100,13 @@ module.exports = {
|
|
94
100
|
functionName: sourceCode.getText(node.callee)
|
95
101
|
},
|
96
102
|
fix(fixer) {
|
97
|
-
const newPrefix = prefixMap[node.arguments[1].value];
|
98
|
-
|
99
103
|
if (sourceCode.getCommentsInside(node).length) {
|
100
104
|
return null;
|
101
105
|
}
|
102
106
|
|
103
|
-
|
107
|
+
const replacement = `${prefixMap[node.arguments[1].value]}${node.arguments[0].value}`;
|
108
|
+
|
109
|
+
if (+replacement !== parseInt(node.arguments[0].value, node.arguments[1].value)) {
|
104
110
|
|
105
111
|
/*
|
106
112
|
* If the newly-produced literal would be invalid, (e.g. 0b1234),
|
@@ -108,7 +114,29 @@ module.exports = {
|
|
108
114
|
*/
|
109
115
|
return null;
|
110
116
|
}
|
111
|
-
|
117
|
+
|
118
|
+
const tokenBefore = sourceCode.getTokenBefore(node),
|
119
|
+
tokenAfter = sourceCode.getTokenAfter(node);
|
120
|
+
let prefix = "",
|
121
|
+
suffix = "";
|
122
|
+
|
123
|
+
if (
|
124
|
+
tokenBefore &&
|
125
|
+
tokenBefore.range[1] === node.range[0] &&
|
126
|
+
!astUtils.canTokensBeAdjacent(tokenBefore, replacement)
|
127
|
+
) {
|
128
|
+
prefix = " ";
|
129
|
+
}
|
130
|
+
|
131
|
+
if (
|
132
|
+
tokenAfter &&
|
133
|
+
node.range[1] === tokenAfter.range[0] &&
|
134
|
+
!astUtils.canTokensBeAdjacent(replacement, tokenAfter)
|
135
|
+
) {
|
136
|
+
suffix = " ";
|
137
|
+
}
|
138
|
+
|
139
|
+
return fixer.replaceText(node, `${prefix}${replacement}${suffix}`);
|
112
140
|
}
|
113
141
|
});
|
114
142
|
}
|
@@ -18,7 +18,7 @@ const ANY_SPACE = /\s/u;
|
|
18
18
|
|
19
19
|
/**
|
20
20
|
* Helper that checks if the Object.assign call has array spread
|
21
|
-
* @param {ASTNode} node
|
21
|
+
* @param {ASTNode} node The node that the rule warns on
|
22
22
|
* @returns {boolean} - Returns true if the Object.assign call has array spread
|
23
23
|
*/
|
24
24
|
function hasArraySpread(node) {
|
@@ -28,8 +28,8 @@ function hasArraySpread(node) {
|
|
28
28
|
/**
|
29
29
|
* Helper that checks if the node needs parentheses to be valid JS.
|
30
30
|
* The default is to wrap the node in parentheses to avoid parsing errors.
|
31
|
-
* @param {ASTNode} node
|
32
|
-
* @param {Object} sourceCode
|
31
|
+
* @param {ASTNode} node The node that the rule warns on
|
32
|
+
* @param {Object} sourceCode in context sourcecode object
|
33
33
|
* @returns {boolean} - Returns true if the node needs parentheses
|
34
34
|
*/
|
35
35
|
function needsParens(node, sourceCode) {
|
@@ -51,8 +51,8 @@ function needsParens(node, sourceCode) {
|
|
51
51
|
|
52
52
|
/**
|
53
53
|
* Determines if an argument needs parentheses. The default is to not add parens.
|
54
|
-
* @param {ASTNode} node
|
55
|
-
* @param {Object} sourceCode
|
54
|
+
* @param {ASTNode} node The node to be checked.
|
55
|
+
* @param {Object} sourceCode in context sourcecode object
|
56
56
|
* @returns {boolean} True if the node needs parentheses
|
57
57
|
*/
|
58
58
|
function argNeedsParens(node, sourceCode) {
|
@@ -142,8 +142,8 @@ function getEndWithSpaces(token, sourceCode) {
|
|
142
142
|
|
143
143
|
/**
|
144
144
|
* Autofixes the Object.assign call to use an object spread instead.
|
145
|
-
* @param {ASTNode|null} node
|
146
|
-
* @param {string} sourceCode
|
145
|
+
* @param {ASTNode|null} node The node that the rule warns on, i.e. the Object.assign call
|
146
|
+
* @param {string} sourceCode sourceCode of the Object.assign call
|
147
147
|
* @returns {Function} autofixer - replaces the Object.assign with a spread object.
|
148
148
|
*/
|
149
149
|
function defineFixer(node, sourceCode) {
|
@@ -11,7 +11,7 @@
|
|
11
11
|
|
12
12
|
/**
|
13
13
|
* Gets the variable object of `arguments` which is defined implicitly.
|
14
|
-
* @param {eslint-scope.Scope} scope
|
14
|
+
* @param {eslint-scope.Scope} scope A scope to get.
|
15
15
|
* @returns {eslint-scope.Variable} The found variable object.
|
16
16
|
*/
|
17
17
|
function getVariableOfArguments(scope) {
|
@@ -41,8 +41,7 @@ function getVariableOfArguments(scope) {
|
|
41
41
|
* - arguments[i] .... true // computed member access
|
42
42
|
* - arguments[0] .... true // computed member access
|
43
43
|
* - arguments.length .... false // normal member access
|
44
|
-
*
|
45
|
-
* @param {eslint-scope.Reference} reference - The reference to check.
|
44
|
+
* @param {eslint-scope.Reference} reference The reference to check.
|
46
45
|
* @returns {boolean} `true` if the reference is not normal member access.
|
47
46
|
*/
|
48
47
|
function isNotNormalMemberAccess(reference) {
|
@@ -78,8 +77,7 @@ module.exports = {
|
|
78
77
|
|
79
78
|
/**
|
80
79
|
* Reports a given reference.
|
81
|
-
*
|
82
|
-
* @param {eslint-scope.Reference} reference - A reference to report.
|
80
|
+
* @param {eslint-scope.Reference} reference A reference to report.
|
83
81
|
* @returns {void}
|
84
82
|
*/
|
85
83
|
function report(reference) {
|
@@ -92,7 +90,6 @@ module.exports = {
|
|
92
90
|
|
93
91
|
/**
|
94
92
|
* Reports references of the implicit `arguments` variable if exist.
|
95
|
-
*
|
96
93
|
* @returns {void}
|
97
94
|
*/
|
98
95
|
function checkForArguments() {
|
@@ -13,7 +13,7 @@ const astUtils = require("./utils/ast-utils");
|
|
13
13
|
|
14
14
|
/**
|
15
15
|
* Checks whether or not a node is a `.apply()` for variadic.
|
16
|
-
* @param {ASTNode} node
|
16
|
+
* @param {ASTNode} node A CallExpression node to check.
|
17
17
|
* @returns {boolean} Whether or not the node is a `.apply()` for variadic.
|
18
18
|
*/
|
19
19
|
function isVariadicApplyCalling(node) {
|
@@ -31,9 +31,9 @@ function isVariadicApplyCalling(node) {
|
|
31
31
|
|
32
32
|
/**
|
33
33
|
* Checks whether or not `thisArg` is not changed by `.apply()`.
|
34
|
-
* @param {ASTNode|null} expectedThis
|
35
|
-
* @param {ASTNode} thisArg
|
36
|
-
* @param {RuleContext} context
|
34
|
+
* @param {ASTNode|null} expectedThis The node that is the owner of the applied function.
|
35
|
+
* @param {ASTNode} thisArg The node that is given to the first argument of the `.apply()`.
|
36
|
+
* @param {RuleContext} context The ESLint rule context object.
|
37
37
|
* @returns {boolean} Whether or not `thisArg` is not changed by `.apply()`.
|
38
38
|
*/
|
39
39
|
function isValidThisArg(expectedThis, thisArg, context) {
|
@@ -17,7 +17,7 @@ const astUtils = require("./utils/ast-utils");
|
|
17
17
|
|
18
18
|
/**
|
19
19
|
* Checks whether or not a given node is a concatenation.
|
20
|
-
* @param {ASTNode} node
|
20
|
+
* @param {ASTNode} node A node to check.
|
21
21
|
* @returns {boolean} `true` if the node is a concatenation.
|
22
22
|
*/
|
23
23
|
function isConcatenation(node) {
|
@@ -26,7 +26,7 @@ function isConcatenation(node) {
|
|
26
26
|
|
27
27
|
/**
|
28
28
|
* Gets the top binary expression node for concatenation in parents of a given node.
|
29
|
-
* @param {ASTNode} node
|
29
|
+
* @param {ASTNode} node A node to get.
|
30
30
|
* @returns {ASTNode} the top binary expression node in parents of a given node.
|
31
31
|
*/
|
32
32
|
function getTopConcatBinaryExpression(node) {
|
@@ -70,7 +70,7 @@ function hasOctalEscapeSequence(node) {
|
|
70
70
|
|
71
71
|
/**
|
72
72
|
* Checks whether or not a given binary expression has string literals.
|
73
|
-
* @param {ASTNode} node
|
73
|
+
* @param {ASTNode} node A node to check.
|
74
74
|
* @returns {boolean} `true` if the node has string literals.
|
75
75
|
*/
|
76
76
|
function hasStringLiteral(node) {
|
@@ -84,7 +84,7 @@ function hasStringLiteral(node) {
|
|
84
84
|
|
85
85
|
/**
|
86
86
|
* Checks whether or not a given binary expression has non string literals.
|
87
|
-
* @param {ASTNode} node
|
87
|
+
* @param {ASTNode} node A node to check.
|
88
88
|
* @returns {boolean} `true` if the node has non string literals.
|
89
89
|
*/
|
90
90
|
function hasNonStringLiteral(node) {
|
@@ -242,8 +242,7 @@ module.exports = {
|
|
242
242
|
|
243
243
|
/**
|
244
244
|
* Reports if a given node is string concatenation with non string literals.
|
245
|
-
*
|
246
|
-
* @param {ASTNode} node - A node to check.
|
245
|
+
* @param {ASTNode} node A node to check.
|
247
246
|
* @returns {void}
|
248
247
|
*/
|
249
248
|
function checkForStringConcat(node) {
|
package/lib/rules/quote-props.js
CHANGED
@@ -85,7 +85,7 @@ module.exports = {
|
|
85
85
|
|
86
86
|
/**
|
87
87
|
* Checks whether a certain string constitutes an ES3 token
|
88
|
-
* @param {string} tokenStr
|
88
|
+
* @param {string} tokenStr The string to be checked.
|
89
89
|
* @returns {boolean} `true` if it is an ES3 token.
|
90
90
|
*/
|
91
91
|
function isKeyword(tokenStr) {
|
package/lib/rules/quotes.js
CHANGED
@@ -41,7 +41,7 @@ const UNESCAPED_LINEBREAK_PATTERN = new RegExp(String.raw`(^|[^\\])(\\\\)*[${Arr
|
|
41
41
|
* escaping and unescaping as necessary.
|
42
42
|
* Only escaping of the minimal set of characters is changed.
|
43
43
|
* Note: escaping of newlines when switching from backtick to other quotes is not handled.
|
44
|
-
* @param {string} str
|
44
|
+
* @param {string} str A string to convert.
|
45
45
|
* @returns {string} The string with changed quotes.
|
46
46
|
* @private
|
47
47
|
*/
|
@@ -143,7 +143,6 @@ module.exports = {
|
|
143
143
|
*
|
144
144
|
* In both cases, inside of the braces is handled as normal JavaScript.
|
145
145
|
* The braces are `JSXExpressionContainer` nodes.
|
146
|
-
*
|
147
146
|
* @param {ASTNode} node The Literal node to check.
|
148
147
|
* @returns {boolean} True if the node is a part of JSX, false if not.
|
149
148
|
* @private
|
@@ -155,7 +154,7 @@ module.exports = {
|
|
155
154
|
/**
|
156
155
|
* Checks whether or not a given node is a directive.
|
157
156
|
* The directive is a `ExpressionStatement` which has only a string literal.
|
158
|
-
* @param {ASTNode} node
|
157
|
+
* @param {ASTNode} node A node to check.
|
159
158
|
* @returns {boolean} Whether or not the node is a directive.
|
160
159
|
* @private
|
161
160
|
*/
|
@@ -170,7 +169,7 @@ module.exports = {
|
|
170
169
|
/**
|
171
170
|
* Checks whether or not a given node is a part of directive prologues.
|
172
171
|
* See also: http://www.ecma-international.org/ecma-262/6.0/#sec-directive-prologues-and-the-use-strict-directive
|
173
|
-
* @param {ASTNode} node
|
172
|
+
* @param {ASTNode} node A node to check.
|
174
173
|
* @returns {boolean} Whether or not the node is a part of directive prologues.
|
175
174
|
* @private
|
176
175
|
*/
|
@@ -198,7 +197,7 @@ module.exports = {
|
|
198
197
|
|
199
198
|
/**
|
200
199
|
* Checks whether or not a given node is allowed as non backtick.
|
201
|
-
* @param {ASTNode} node
|
200
|
+
* @param {ASTNode} node A node to check.
|
202
201
|
* @returns {boolean} Whether or not the node is allowed as non backtick.
|
203
202
|
* @private
|
204
203
|
*/
|
@@ -230,7 +229,7 @@ module.exports = {
|
|
230
229
|
|
231
230
|
/**
|
232
231
|
* Checks whether or not a given TemplateLiteral node is actually using any of the special features provided by template literal strings.
|
233
|
-
* @param {ASTNode} node
|
232
|
+
* @param {ASTNode} node A TemplateLiteral node to check.
|
234
233
|
* @returns {boolean} Whether or not the TemplateLiteral node is using any of the special features provided by template literal strings.
|
235
234
|
* @private
|
236
235
|
*/
|
package/lib/rules/radix.js
CHANGED
@@ -20,8 +20,7 @@ const MODE_ALWAYS = "always",
|
|
20
20
|
|
21
21
|
/**
|
22
22
|
* Checks whether a given variable is shadowed or not.
|
23
|
-
*
|
24
|
-
* @param {eslint-scope.Variable} variable - A variable to check.
|
23
|
+
* @param {eslint-scope.Variable} variable A variable to check.
|
25
24
|
* @returns {boolean} `true` if the variable is shadowed.
|
26
25
|
*/
|
27
26
|
function isShadowed(variable) {
|
@@ -30,8 +29,7 @@ function isShadowed(variable) {
|
|
30
29
|
|
31
30
|
/**
|
32
31
|
* Checks whether a given node is a MemberExpression of `parseInt` method or not.
|
33
|
-
*
|
34
|
-
* @param {ASTNode} node - A node to check.
|
32
|
+
* @param {ASTNode} node A node to check.
|
35
33
|
* @returns {boolean} `true` if the node is a MemberExpression of `parseInt`
|
36
34
|
* method.
|
37
35
|
*/
|
@@ -51,8 +49,7 @@ function isParseIntMethod(node) {
|
|
51
49
|
*
|
52
50
|
* - A literal except numbers.
|
53
51
|
* - undefined.
|
54
|
-
*
|
55
|
-
* @param {ASTNode} radix - A node of radix to check.
|
52
|
+
* @param {ASTNode} radix A node of radix to check.
|
56
53
|
* @returns {boolean} `true` if the node is valid.
|
57
54
|
*/
|
58
55
|
function isValidRadix(radix) {
|
@@ -64,8 +61,7 @@ function isValidRadix(radix) {
|
|
64
61
|
|
65
62
|
/**
|
66
63
|
* Checks whether a given node is a default value of radix or not.
|
67
|
-
*
|
68
|
-
* @param {ASTNode} radix - A node of radix to check.
|
64
|
+
* @param {ASTNode} radix A node of radix to check.
|
69
65
|
* @returns {boolean} `true` if the node is the literal node of `10`.
|
70
66
|
*/
|
71
67
|
function isDefaultRadix(radix) {
|
@@ -100,8 +96,7 @@ module.exports = {
|
|
100
96
|
/**
|
101
97
|
* Checks the arguments of a given CallExpression node and reports it if it
|
102
98
|
* offends this rule.
|
103
|
-
*
|
104
|
-
* @param {ASTNode} node - A CallExpression node to check.
|
99
|
+
* @param {ASTNode} node A CallExpression node to check.
|
105
100
|
* @returns {void}
|
106
101
|
*/
|
107
102
|
function checkArguments(node) {
|
@@ -17,8 +17,7 @@ const astUtils = require("./utils/ast-utils");
|
|
17
17
|
|
18
18
|
/**
|
19
19
|
* Capitalize the 1st letter of the given text.
|
20
|
-
*
|
21
|
-
* @param {string} text - The text to capitalize.
|
20
|
+
* @param {string} text The text to capitalize.
|
22
21
|
* @returns {string} The text that the 1st letter was capitalized.
|
23
22
|
*/
|
24
23
|
function capitalizeFirstLetter(text) {
|
@@ -49,7 +48,6 @@ module.exports = {
|
|
49
48
|
|
50
49
|
/**
|
51
50
|
* Push the scope info object to the stack.
|
52
|
-
*
|
53
51
|
* @returns {void}
|
54
52
|
*/
|
55
53
|
function enterFunction() {
|
@@ -62,8 +60,7 @@ module.exports = {
|
|
62
60
|
/**
|
63
61
|
* Pop the top scope info object from the stack.
|
64
62
|
* Also, it reports the function if needed.
|
65
|
-
*
|
66
|
-
* @param {ASTNode} node - The node to report.
|
63
|
+
* @param {ASTNode} node The node to report.
|
67
64
|
* @returns {void}
|
68
65
|
*/
|
69
66
|
function exitFunction(node) {
|
@@ -92,9 +89,17 @@ module.exports = {
|
|
92
89
|
"ArrowFunctionExpression:exit": exitFunction,
|
93
90
|
|
94
91
|
AwaitExpression() {
|
92
|
+
if (!scopeInfo) {
|
93
|
+
return;
|
94
|
+
}
|
95
|
+
|
95
96
|
scopeInfo.hasAwait = true;
|
96
97
|
},
|
97
98
|
ForOfStatement(node) {
|
99
|
+
if (!scopeInfo) {
|
100
|
+
return;
|
101
|
+
}
|
102
|
+
|
98
103
|
if (node.await) {
|
99
104
|
scopeInfo.hasAwait = true;
|
100
105
|
}
|
@@ -28,7 +28,7 @@ module.exports = {
|
|
28
28
|
|
29
29
|
/**
|
30
30
|
* If the node is a generator function, start counting `yield` keywords.
|
31
|
-
* @param {Node} node
|
31
|
+
* @param {Node} node A function node to check.
|
32
32
|
* @returns {void}
|
33
33
|
*/
|
34
34
|
function beginChecking(node) {
|
@@ -40,7 +40,7 @@ module.exports = {
|
|
40
40
|
/**
|
41
41
|
* If the node is a generator function, end counting `yield` keywords, then
|
42
42
|
* reports result.
|
43
|
-
* @param {Node} node
|
43
|
+
* @param {Node} node A function node to check.
|
44
44
|
* @returns {void}
|
45
45
|
*/
|
46
46
|
function endChecking(node) {
|
package/lib/rules/semi.js
CHANGED
@@ -93,17 +93,20 @@ module.exports = {
|
|
93
93
|
const lastToken = sourceCode.getLastToken(node);
|
94
94
|
let message,
|
95
95
|
fix,
|
96
|
-
loc
|
96
|
+
loc;
|
97
97
|
|
98
98
|
if (!missing) {
|
99
99
|
message = "Missing semicolon.";
|
100
|
-
loc =
|
100
|
+
loc = {
|
101
|
+
start: lastToken.loc.end,
|
102
|
+
end: astUtils.getNextLocation(sourceCode, lastToken.loc.end)
|
103
|
+
};
|
101
104
|
fix = function(fixer) {
|
102
105
|
return fixer.insertTextAfter(lastToken, ";");
|
103
106
|
};
|
104
107
|
} else {
|
105
108
|
message = "Extra semicolon.";
|
106
|
-
loc = loc
|
109
|
+
loc = lastToken.loc;
|
107
110
|
fix = function(fixer) {
|
108
111
|
|
109
112
|
/*
|
@@ -70,8 +70,7 @@ module.exports = {
|
|
70
70
|
* import * as myModule from "my-module.js" --> all
|
71
71
|
* import {myMember} from "my-module.js" --> single
|
72
72
|
* import {foo, bar} from "my-module.js" --> multiple
|
73
|
-
*
|
74
|
-
* @param {ASTNode} node - the ImportDeclaration node.
|
73
|
+
* @param {ASTNode} node the ImportDeclaration node.
|
75
74
|
* @returns {string} used member parameter style, ["all", "multiple", "single"]
|
76
75
|
*/
|
77
76
|
function usedMemberSyntax(node) {
|
@@ -90,7 +89,7 @@ module.exports = {
|
|
90
89
|
|
91
90
|
/**
|
92
91
|
* Gets the group by member parameter index for given declaration.
|
93
|
-
* @param {ASTNode} node
|
92
|
+
* @param {ASTNode} node the ImportDeclaration node.
|
94
93
|
* @returns {number} the declaration group by member index.
|
95
94
|
*/
|
96
95
|
function getMemberParameterGroupIndex(node) {
|
@@ -99,7 +98,7 @@ module.exports = {
|
|
99
98
|
|
100
99
|
/**
|
101
100
|
* Gets the local name of the first imported module.
|
102
|
-
* @param {ASTNode} node
|
101
|
+
* @param {ASTNode} node the ImportDeclaration node.
|
103
102
|
* @returns {?string} the local name of the first imported module.
|
104
103
|
*/
|
105
104
|
function getFirstLocalMemberName(node) {
|
package/lib/rules/sort-keys.js
CHANGED
@@ -23,8 +23,7 @@ const astUtils = require("./utils/ast-utils"),
|
|
23
23
|
* whether it's a computed property or not.
|
24
24
|
* - If the property has a static name, this returns the static name.
|
25
25
|
* - Otherwise, this returns null.
|
26
|
-
*
|
27
|
-
* @param {ASTNode} node - The `Property` node to get.
|
26
|
+
* @param {ASTNode} node The `Property` node to get.
|
28
27
|
* @returns {string|null} The property name or null.
|
29
28
|
* @private
|
30
29
|
*/
|
@@ -43,7 +42,6 @@ function getPropertyName(node) {
|
|
43
42
|
*
|
44
43
|
* Postfix `I` is meant insensitive.
|
45
44
|
* Postfix `N` is meant natual.
|
46
|
-
*
|
47
45
|
* @private
|
48
46
|
*/
|
49
47
|
const isValidOrders = {
|
@@ -79,8 +79,7 @@ module.exports = {
|
|
79
79
|
/**
|
80
80
|
* Checks whether or not a given token is an arrow operator (=>) or a keyword
|
81
81
|
* in order to avoid to conflict with `arrow-spacing` and `keyword-spacing`.
|
82
|
-
*
|
83
|
-
* @param {Token} token - A token to check.
|
82
|
+
* @param {Token} token A token to check.
|
84
83
|
* @returns {boolean} `true` if the token is an arrow operator.
|
85
84
|
*/
|
86
85
|
function isConflicted(token) {
|
@@ -232,7 +232,7 @@ module.exports = {
|
|
232
232
|
if (token.value === "(" && openerMissingSpace(token, nextToken)) {
|
233
233
|
context.report({
|
234
234
|
node,
|
235
|
-
loc: token.loc
|
235
|
+
loc: token.loc,
|
236
236
|
messageId: "missingOpeningSpace",
|
237
237
|
fix(fixer) {
|
238
238
|
return fixer.insertTextAfter(token, " ");
|
@@ -244,7 +244,7 @@ module.exports = {
|
|
244
244
|
if (token.value === "(" && openerRejectsSpace(token, nextToken)) {
|
245
245
|
context.report({
|
246
246
|
node,
|
247
|
-
loc: token.loc.start,
|
247
|
+
loc: { start: token.loc.end, end: nextToken.loc.start },
|
248
248
|
messageId: "rejectedOpeningSpace",
|
249
249
|
fix(fixer) {
|
250
250
|
return fixer.removeRange([token.range[1], nextToken.range[0]]);
|
@@ -256,7 +256,7 @@ module.exports = {
|
|
256
256
|
if (token.value === ")" && closerMissingSpace(prevToken, token)) {
|
257
257
|
context.report({
|
258
258
|
node,
|
259
|
-
loc: token.loc
|
259
|
+
loc: token.loc,
|
260
260
|
messageId: "missingClosingSpace",
|
261
261
|
fix(fixer) {
|
262
262
|
return fixer.insertTextBefore(token, " ");
|
@@ -268,7 +268,7 @@ module.exports = {
|
|
268
268
|
if (token.value === ")" && closerRejectsSpace(prevToken, token)) {
|
269
269
|
context.report({
|
270
270
|
node,
|
271
|
-
loc: token.loc.start,
|
271
|
+
loc: { start: prevToken.loc.end, end: token.loc.start },
|
272
272
|
messageId: "rejectedClosingSpace",
|
273
273
|
fix(fixer) {
|
274
274
|
return fixer.removeRange([prevToken.range[1], token.range[0]]);
|
@@ -41,9 +41,9 @@ module.exports = {
|
|
41
41
|
|
42
42
|
/**
|
43
43
|
* Returns the first token which violates the rule
|
44
|
-
* @param {ASTNode} left
|
45
|
-
* @param {ASTNode} right
|
46
|
-
* @param {string} op
|
44
|
+
* @param {ASTNode} left The left node of the main node
|
45
|
+
* @param {ASTNode} right The right node of the main node
|
46
|
+
* @param {string} op The operator of the main node
|
47
47
|
* @returns {Object} The violator token or null
|
48
48
|
* @private
|
49
49
|
*/
|
@@ -61,15 +61,15 @@ module.exports = {
|
|
61
61
|
|
62
62
|
/**
|
63
63
|
* Reports an AST node as a rule violation
|
64
|
-
* @param {ASTNode} mainNode
|
65
|
-
* @param {Object} culpritToken
|
64
|
+
* @param {ASTNode} mainNode The node to report
|
65
|
+
* @param {Object} culpritToken The token which has a problem
|
66
66
|
* @returns {void}
|
67
67
|
* @private
|
68
68
|
*/
|
69
69
|
function report(mainNode, culpritToken) {
|
70
70
|
context.report({
|
71
71
|
node: mainNode,
|
72
|
-
loc: culpritToken.loc
|
72
|
+
loc: culpritToken.loc,
|
73
73
|
message: "Operator '{{operator}}' must be spaced.",
|
74
74
|
data: {
|
75
75
|
operator: culpritToken.value
|
@@ -13,7 +13,7 @@ const astUtils = require("./utils/ast-utils");
|
|
13
13
|
|
14
14
|
/**
|
15
15
|
* Escapes the control characters of a given string.
|
16
|
-
* @param {string} s
|
16
|
+
* @param {string} s A string to escape.
|
17
17
|
* @returns {string} An escaped string.
|
18
18
|
*/
|
19
19
|
function escape(s) {
|
@@ -23,7 +23,7 @@ function escape(s) {
|
|
23
23
|
/**
|
24
24
|
* Escapes the control characters of a given string.
|
25
25
|
* And adds a repeat flag.
|
26
|
-
* @param {string} s
|
26
|
+
* @param {string} s A string to escape.
|
27
27
|
* @returns {string} An escaped string.
|
28
28
|
*/
|
29
29
|
function escapeAndRepeat(s) {
|
@@ -33,7 +33,7 @@ function escapeAndRepeat(s) {
|
|
33
33
|
/**
|
34
34
|
* Parses `markers` option.
|
35
35
|
* If markers don't include `"*"`, this adds `"*"` to allow JSDoc comments.
|
36
|
-
* @param {string[]} [markers]
|
36
|
+
* @param {string[]} [markers] A marker list.
|
37
37
|
* @returns {string[]} A marker list.
|
38
38
|
*/
|
39
39
|
function parseMarkersOption(markers) {
|
@@ -51,8 +51,7 @@ function parseMarkersOption(markers) {
|
|
51
51
|
* Generated pattern:
|
52
52
|
*
|
53
53
|
* 1. A space or an exception pattern sequence.
|
54
|
-
*
|
55
|
-
* @param {string[]} exceptions - An exception pattern list.
|
54
|
+
* @param {string[]} exceptions An exception pattern list.
|
56
55
|
* @returns {string} A regular expression string for exceptions.
|
57
56
|
*/
|
58
57
|
function createExceptionsPattern(exceptions) {
|
@@ -97,9 +96,8 @@ function createExceptionsPattern(exceptions) {
|
|
97
96
|
*
|
98
97
|
* 1. First, a marker or nothing.
|
99
98
|
* 2. Next, a space or an exception pattern sequence.
|
100
|
-
*
|
101
|
-
* @param {string[]}
|
102
|
-
* @param {string[]} exceptions - An exception pattern list.
|
99
|
+
* @param {string[]} markers A marker list.
|
100
|
+
* @param {string[]} exceptions An exception pattern list.
|
103
101
|
* @returns {RegExp} A RegExp object for the beginning of a comment in `always` mode.
|
104
102
|
*/
|
105
103
|
function createAlwaysStylePattern(markers, exceptions) {
|
@@ -135,8 +133,7 @@ function createAlwaysStylePattern(markers, exceptions) {
|
|
135
133
|
*
|
136
134
|
* 1. First, a marker or nothing (captured).
|
137
135
|
* 2. Next, a space or a tab.
|
138
|
-
*
|
139
|
-
* @param {string[]} markers - A marker list.
|
136
|
+
* @param {string[]} markers A marker list.
|
140
137
|
* @returns {RegExp} A RegExp object for `never` mode.
|
141
138
|
*/
|
142
139
|
function createNeverStylePattern(markers) {
|
@@ -252,7 +249,8 @@ module.exports = {
|
|
252
249
|
beginRegex: requireSpace ? createAlwaysStylePattern(markers, exceptions) : createNeverStylePattern(markers),
|
253
250
|
endRegex: balanced && requireSpace ? new RegExp(`${createExceptionsPattern(exceptions)}$`, "u") : new RegExp(endNeverPattern, "u"),
|
254
251
|
hasExceptions: exceptions.length > 0,
|
255
|
-
|
252
|
+
captureMarker: new RegExp(`^(${markers.map(escape).join("|")})`, "u"),
|
253
|
+
markers: new Set(markers)
|
256
254
|
};
|
257
255
|
|
258
256
|
return rule;
|
@@ -260,10 +258,10 @@ module.exports = {
|
|
260
258
|
|
261
259
|
/**
|
262
260
|
* Reports a beginning spacing error with an appropriate message.
|
263
|
-
* @param {ASTNode} node
|
264
|
-
* @param {string} message
|
265
|
-
* @param {Array} match
|
266
|
-
* @param {string} refChar
|
261
|
+
* @param {ASTNode} node A comment node to check.
|
262
|
+
* @param {string} message An error message to report.
|
263
|
+
* @param {Array} match An array of match results for markers.
|
264
|
+
* @param {string} refChar Character used for reference in the error message.
|
267
265
|
* @returns {void}
|
268
266
|
*/
|
269
267
|
function reportBegin(node, message, match, refChar) {
|
@@ -293,9 +291,9 @@ module.exports = {
|
|
293
291
|
|
294
292
|
/**
|
295
293
|
* Reports an ending spacing error with an appropriate message.
|
296
|
-
* @param {ASTNode} node
|
297
|
-
* @param {string} message
|
298
|
-
* @param {string} match
|
294
|
+
* @param {ASTNode} node A comment node to check.
|
295
|
+
* @param {string} message An error message to report.
|
296
|
+
* @param {string} match An array of the matched whitespace characters.
|
299
297
|
* @returns {void}
|
300
298
|
*/
|
301
299
|
function reportEnd(node, message, match) {
|
@@ -317,7 +315,7 @@ module.exports = {
|
|
317
315
|
|
318
316
|
/**
|
319
317
|
* Reports a given comment if it's invalid.
|
320
|
-
* @param {ASTNode} node
|
318
|
+
* @param {ASTNode} node a comment node to check.
|
321
319
|
* @returns {void}
|
322
320
|
*/
|
323
321
|
function checkCommentForSpace(node) {
|
@@ -325,8 +323,8 @@ module.exports = {
|
|
325
323
|
rule = styleRules[type],
|
326
324
|
commentIdentifier = type === "block" ? "/*" : "//";
|
327
325
|
|
328
|
-
// Ignores empty comments.
|
329
|
-
if (node.value.length === 0) {
|
326
|
+
// Ignores empty comments and comments that consist only of a marker.
|
327
|
+
if (node.value.length === 0 || rule.markers.has(node.value)) {
|
330
328
|
return;
|
331
329
|
}
|
332
330
|
|
@@ -336,7 +334,7 @@ module.exports = {
|
|
336
334
|
// Checks.
|
337
335
|
if (requireSpace) {
|
338
336
|
if (!beginMatch) {
|
339
|
-
const hasMarker = rule.
|
337
|
+
const hasMarker = rule.captureMarker.exec(node.value);
|
340
338
|
const marker = hasMarker ? commentIdentifier + hasMarker[0] : commentIdentifier;
|
341
339
|
|
342
340
|
if (rule.hasExceptions) {
|