eslint 4.12.1 → 4.15.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 +49 -0
- package/README.md +3 -3
- package/lib/cli-engine.js +4 -0
- package/lib/linter.js +78 -35
- package/lib/options.js +47 -41
- package/lib/report-translator.js +34 -13
- package/lib/rules/.eslintrc.yml +1 -0
- package/lib/rules/accessor-pairs.js +2 -1
- package/lib/rules/array-bracket-newline.js +2 -1
- package/lib/rules/array-bracket-spacing.js +2 -1
- package/lib/rules/array-callback-return.js +18 -3
- package/lib/rules/array-element-newline.js +2 -1
- package/lib/rules/arrow-body-style.js +15 -2
- package/lib/rules/arrow-parens.js +2 -1
- package/lib/rules/arrow-spacing.js +2 -1
- package/lib/rules/block-scoped-var.js +2 -1
- package/lib/rules/block-spacing.js +2 -1
- package/lib/rules/brace-style.js +2 -1
- package/lib/rules/callback-return.js +2 -1
- package/lib/rules/camelcase.js +29 -17
- package/lib/rules/capitalized-comments.js +2 -1
- package/lib/rules/class-methods-use-this.js +2 -1
- package/lib/rules/comma-dangle.js +2 -1
- package/lib/rules/comma-spacing.js +2 -1
- package/lib/rules/comma-style.js +2 -1
- package/lib/rules/complexity.js +3 -16
- package/lib/rules/computed-property-spacing.js +2 -1
- package/lib/rules/consistent-return.js +2 -1
- package/lib/rules/consistent-this.js +2 -1
- package/lib/rules/constructor-super.js +2 -1
- package/lib/rules/curly.js +2 -1
- package/lib/rules/default-case.js +2 -1
- package/lib/rules/dot-location.js +2 -1
- package/lib/rules/dot-notation.js +2 -1
- package/lib/rules/eol-last.js +10 -1
- package/lib/rules/eqeqeq.js +2 -1
- package/lib/rules/for-direction.js +2 -1
- package/lib/rules/func-call-spacing.js +2 -1
- package/lib/rules/func-name-matching.js +2 -1
- package/lib/rules/func-names.js +2 -1
- package/lib/rules/func-style.js +2 -1
- package/lib/rules/function-paren-newline.js +2 -1
- package/lib/rules/generator-star-spacing.js +2 -1
- package/lib/rules/getter-return.js +2 -1
- package/lib/rules/global-require.js +2 -1
- package/lib/rules/guard-for-in.js +2 -1
- package/lib/rules/handle-callback-err.js +2 -1
- package/lib/rules/id-blacklist.js +2 -1
- package/lib/rules/id-length.js +2 -1
- package/lib/rules/id-match.js +2 -1
- package/lib/rules/implicit-arrow-linebreak.js +2 -1
- package/lib/rules/indent-legacy.js +2 -1
- package/lib/rules/indent.js +13 -2
- package/lib/rules/init-declarations.js +2 -1
- package/lib/rules/jsx-quotes.js +2 -1
- package/lib/rules/key-spacing.js +2 -1
- package/lib/rules/keyword-spacing.js +2 -1
- package/lib/rules/line-comment-position.js +2 -1
- package/lib/rules/linebreak-style.js +2 -1
- package/lib/rules/lines-around-comment.js +2 -1
- package/lib/rules/lines-around-directive.js +2 -1
- package/lib/rules/lines-between-class-members.js +53 -4
- package/lib/rules/max-depth.js +2 -1
- package/lib/rules/max-len.js +2 -1
- package/lib/rules/max-lines.js +2 -1
- package/lib/rules/max-nested-callbacks.js +2 -1
- package/lib/rules/max-params.js +2 -1
- package/lib/rules/max-statements-per-line.js +2 -1
- package/lib/rules/max-statements.js +2 -1
- package/lib/rules/multiline-comment-style.js +2 -1
- package/lib/rules/multiline-ternary.js +2 -1
- package/lib/rules/new-cap.js +2 -1
- package/lib/rules/new-parens.js +2 -1
- package/lib/rules/newline-after-var.js +2 -1
- package/lib/rules/newline-before-return.js +2 -1
- package/lib/rules/newline-per-chained-call.js +2 -1
- package/lib/rules/no-alert.js +2 -1
- package/lib/rules/no-array-constructor.js +2 -1
- package/lib/rules/no-await-in-loop.js +2 -1
- package/lib/rules/no-bitwise.js +2 -1
- package/lib/rules/no-buffer-constructor.js +2 -1
- package/lib/rules/no-caller.js +2 -1
- package/lib/rules/no-case-declarations.js +2 -1
- package/lib/rules/no-catch-shadow.js +2 -1
- package/lib/rules/no-class-assign.js +2 -1
- package/lib/rules/no-compare-neg-zero.js +2 -1
- package/lib/rules/no-cond-assign.js +2 -1
- package/lib/rules/no-confusing-arrow.js +2 -1
- package/lib/rules/no-console.js +2 -1
- package/lib/rules/no-const-assign.js +2 -1
- package/lib/rules/no-constant-condition.js +2 -1
- package/lib/rules/no-continue.js +2 -1
- package/lib/rules/no-control-regex.js +2 -1
- package/lib/rules/no-debugger.js +2 -1
- package/lib/rules/no-delete-var.js +2 -1
- package/lib/rules/no-div-regex.js +2 -1
- package/lib/rules/no-dupe-args.js +2 -1
- package/lib/rules/no-dupe-class-members.js +2 -1
- package/lib/rules/no-dupe-keys.js +2 -1
- package/lib/rules/no-duplicate-case.js +2 -1
- package/lib/rules/no-duplicate-imports.js +2 -1
- package/lib/rules/no-else-return.js +2 -1
- package/lib/rules/no-empty-character-class.js +2 -1
- package/lib/rules/no-empty-function.js +2 -1
- package/lib/rules/no-empty-pattern.js +2 -1
- package/lib/rules/no-empty.js +2 -1
- package/lib/rules/no-eq-null.js +2 -1
- package/lib/rules/no-eval.js +2 -1
- package/lib/rules/no-ex-assign.js +2 -1
- package/lib/rules/no-extend-native.js +2 -1
- package/lib/rules/no-extra-bind.js +2 -1
- package/lib/rules/no-extra-boolean-cast.js +2 -1
- package/lib/rules/no-extra-label.js +2 -1
- package/lib/rules/no-extra-parens.js +3 -2
- package/lib/rules/no-extra-semi.js +2 -1
- package/lib/rules/no-fallthrough.js +2 -1
- package/lib/rules/no-floating-decimal.js +2 -1
- package/lib/rules/no-func-assign.js +2 -1
- package/lib/rules/no-global-assign.js +2 -1
- package/lib/rules/no-implicit-coercion.js +2 -1
- package/lib/rules/no-implicit-globals.js +2 -1
- package/lib/rules/no-implied-eval.js +2 -1
- package/lib/rules/no-inline-comments.js +2 -1
- package/lib/rules/no-inner-declarations.js +2 -1
- package/lib/rules/no-invalid-regexp.js +2 -1
- package/lib/rules/no-invalid-this.js +2 -1
- package/lib/rules/no-irregular-whitespace.js +2 -1
- package/lib/rules/no-iterator.js +2 -1
- package/lib/rules/no-label-var.js +2 -1
- package/lib/rules/no-labels.js +2 -1
- package/lib/rules/no-lone-blocks.js +2 -1
- package/lib/rules/no-lonely-if.js +2 -1
- package/lib/rules/no-loop-func.js +2 -1
- package/lib/rules/no-magic-numbers.js +2 -1
- package/lib/rules/no-mixed-operators.js +2 -1
- package/lib/rules/no-mixed-requires.js +2 -1
- package/lib/rules/no-mixed-spaces-and-tabs.js +2 -1
- package/lib/rules/no-multi-assign.js +2 -1
- package/lib/rules/no-multi-spaces.js +2 -1
- package/lib/rules/no-multi-str.js +2 -1
- package/lib/rules/no-multiple-empty-lines.js +2 -1
- package/lib/rules/no-native-reassign.js +2 -1
- package/lib/rules/no-negated-condition.js +2 -1
- package/lib/rules/no-negated-in-lhs.js +2 -1
- package/lib/rules/no-nested-ternary.js +2 -1
- package/lib/rules/no-new-func.js +2 -1
- package/lib/rules/no-new-object.js +2 -1
- package/lib/rules/no-new-require.js +2 -1
- package/lib/rules/no-new-symbol.js +2 -1
- package/lib/rules/no-new-wrappers.js +2 -1
- package/lib/rules/no-new.js +2 -1
- package/lib/rules/no-obj-calls.js +2 -1
- package/lib/rules/no-octal-escape.js +2 -1
- package/lib/rules/no-octal.js +2 -1
- package/lib/rules/no-param-reassign.js +2 -1
- package/lib/rules/no-path-concat.js +2 -1
- package/lib/rules/no-plusplus.js +2 -1
- package/lib/rules/no-process-env.js +2 -1
- package/lib/rules/no-process-exit.js +2 -1
- package/lib/rules/no-proto.js +2 -1
- package/lib/rules/no-prototype-builtins.js +2 -1
- package/lib/rules/no-redeclare.js +2 -1
- package/lib/rules/no-regex-spaces.js +2 -1
- package/lib/rules/no-restricted-globals.js +2 -1
- package/lib/rules/no-restricted-imports.js +2 -1
- package/lib/rules/no-restricted-modules.js +2 -1
- package/lib/rules/no-restricted-properties.js +2 -1
- package/lib/rules/no-restricted-syntax.js +2 -1
- package/lib/rules/no-return-assign.js +2 -1
- package/lib/rules/no-return-await.js +5 -1
- package/lib/rules/no-script-url.js +2 -1
- package/lib/rules/no-self-assign.js +2 -1
- package/lib/rules/no-self-compare.js +2 -1
- package/lib/rules/no-sequences.js +2 -1
- package/lib/rules/no-shadow-restricted-names.js +2 -1
- package/lib/rules/no-shadow.js +2 -1
- package/lib/rules/no-spaced-func.js +2 -1
- package/lib/rules/no-sparse-arrays.js +2 -1
- package/lib/rules/no-sync.js +2 -1
- package/lib/rules/no-tabs.js +2 -1
- package/lib/rules/no-template-curly-in-string.js +2 -1
- package/lib/rules/no-ternary.js +2 -1
- package/lib/rules/no-this-before-super.js +2 -1
- package/lib/rules/no-throw-literal.js +2 -1
- package/lib/rules/no-trailing-spaces.js +2 -1
- package/lib/rules/no-undef-init.js +2 -1
- package/lib/rules/no-undef.js +2 -1
- package/lib/rules/no-undefined.js +2 -1
- package/lib/rules/no-underscore-dangle.js +2 -1
- package/lib/rules/no-unexpected-multiline.js +2 -1
- package/lib/rules/no-unmodified-loop-condition.js +81 -79
- package/lib/rules/no-unneeded-ternary.js +2 -1
- package/lib/rules/no-unreachable.js +2 -1
- package/lib/rules/no-unsafe-finally.js +2 -1
- package/lib/rules/no-unsafe-negation.js +2 -1
- package/lib/rules/no-unused-expressions.js +2 -1
- package/lib/rules/no-unused-labels.js +2 -1
- package/lib/rules/no-unused-vars.js +10 -14
- package/lib/rules/no-use-before-define.js +2 -1
- package/lib/rules/no-useless-call.js +2 -1
- package/lib/rules/no-useless-computed-key.js +2 -1
- package/lib/rules/no-useless-concat.js +2 -1
- package/lib/rules/no-useless-constructor.js +2 -1
- package/lib/rules/no-useless-escape.js +2 -1
- package/lib/rules/no-useless-rename.js +2 -1
- package/lib/rules/no-useless-return.js +2 -1
- package/lib/rules/no-var.js +2 -1
- package/lib/rules/no-void.js +2 -1
- package/lib/rules/no-warning-comments.js +2 -1
- package/lib/rules/no-whitespace-before-property.js +2 -1
- package/lib/rules/no-with.js +2 -1
- package/lib/rules/nonblock-statement-body-position.js +2 -1
- package/lib/rules/object-curly-newline.js +2 -1
- package/lib/rules/object-curly-spacing.js +2 -1
- package/lib/rules/object-property-newline.js +2 -1
- package/lib/rules/object-shorthand.js +2 -1
- package/lib/rules/one-var-declaration-per-line.js +2 -1
- package/lib/rules/one-var.js +42 -8
- package/lib/rules/operator-assignment.js +2 -1
- package/lib/rules/operator-linebreak.js +2 -1
- package/lib/rules/padded-blocks.js +2 -1
- package/lib/rules/padding-line-between-statements.js +2 -1
- package/lib/rules/prefer-arrow-callback.js +2 -1
- package/lib/rules/prefer-const.js +2 -1
- package/lib/rules/prefer-destructuring.js +2 -1
- package/lib/rules/prefer-numeric-literals.js +2 -1
- package/lib/rules/prefer-promise-reject-errors.js +2 -1
- package/lib/rules/prefer-reflect.js +2 -1
- package/lib/rules/prefer-rest-params.js +2 -1
- package/lib/rules/prefer-spread.js +2 -1
- package/lib/rules/prefer-template.js +2 -1
- package/lib/rules/quote-props.js +2 -1
- package/lib/rules/quotes.js +2 -1
- package/lib/rules/radix.js +2 -1
- package/lib/rules/require-await.js +2 -1
- package/lib/rules/require-jsdoc.js +2 -1
- package/lib/rules/require-yield.js +2 -1
- package/lib/rules/rest-spread-spacing.js +2 -1
- package/lib/rules/semi-spacing.js +2 -1
- package/lib/rules/semi-style.js +2 -1
- package/lib/rules/semi.js +2 -1
- package/lib/rules/sort-imports.js +2 -1
- package/lib/rules/sort-keys.js +2 -1
- package/lib/rules/sort-vars.js +2 -1
- package/lib/rules/space-before-blocks.js +2 -1
- package/lib/rules/space-before-function-paren.js +2 -1
- package/lib/rules/space-in-parens.js +2 -1
- package/lib/rules/space-infix-ops.js +2 -1
- package/lib/rules/space-unary-ops.js +2 -1
- package/lib/rules/spaced-comment.js +2 -1
- package/lib/rules/strict.js +2 -1
- package/lib/rules/switch-colon-spacing.js +2 -1
- package/lib/rules/symbol-description.js +2 -1
- package/lib/rules/template-curly-spacing.js +2 -1
- package/lib/rules/template-tag-spacing.js +2 -1
- package/lib/rules/unicode-bom.js +2 -1
- package/lib/rules/use-isnan.js +2 -1
- package/lib/rules/valid-jsdoc.js +2 -1
- package/lib/rules/valid-typeof.js +2 -1
- package/lib/rules/vars-on-top.js +2 -1
- package/lib/rules/wrap-iife.js +2 -1
- package/lib/rules/wrap-regex.js +2 -1
- package/lib/rules/yield-star-spacing.js +2 -1
- package/lib/rules/yoda.js +2 -1
- package/lib/testers/rule-tester.js +63 -30
- package/lib/util/interpolate.js +24 -0
- package/lib/util/source-code.js +41 -6
- package/lib/util/traverser.js +163 -15
- package/package.json +3 -3
@@ -50,7 +50,8 @@ module.exports = {
|
|
50
50
|
docs: {
|
51
51
|
description: "disallow specified modules when loaded by `require`",
|
52
52
|
category: "Node.js and CommonJS",
|
53
|
-
recommended: false
|
53
|
+
recommended: false,
|
54
|
+
url: "https://eslint.org/docs/rules/no-restricted-modules"
|
54
55
|
},
|
55
56
|
|
56
57
|
schema: {
|
@@ -16,7 +16,8 @@ module.exports = {
|
|
16
16
|
docs: {
|
17
17
|
description: "disallow certain properties on certain objects",
|
18
18
|
category: "Best Practices",
|
19
|
-
recommended: false
|
19
|
+
recommended: false,
|
20
|
+
url: "https://eslint.org/docs/rules/no-restricted-properties"
|
20
21
|
},
|
21
22
|
|
22
23
|
schema: {
|
@@ -17,7 +17,11 @@ module.exports = {
|
|
17
17
|
docs: {
|
18
18
|
description: "disallow unnecessary `return await`",
|
19
19
|
category: "Best Practices",
|
20
|
-
|
20
|
+
|
21
|
+
// TODO: set to true
|
22
|
+
recommended: false,
|
23
|
+
|
24
|
+
url: "https://eslint.org/docs/rules/no-return-await"
|
21
25
|
},
|
22
26
|
fixable: null,
|
23
27
|
schema: [
|
@@ -166,7 +166,8 @@ module.exports = {
|
|
166
166
|
docs: {
|
167
167
|
description: "disallow assignments where both sides are exactly the same",
|
168
168
|
category: "Best Practices",
|
169
|
-
recommended: true
|
169
|
+
recommended: true,
|
170
|
+
url: "https://eslint.org/docs/rules/no-self-assign"
|
170
171
|
},
|
171
172
|
|
172
173
|
schema: [
|
@@ -15,7 +15,8 @@ module.exports = {
|
|
15
15
|
docs: {
|
16
16
|
description: "disallow comparisons where both sides are exactly the same",
|
17
17
|
category: "Best Practices",
|
18
|
-
recommended: false
|
18
|
+
recommended: false,
|
19
|
+
url: "https://eslint.org/docs/rules/no-self-compare"
|
19
20
|
},
|
20
21
|
|
21
22
|
schema: []
|
@@ -13,7 +13,8 @@ module.exports = {
|
|
13
13
|
docs: {
|
14
14
|
description: "disallow identifiers from shadowing restricted names",
|
15
15
|
category: "Variables",
|
16
|
-
recommended: false
|
16
|
+
recommended: false,
|
17
|
+
url: "https://eslint.org/docs/rules/no-shadow-restricted-names"
|
17
18
|
},
|
18
19
|
|
19
20
|
schema: []
|
package/lib/rules/no-shadow.js
CHANGED
@@ -20,7 +20,8 @@ module.exports = {
|
|
20
20
|
docs: {
|
21
21
|
description: "disallow variable declarations from shadowing variables declared in the outer scope",
|
22
22
|
category: "Variables",
|
23
|
-
recommended: false
|
23
|
+
recommended: false,
|
24
|
+
url: "https://eslint.org/docs/rules/no-shadow"
|
24
25
|
},
|
25
26
|
|
26
27
|
schema: [
|
@@ -16,7 +16,8 @@ module.exports = {
|
|
16
16
|
description: "disallow spacing between function identifiers and their applications (deprecated)",
|
17
17
|
category: "Stylistic Issues",
|
18
18
|
recommended: false,
|
19
|
-
replacedBy: ["func-call-spacing"]
|
19
|
+
replacedBy: ["func-call-spacing"],
|
20
|
+
url: "https://eslint.org/docs/rules/no-spaced-func"
|
20
21
|
},
|
21
22
|
|
22
23
|
deprecated: true,
|
package/lib/rules/no-sync.js
CHANGED
package/lib/rules/no-tabs.js
CHANGED
@@ -13,7 +13,8 @@ module.exports = {
|
|
13
13
|
docs: {
|
14
14
|
description: "disallow template literal placeholder syntax in regular strings",
|
15
15
|
category: "Possible Errors",
|
16
|
-
recommended: false
|
16
|
+
recommended: false,
|
17
|
+
url: "https://eslint.org/docs/rules/no-template-curly-in-string"
|
17
18
|
},
|
18
19
|
|
19
20
|
schema: []
|
package/lib/rules/no-ternary.js
CHANGED
@@ -39,7 +39,8 @@ module.exports = {
|
|
39
39
|
docs: {
|
40
40
|
description: "disallow `this`/`super` before calling `super()` in constructors",
|
41
41
|
category: "ECMAScript 6",
|
42
|
-
recommended: true
|
42
|
+
recommended: true,
|
43
|
+
url: "https://eslint.org/docs/rules/no-this-before-super"
|
43
44
|
},
|
44
45
|
|
45
46
|
schema: []
|
@@ -19,7 +19,8 @@ module.exports = {
|
|
19
19
|
docs: {
|
20
20
|
description: "disallow trailing whitespace at the end of lines",
|
21
21
|
category: "Stylistic Issues",
|
22
|
-
recommended: false
|
22
|
+
recommended: false,
|
23
|
+
url: "https://eslint.org/docs/rules/no-trailing-spaces"
|
23
24
|
},
|
24
25
|
|
25
26
|
fixable: "whitespace",
|
package/lib/rules/no-undef.js
CHANGED
@@ -28,7 +28,8 @@ module.exports = {
|
|
28
28
|
docs: {
|
29
29
|
description: "disallow the use of undeclared variables unless mentioned in `/*global */` comments",
|
30
30
|
category: "Variables",
|
31
|
-
recommended: true
|
31
|
+
recommended: true,
|
32
|
+
url: "https://eslint.org/docs/rules/no-undef"
|
32
33
|
},
|
33
34
|
|
34
35
|
schema: [
|
@@ -106,84 +106,6 @@ const isInLoop = {
|
|
106
106
|
}
|
107
107
|
};
|
108
108
|
|
109
|
-
/**
|
110
|
-
* Checks whether or not a given group node has any dynamic elements.
|
111
|
-
*
|
112
|
-
* @param {ASTNode} root - A node to check.
|
113
|
-
* This node is one of BinaryExpression or ConditionalExpression.
|
114
|
-
* @returns {boolean} `true` if the node is dynamic.
|
115
|
-
*/
|
116
|
-
function hasDynamicExpressions(root) {
|
117
|
-
let retv = false;
|
118
|
-
const traverser = new Traverser();
|
119
|
-
|
120
|
-
traverser.traverse(root, {
|
121
|
-
enter(node) {
|
122
|
-
if (DYNAMIC_PATTERN.test(node.type)) {
|
123
|
-
retv = true;
|
124
|
-
this.break();
|
125
|
-
} else if (SKIP_PATTERN.test(node.type)) {
|
126
|
-
this.skip();
|
127
|
-
}
|
128
|
-
}
|
129
|
-
});
|
130
|
-
|
131
|
-
return retv;
|
132
|
-
}
|
133
|
-
|
134
|
-
/**
|
135
|
-
* Creates the loop condition information from a given reference.
|
136
|
-
*
|
137
|
-
* @param {eslint-scope.Reference} reference - A reference to create.
|
138
|
-
* @returns {LoopConditionInfo|null} Created loop condition info, or null.
|
139
|
-
*/
|
140
|
-
function toLoopCondition(reference) {
|
141
|
-
if (reference.init) {
|
142
|
-
return null;
|
143
|
-
}
|
144
|
-
|
145
|
-
let group = null;
|
146
|
-
let child = reference.identifier;
|
147
|
-
let node = child.parent;
|
148
|
-
|
149
|
-
while (node) {
|
150
|
-
if (SENTINEL_PATTERN.test(node.type)) {
|
151
|
-
if (LOOP_PATTERN.test(node.type) && node.test === child) {
|
152
|
-
|
153
|
-
// This reference is inside of a loop condition.
|
154
|
-
return {
|
155
|
-
reference,
|
156
|
-
group,
|
157
|
-
isInLoop: isInLoop[node.type].bind(null, node),
|
158
|
-
modified: false
|
159
|
-
};
|
160
|
-
}
|
161
|
-
|
162
|
-
// This reference is outside of a loop condition.
|
163
|
-
break;
|
164
|
-
}
|
165
|
-
|
166
|
-
/*
|
167
|
-
* If it's inside of a group, OK if either operand is modified.
|
168
|
-
* So stores the group this reference belongs to.
|
169
|
-
*/
|
170
|
-
if (GROUP_PATTERN.test(node.type)) {
|
171
|
-
|
172
|
-
// If this expression is dynamic, no need to check.
|
173
|
-
if (hasDynamicExpressions(node)) {
|
174
|
-
break;
|
175
|
-
} else {
|
176
|
-
group = node;
|
177
|
-
}
|
178
|
-
}
|
179
|
-
|
180
|
-
child = node;
|
181
|
-
node = node.parent;
|
182
|
-
}
|
183
|
-
|
184
|
-
return null;
|
185
|
-
}
|
186
|
-
|
187
109
|
/**
|
188
110
|
* Gets the function which encloses a given reference.
|
189
111
|
* This supports only FunctionDeclaration.
|
@@ -247,13 +169,15 @@ module.exports = {
|
|
247
169
|
docs: {
|
248
170
|
description: "disallow unmodified loop conditions",
|
249
171
|
category: "Best Practices",
|
250
|
-
recommended: false
|
172
|
+
recommended: false,
|
173
|
+
url: "https://eslint.org/docs/rules/no-unmodified-loop-condition"
|
251
174
|
},
|
252
175
|
|
253
176
|
schema: []
|
254
177
|
},
|
255
178
|
|
256
179
|
create(context) {
|
180
|
+
const sourceCode = context.getSourceCode();
|
257
181
|
let groupMap = null;
|
258
182
|
|
259
183
|
/**
|
@@ -307,6 +231,84 @@ module.exports = {
|
|
307
231
|
}
|
308
232
|
}
|
309
233
|
|
234
|
+
/**
|
235
|
+
* Checks whether or not a given group node has any dynamic elements.
|
236
|
+
*
|
237
|
+
* @param {ASTNode} root - A node to check.
|
238
|
+
* This node is one of BinaryExpression or ConditionalExpression.
|
239
|
+
* @returns {boolean} `true` if the node is dynamic.
|
240
|
+
*/
|
241
|
+
function hasDynamicExpressions(root) {
|
242
|
+
let retv = false;
|
243
|
+
|
244
|
+
Traverser.traverse(root, {
|
245
|
+
visitorKeys: sourceCode.visitorKeys,
|
246
|
+
enter(node) {
|
247
|
+
if (DYNAMIC_PATTERN.test(node.type)) {
|
248
|
+
retv = true;
|
249
|
+
this.break();
|
250
|
+
} else if (SKIP_PATTERN.test(node.type)) {
|
251
|
+
this.skip();
|
252
|
+
}
|
253
|
+
}
|
254
|
+
});
|
255
|
+
|
256
|
+
return retv;
|
257
|
+
}
|
258
|
+
|
259
|
+
/**
|
260
|
+
* Creates the loop condition information from a given reference.
|
261
|
+
*
|
262
|
+
* @param {eslint-scope.Reference} reference - A reference to create.
|
263
|
+
* @returns {LoopConditionInfo|null} Created loop condition info, or null.
|
264
|
+
*/
|
265
|
+
function toLoopCondition(reference) {
|
266
|
+
if (reference.init) {
|
267
|
+
return null;
|
268
|
+
}
|
269
|
+
|
270
|
+
let group = null;
|
271
|
+
let child = reference.identifier;
|
272
|
+
let node = child.parent;
|
273
|
+
|
274
|
+
while (node) {
|
275
|
+
if (SENTINEL_PATTERN.test(node.type)) {
|
276
|
+
if (LOOP_PATTERN.test(node.type) && node.test === child) {
|
277
|
+
|
278
|
+
// This reference is inside of a loop condition.
|
279
|
+
return {
|
280
|
+
reference,
|
281
|
+
group,
|
282
|
+
isInLoop: isInLoop[node.type].bind(null, node),
|
283
|
+
modified: false
|
284
|
+
};
|
285
|
+
}
|
286
|
+
|
287
|
+
// This reference is outside of a loop condition.
|
288
|
+
break;
|
289
|
+
}
|
290
|
+
|
291
|
+
/*
|
292
|
+
* If it's inside of a group, OK if either operand is modified.
|
293
|
+
* So stores the group this reference belongs to.
|
294
|
+
*/
|
295
|
+
if (GROUP_PATTERN.test(node.type)) {
|
296
|
+
|
297
|
+
// If this expression is dynamic, no need to check.
|
298
|
+
if (hasDynamicExpressions(node)) {
|
299
|
+
break;
|
300
|
+
} else {
|
301
|
+
group = node;
|
302
|
+
}
|
303
|
+
}
|
304
|
+
|
305
|
+
child = node;
|
306
|
+
node = node.parent;
|
307
|
+
}
|
308
|
+
|
309
|
+
return null;
|
310
|
+
}
|
311
|
+
|
310
312
|
/**
|
311
313
|
* Finds unmodified references which are inside of a loop condition.
|
312
314
|
* Then reports the references which are outside of groups.
|
@@ -27,7 +27,8 @@ module.exports = {
|
|
27
27
|
docs: {
|
28
28
|
description: "disallow ternary operators when simpler alternatives exist",
|
29
29
|
category: "Stylistic Issues",
|
30
|
-
recommended: false
|
30
|
+
recommended: false,
|
31
|
+
url: "https://eslint.org/docs/rules/no-unneeded-ternary"
|
31
32
|
},
|
32
33
|
|
33
34
|
schema: [
|
@@ -104,7 +104,8 @@ module.exports = {
|
|
104
104
|
docs: {
|
105
105
|
description: "disallow unreachable code after `return`, `throw`, `continue`, and `break` statements",
|
106
106
|
category: "Possible Errors",
|
107
|
-
recommended: true
|
107
|
+
recommended: true,
|
108
|
+
url: "https://eslint.org/docs/rules/no-unreachable"
|
108
109
|
},
|
109
110
|
|
110
111
|
schema: []
|
@@ -44,7 +44,8 @@ module.exports = {
|
|
44
44
|
docs: {
|
45
45
|
description: "disallow negating the left operand of relational operators",
|
46
46
|
category: "Possible Errors",
|
47
|
-
recommended: true
|
47
|
+
recommended: true,
|
48
|
+
url: "https://eslint.org/docs/rules/no-unsafe-negation"
|
48
49
|
},
|
49
50
|
schema: [],
|
50
51
|
fixable: "code"
|
@@ -21,7 +21,8 @@ module.exports = {
|
|
21
21
|
docs: {
|
22
22
|
description: "disallow unused variables",
|
23
23
|
category: "Variables",
|
24
|
-
recommended: true
|
24
|
+
recommended: true,
|
25
|
+
url: "https://eslint.org/docs/rules/no-unused-vars"
|
25
26
|
},
|
26
27
|
|
27
28
|
schema: [
|
@@ -105,26 +106,21 @@ module.exports = {
|
|
105
106
|
* @returns {string} The warning message to be used with this unused variable.
|
106
107
|
*/
|
107
108
|
function getDefinedMessage(unusedVar) {
|
109
|
+
const defType = unusedVar.defs && unusedVar.defs[0] && unusedVar.defs[0].type;
|
108
110
|
let type;
|
109
111
|
let pattern;
|
110
112
|
|
111
|
-
if (config.
|
113
|
+
if (defType === "CatchClause" && config.caughtErrorsIgnorePattern) {
|
114
|
+
type = "args";
|
115
|
+
pattern = config.caughtErrorsIgnorePattern.toString();
|
116
|
+
} else if (defType === "Parameter" && config.argsIgnorePattern) {
|
117
|
+
type = "args";
|
118
|
+
pattern = config.argsIgnorePattern.toString();
|
119
|
+
} else if (defType !== "Parameter" && config.varsIgnorePattern) {
|
112
120
|
type = "vars";
|
113
121
|
pattern = config.varsIgnorePattern.toString();
|
114
122
|
}
|
115
123
|
|
116
|
-
if (unusedVar.defs && unusedVar.defs[0] && unusedVar.defs[0].type) {
|
117
|
-
const defType = unusedVar.defs[0].type;
|
118
|
-
|
119
|
-
if (defType === "CatchClause" && config.caughtErrorsIgnorePattern) {
|
120
|
-
type = "args";
|
121
|
-
pattern = config.caughtErrorsIgnorePattern.toString();
|
122
|
-
} else if (defType === "Parameter" && config.argsIgnorePattern) {
|
123
|
-
type = "args";
|
124
|
-
pattern = config.argsIgnorePattern.toString();
|
125
|
-
}
|
126
|
-
}
|
127
|
-
|
128
124
|
const additional = type ? ` Allowed unused ${type} must match ${pattern}.` : "";
|
129
125
|
|
130
126
|
return `'{{name}}' is defined but never used.${additional}`;
|
@@ -139,7 +139,8 @@ module.exports = {
|
|
139
139
|
docs: {
|
140
140
|
description: "disallow the use of variables before they are defined",
|
141
141
|
category: "Variables",
|
142
|
-
recommended: false
|
142
|
+
recommended: false,
|
143
|
+
url: "https://eslint.org/docs/rules/no-use-before-define"
|
143
144
|
},
|
144
145
|
|
145
146
|
schema: [
|
@@ -52,7 +52,8 @@ module.exports = {
|
|
52
52
|
docs: {
|
53
53
|
description: "disallow unnecessary calls to `.call()` and `.apply()`",
|
54
54
|
category: "Best Practices",
|
55
|
-
recommended: false
|
55
|
+
recommended: false,
|
56
|
+
url: "https://eslint.org/docs/rules/no-useless-call"
|
56
57
|
},
|
57
58
|
|
58
59
|
schema: []
|
@@ -21,7 +21,8 @@ module.exports = {
|
|
21
21
|
docs: {
|
22
22
|
description: "disallow unnecessary computed property keys in object literals",
|
23
23
|
category: "ECMAScript 6",
|
24
|
-
recommended: false
|
24
|
+
recommended: false,
|
25
|
+
url: "https://eslint.org/docs/rules/no-useless-computed-key"
|
25
26
|
},
|
26
27
|
|
27
28
|
schema: [],
|
@@ -69,7 +69,8 @@ module.exports = {
|
|
69
69
|
docs: {
|
70
70
|
description: "disallow unnecessary concatenation of literals or template literals",
|
71
71
|
category: "Best Practices",
|
72
|
-
recommended: false
|
72
|
+
recommended: false,
|
73
|
+
url: "https://eslint.org/docs/rules/no-useless-concat"
|
73
74
|
},
|
74
75
|
|
75
76
|
schema: []
|
@@ -145,7 +145,8 @@ module.exports = {
|
|
145
145
|
docs: {
|
146
146
|
description: "disallow unnecessary constructors",
|
147
147
|
category: "ECMAScript 6",
|
148
|
-
recommended: false
|
148
|
+
recommended: false,
|
149
|
+
url: "https://eslint.org/docs/rules/no-useless-constructor"
|
149
150
|
},
|
150
151
|
|
151
152
|
schema: []
|
@@ -14,7 +14,8 @@ module.exports = {
|
|
14
14
|
docs: {
|
15
15
|
description: "disallow renaming import, export, and destructured assignments to the same name",
|
16
16
|
category: "ECMAScript 6",
|
17
|
-
recommended: false
|
17
|
+
recommended: false,
|
18
|
+
url: "https://eslint.org/docs/rules/no-useless-rename"
|
18
19
|
},
|
19
20
|
fixable: "code",
|
20
21
|
schema: [
|