eslint 5.7.0 → 5.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +76 -0
- package/README.md +2 -2
- package/conf/eslint-recommended.js +1 -0
- package/lib/cli-engine.js +129 -32
- package/lib/cli.js +6 -1
- package/lib/config/autoconfig.js +0 -1
- package/lib/config/config-rule.js +4 -4
- package/lib/config/config-validator.js +2 -2
- package/lib/config.js +15 -2
- package/lib/linter.js +17 -120
- package/lib/options.js +5 -0
- package/lib/rules/accessor-pairs.js +4 -0
- package/lib/rules/array-bracket-newline.js +5 -0
- package/lib/rules/array-bracket-spacing.js +5 -0
- package/lib/rules/array-callback-return.js +2 -0
- package/lib/rules/array-element-newline.js +4 -1
- package/lib/rules/arrow-body-style.js +2 -0
- package/lib/rules/arrow-parens.js +2 -0
- package/lib/rules/arrow-spacing.js +2 -0
- package/lib/rules/block-scoped-var.js +2 -0
- package/lib/rules/block-spacing.js +2 -0
- package/lib/rules/brace-style.js +2 -0
- package/lib/rules/callback-return.js +2 -0
- package/lib/rules/camelcase.js +26 -14
- package/lib/rules/capitalized-comments.js +4 -0
- package/lib/rules/class-methods-use-this.js +3 -0
- package/lib/rules/comma-dangle.js +4 -0
- package/lib/rules/comma-spacing.js +2 -0
- package/lib/rules/comma-style.js +12 -2
- package/lib/rules/complexity.js +2 -0
- package/lib/rules/computed-property-spacing.js +2 -0
- package/lib/rules/consistent-return.js +2 -0
- package/lib/rules/consistent-this.js +2 -0
- package/lib/rules/constructor-super.js +2 -0
- package/lib/rules/curly.js +2 -0
- package/lib/rules/default-case.js +2 -0
- package/lib/rules/dot-location.js +2 -0
- package/lib/rules/dot-notation.js +2 -0
- package/lib/rules/eol-last.js +5 -0
- package/lib/rules/eqeqeq.js +2 -1
- package/lib/rules/for-direction.js +4 -0
- package/lib/rules/func-call-spacing.js +4 -0
- package/lib/rules/func-name-matching.js +3 -0
- package/lib/rules/func-names.js +3 -0
- package/lib/rules/func-style.js +3 -0
- package/lib/rules/function-paren-newline.js +5 -0
- package/lib/rules/generator-star-spacing.js +3 -0
- package/lib/rules/getter-return.js +5 -0
- package/lib/rules/global-require.js +2 -0
- package/lib/rules/guard-for-in.js +2 -0
- package/lib/rules/handle-callback-err.js +3 -1
- package/lib/rules/id-blacklist.js +2 -0
- package/lib/rules/id-length.js +2 -0
- package/lib/rules/id-match.js +101 -27
- package/lib/rules/implicit-arrow-linebreak.js +147 -2
- package/lib/rules/indent-legacy.js +4 -4
- package/lib/rules/indent.js +31 -23
- package/lib/rules/init-declarations.js +2 -0
- package/lib/rules/jsx-quotes.js +2 -0
- package/lib/rules/key-spacing.js +4 -3
- package/lib/rules/keyword-spacing.js +7 -1
- package/lib/rules/line-comment-position.js +2 -0
- package/lib/rules/linebreak-style.js +2 -0
- package/lib/rules/lines-around-comment.js +2 -0
- package/lib/rules/lines-around-directive.js +6 -2
- package/lib/rules/lines-between-class-members.js +2 -0
- package/lib/rules/max-classes-per-file.js +4 -0
- package/lib/rules/max-depth.js +2 -0
- package/lib/rules/max-len.js +2 -0
- package/lib/rules/max-lines-per-function.js +2 -0
- package/lib/rules/max-lines.js +2 -0
- package/lib/rules/max-nested-callbacks.js +2 -0
- package/lib/rules/max-params.js +2 -0
- package/lib/rules/max-statements-per-line.js +2 -0
- package/lib/rules/max-statements.js +2 -0
- package/lib/rules/multiline-comment-style.js +3 -0
- package/lib/rules/multiline-ternary.js +3 -0
- package/lib/rules/new-cap.js +2 -0
- package/lib/rules/new-parens.js +2 -1
- package/lib/rules/newline-after-var.js +5 -2
- package/lib/rules/newline-before-return.js +6 -3
- package/lib/rules/newline-per-chained-call.js +4 -0
- package/lib/rules/no-alert.js +2 -0
- package/lib/rules/no-array-constructor.js +2 -0
- package/lib/rules/no-async-promise-executor.js +3 -0
- package/lib/rules/no-await-in-loop.js +4 -0
- package/lib/rules/no-bitwise.js +2 -0
- package/lib/rules/no-buffer-constructor.js +4 -0
- package/lib/rules/no-caller.js +2 -0
- package/lib/rules/no-case-declarations.js +2 -0
- package/lib/rules/no-catch-shadow.js +6 -3
- package/lib/rules/no-class-assign.js +2 -0
- package/lib/rules/no-compare-neg-zero.js +4 -0
- package/lib/rules/no-cond-assign.js +2 -0
- package/lib/rules/no-confusing-arrow.js +2 -0
- package/lib/rules/no-console.js +2 -0
- package/lib/rules/no-const-assign.js +2 -0
- package/lib/rules/no-constant-condition.js +2 -1
- package/lib/rules/no-continue.js +2 -0
- package/lib/rules/no-control-regex.js +4 -2
- package/lib/rules/no-debugger.js +4 -0
- package/lib/rules/no-delete-var.js +2 -0
- package/lib/rules/no-div-regex.js +2 -0
- package/lib/rules/no-dupe-args.js +2 -0
- package/lib/rules/no-dupe-class-members.js +2 -0
- package/lib/rules/no-dupe-keys.js +2 -0
- package/lib/rules/no-duplicate-case.js +2 -0
- package/lib/rules/no-duplicate-imports.js +2 -0
- package/lib/rules/no-else-return.js +2 -1
- package/lib/rules/no-empty-character-class.js +2 -0
- package/lib/rules/no-empty-function.js +2 -0
- package/lib/rules/no-empty-pattern.js +2 -0
- package/lib/rules/no-empty.js +2 -0
- package/lib/rules/no-eq-null.js +2 -0
- package/lib/rules/no-eval.js +2 -0
- package/lib/rules/no-ex-assign.js +2 -0
- package/lib/rules/no-extend-native.js +2 -0
- 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 +5 -6
- package/lib/rules/no-extra-semi.js +2 -0
- package/lib/rules/no-fallthrough.js +2 -0
- package/lib/rules/no-floating-decimal.js +2 -1
- package/lib/rules/no-func-assign.js +2 -0
- package/lib/rules/no-global-assign.js +2 -0
- package/lib/rules/no-implicit-coercion.js +3 -0
- package/lib/rules/no-implicit-globals.js +2 -0
- package/lib/rules/no-implied-eval.js +3 -1
- package/lib/rules/no-inline-comments.js +2 -0
- package/lib/rules/no-inner-declarations.js +2 -0
- package/lib/rules/no-invalid-regexp.js +2 -0
- package/lib/rules/no-invalid-this.js +2 -0
- package/lib/rules/no-irregular-whitespace.js +7 -9
- package/lib/rules/no-iterator.js +2 -0
- package/lib/rules/no-label-var.js +2 -0
- package/lib/rules/no-labels.js +2 -0
- package/lib/rules/no-lone-blocks.js +2 -0
- package/lib/rules/no-lonely-if.js +2 -1
- package/lib/rules/no-loop-func.js +2 -0
- package/lib/rules/no-magic-numbers.js +3 -0
- package/lib/rules/no-misleading-character-class.js +4 -0
- package/lib/rules/no-mixed-operators.js +3 -0
- package/lib/rules/no-mixed-requires.js +2 -0
- package/lib/rules/no-mixed-spaces-and-tabs.js +2 -0
- package/lib/rules/no-multi-assign.js +3 -0
- package/lib/rules/no-multi-spaces.js +2 -0
- package/lib/rules/no-multi-str.js +2 -0
- package/lib/rules/no-multiple-empty-lines.js +2 -0
- package/lib/rules/no-native-reassign.js +4 -1
- package/lib/rules/no-negated-condition.js +2 -0
- package/lib/rules/no-negated-in-lhs.js +5 -2
- package/lib/rules/no-nested-ternary.js +2 -0
- package/lib/rules/no-new-func.js +2 -0
- package/lib/rules/no-new-object.js +2 -0
- package/lib/rules/no-new-require.js +2 -0
- package/lib/rules/no-new-symbol.js +2 -0
- package/lib/rules/no-new-wrappers.js +2 -0
- package/lib/rules/no-new.js +2 -0
- package/lib/rules/no-obj-calls.js +2 -0
- package/lib/rules/no-octal-escape.js +2 -0
- package/lib/rules/no-octal.js +2 -0
- package/lib/rules/no-param-reassign.js +2 -0
- package/lib/rules/no-path-concat.js +2 -0
- package/lib/rules/no-plusplus.js +2 -0
- package/lib/rules/no-process-env.js +2 -0
- package/lib/rules/no-process-exit.js +2 -0
- package/lib/rules/no-proto.js +2 -0
- package/lib/rules/no-prototype-builtins.js +2 -0
- package/lib/rules/no-redeclare.js +2 -0
- package/lib/rules/no-regex-spaces.js +2 -1
- package/lib/rules/no-restricted-globals.js +2 -0
- package/lib/rules/no-restricted-imports.js +41 -23
- package/lib/rules/no-restricted-modules.js +2 -0
- package/lib/rules/no-restricted-properties.js +2 -0
- package/lib/rules/no-restricted-syntax.js +2 -0
- package/lib/rules/no-return-assign.js +2 -0
- package/lib/rules/no-return-await.js +4 -0
- package/lib/rules/no-script-url.js +2 -0
- package/lib/rules/no-self-assign.js +2 -0
- package/lib/rules/no-self-compare.js +2 -0
- package/lib/rules/no-sequences.js +2 -0
- package/lib/rules/no-shadow-restricted-names.js +2 -0
- package/lib/rules/no-shadow.js +2 -0
- package/lib/rules/no-spaced-func.js +4 -1
- package/lib/rules/no-sparse-arrays.js +2 -0
- package/lib/rules/no-sync.js +2 -0
- package/lib/rules/no-tabs.js +2 -0
- package/lib/rules/no-template-curly-in-string.js +2 -0
- package/lib/rules/no-ternary.js +2 -0
- package/lib/rules/no-this-before-super.js +2 -1
- package/lib/rules/no-throw-literal.js +2 -0
- package/lib/rules/no-trailing-spaces.js +2 -0
- package/lib/rules/no-undef-init.js +2 -1
- package/lib/rules/no-undef.js +2 -0
- package/lib/rules/no-undefined.js +2 -0
- package/lib/rules/no-underscore-dangle.js +2 -0
- package/lib/rules/no-unexpected-multiline.js +2 -0
- package/lib/rules/no-unmodified-loop-condition.js +2 -0
- package/lib/rules/no-unneeded-ternary.js +2 -0
- package/lib/rules/no-unreachable.js +2 -1
- package/lib/rules/no-unsafe-finally.js +2 -0
- package/lib/rules/no-unsafe-negation.js +3 -0
- package/lib/rules/no-unused-expressions.js +2 -0
- package/lib/rules/no-unused-labels.js +2 -1
- package/lib/rules/no-unused-vars.js +36 -12
- package/lib/rules/no-use-before-define.js +2 -0
- package/lib/rules/no-useless-call.js +2 -0
- package/lib/rules/no-useless-catch.js +51 -0
- package/lib/rules/no-useless-computed-key.js +2 -1
- package/lib/rules/no-useless-concat.js +2 -0
- package/lib/rules/no-useless-constructor.js +2 -0
- package/lib/rules/no-useless-escape.js +2 -0
- package/lib/rules/no-useless-rename.js +4 -0
- package/lib/rules/no-useless-return.js +3 -0
- package/lib/rules/no-var.js +2 -0
- package/lib/rules/no-void.js +2 -0
- package/lib/rules/no-warning-comments.js +2 -0
- package/lib/rules/no-whitespace-before-property.js +2 -0
- package/lib/rules/no-with.js +2 -0
- package/lib/rules/nonblock-statement-body-position.js +4 -0
- package/lib/rules/object-curly-newline.js +4 -1
- package/lib/rules/object-curly-spacing.js +2 -0
- package/lib/rules/object-property-newline.js +3 -2
- package/lib/rules/object-shorthand.js +2 -0
- package/lib/rules/one-var-declaration-per-line.js +2 -0
- package/lib/rules/one-var.js +2 -1
- package/lib/rules/operator-assignment.js +2 -0
- package/lib/rules/operator-linebreak.js +2 -0
- package/lib/rules/padded-blocks.js +2 -0
- package/lib/rules/padding-line-between-statements.js +41 -0
- package/lib/rules/prefer-arrow-callback.js +2 -0
- package/lib/rules/prefer-const.js +116 -11
- package/lib/rules/prefer-destructuring.js +3 -0
- package/lib/rules/prefer-numeric-literals.js +2 -1
- package/lib/rules/prefer-object-spread.js +4 -0
- package/lib/rules/prefer-promise-reject-errors.js +4 -0
- package/lib/rules/prefer-reflect.js +4 -1
- package/lib/rules/prefer-rest-params.js +2 -0
- package/lib/rules/prefer-spread.js +2 -1
- package/lib/rules/prefer-template.js +2 -1
- package/lib/rules/quote-props.js +2 -0
- package/lib/rules/quotes.js +50 -25
- package/lib/rules/radix.js +2 -0
- package/lib/rules/require-atomic-updates.js +4 -0
- package/lib/rules/require-await.js +3 -0
- package/lib/rules/require-jsdoc.js +6 -1
- package/lib/rules/require-unicode-regexp.js +4 -0
- package/lib/rules/require-yield.js +2 -0
- package/lib/rules/rest-spread-spacing.js +4 -0
- package/lib/rules/semi-spacing.js +2 -0
- package/lib/rules/semi-style.js +3 -0
- package/lib/rules/semi.js +2 -0
- package/lib/rules/sort-imports.js +2 -0
- package/lib/rules/sort-keys.js +3 -0
- package/lib/rules/sort-vars.js +2 -0
- package/lib/rules/space-before-blocks.js +46 -35
- package/lib/rules/space-before-function-paren.js +2 -0
- package/lib/rules/space-in-parens.js +2 -1
- package/lib/rules/space-infix-ops.js +6 -1
- package/lib/rules/space-unary-ops.js +2 -0
- package/lib/rules/spaced-comment.js +2 -0
- package/lib/rules/strict.js +2 -0
- package/lib/rules/switch-colon-spacing.js +4 -0
- package/lib/rules/symbol-description.js +2 -0
- package/lib/rules/template-curly-spacing.js +2 -0
- package/lib/rules/template-tag-spacing.js +2 -0
- package/lib/rules/unicode-bom.js +2 -0
- package/lib/rules/use-isnan.js +2 -0
- package/lib/rules/valid-jsdoc.js +6 -1
- package/lib/rules/valid-typeof.js +2 -0
- package/lib/rules/vars-on-top.js +2 -0
- package/lib/rules/wrap-iife.js +2 -0
- package/lib/rules/wrap-regex.js +3 -1
- package/lib/rules/yield-star-spacing.js +2 -0
- package/lib/rules/yoda.js +2 -0
- package/lib/testers/rule-tester.js +2 -2
- package/lib/util/config-comment-parser.js +144 -0
- package/lib/util/glob-utils.js +1 -1
- package/lib/{ignored-paths.js → util/ignored-paths.js} +4 -4
- package/lib/{report-translator.js → util/report-translator.js} +2 -2
- package/lib/util/source-code.js +2 -1
- package/messages/all-files-ignored.txt +1 -1
- package/package.json +10 -11
@@ -53,6 +53,8 @@ const arrayOfStringsOrObjects = {
|
|
53
53
|
|
54
54
|
module.exports = {
|
55
55
|
meta: {
|
56
|
+
type: "suggestion",
|
57
|
+
|
56
58
|
docs: {
|
57
59
|
description: "disallow specified modules when loaded by `import`",
|
58
60
|
category: "ECMAScript 6",
|
@@ -193,7 +195,7 @@ module.exports = {
|
|
193
195
|
/**
|
194
196
|
* Check if the given importNames are restricted given a list of restrictedImportNames.
|
195
197
|
* @param {Set.<string>} importNames - Set of import names that are being imported
|
196
|
-
* @param {[
|
198
|
+
* @param {string[]} restrictedImportNames - array of import names that are restricted for this import
|
197
199
|
* @returns {boolean} whether the objectName is restricted
|
198
200
|
* @private
|
199
201
|
*/
|
@@ -234,31 +236,47 @@ module.exports = {
|
|
234
236
|
return restrictedPatterns.length > 0 && restrictedPatternsMatcher.ignores(importSource);
|
235
237
|
}
|
236
238
|
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
239
|
+
/**
|
240
|
+
* Checks a node to see if any problems should be reported.
|
241
|
+
* @param {ASTNode} node The node to check.
|
242
|
+
* @returns {void}
|
243
|
+
* @private
|
244
|
+
*/
|
245
|
+
function checkNode(node) {
|
246
|
+
const importSource = node.source.value.trim();
|
247
|
+
const importNames = node.specifiers ? node.specifiers.reduce((set, specifier) => {
|
248
|
+
if (specifier.type === "ImportDefaultSpecifier") {
|
249
|
+
set.add("default");
|
250
|
+
} else if (specifier.type === "ImportNamespaceSpecifier") {
|
251
|
+
set.add("*");
|
252
|
+
} else if (specifier.imported) {
|
253
|
+
set.add(specifier.imported.name);
|
254
|
+
} else if (specifier.local) {
|
255
|
+
set.add(specifier.local.name);
|
253
256
|
}
|
257
|
+
return set;
|
258
|
+
}, new Set()) : new Set();
|
254
259
|
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
260
|
+
if (isRestrictedForEverythingImported(importSource, importNames)) {
|
261
|
+
reportPathForEverythingImported(importSource, node);
|
262
|
+
}
|
263
|
+
|
264
|
+
if (isRestrictedPath(importSource, importNames)) {
|
265
|
+
reportPath(node);
|
266
|
+
}
|
267
|
+
if (isRestrictedPattern(importSource)) {
|
268
|
+
reportPathForPatterns(node);
|
261
269
|
}
|
270
|
+
}
|
271
|
+
|
272
|
+
return {
|
273
|
+
ImportDeclaration: checkNode,
|
274
|
+
ExportNamedDeclaration(node) {
|
275
|
+
if (node.source) {
|
276
|
+
checkNode(node);
|
277
|
+
}
|
278
|
+
},
|
279
|
+
ExportAllDeclaration: checkNode
|
262
280
|
};
|
263
281
|
}
|
264
282
|
};
|
@@ -14,6 +14,8 @@ const message = "Redundant use of `await` on a return value.";
|
|
14
14
|
|
15
15
|
module.exports = {
|
16
16
|
meta: {
|
17
|
+
type: "suggestion",
|
18
|
+
|
17
19
|
docs: {
|
18
20
|
description: "disallow unnecessary `return await`",
|
19
21
|
category: "Best Practices",
|
@@ -22,7 +24,9 @@ module.exports = {
|
|
22
24
|
|
23
25
|
url: "https://eslint.org/docs/rules/no-return-await"
|
24
26
|
},
|
27
|
+
|
25
28
|
fixable: null,
|
29
|
+
|
26
30
|
schema: [
|
27
31
|
]
|
28
32
|
},
|
package/lib/rules/no-shadow.js
CHANGED
@@ -12,16 +12,19 @@
|
|
12
12
|
|
13
13
|
module.exports = {
|
14
14
|
meta: {
|
15
|
+
type: "layout",
|
16
|
+
|
15
17
|
docs: {
|
16
18
|
description: "disallow spacing between function identifiers and their applications (deprecated)",
|
17
19
|
category: "Stylistic Issues",
|
18
20
|
recommended: false,
|
19
|
-
replacedBy: ["func-call-spacing"],
|
20
21
|
url: "https://eslint.org/docs/rules/no-spaced-func"
|
21
22
|
},
|
22
23
|
|
23
24
|
deprecated: true,
|
24
25
|
|
26
|
+
replacedBy: ["func-call-spacing"],
|
27
|
+
|
25
28
|
fixable: "whitespace",
|
26
29
|
schema: []
|
27
30
|
},
|
package/lib/rules/no-sync.js
CHANGED
package/lib/rules/no-tabs.js
CHANGED
package/lib/rules/no-ternary.js
CHANGED
@@ -36,6 +36,8 @@ function isConstructorFunction(node) {
|
|
36
36
|
|
37
37
|
module.exports = {
|
38
38
|
meta: {
|
39
|
+
type: "problem",
|
40
|
+
|
39
41
|
docs: {
|
40
42
|
description: "disallow `this`/`super` before calling `super()` in constructors",
|
41
43
|
category: "ECMAScript 6",
|
@@ -169,7 +171,6 @@ module.exports = {
|
|
169
171
|
* invalid node.
|
170
172
|
*
|
171
173
|
* @param {CodePath} codePath - A code path which was ended.
|
172
|
-
* @param {ASTNode} node - The current node.
|
173
174
|
* @returns {void}
|
174
175
|
*/
|
175
176
|
onCodePathEnd(codePath) {
|
@@ -13,6 +13,8 @@ const astUtils = require("../util/ast-utils");
|
|
13
13
|
|
14
14
|
module.exports = {
|
15
15
|
meta: {
|
16
|
+
type: "suggestion",
|
17
|
+
|
16
18
|
docs: {
|
17
19
|
description: "disallow initializing variables to `undefined`",
|
18
20
|
category: "Variables",
|
@@ -21,7 +23,6 @@ module.exports = {
|
|
21
23
|
},
|
22
24
|
|
23
25
|
schema: [],
|
24
|
-
|
25
26
|
fixable: "code"
|
26
27
|
},
|
27
28
|
|
package/lib/rules/no-undef.js
CHANGED
@@ -101,6 +101,8 @@ class ConsecutiveRange {
|
|
101
101
|
|
102
102
|
module.exports = {
|
103
103
|
meta: {
|
104
|
+
type: "problem",
|
105
|
+
|
104
106
|
docs: {
|
105
107
|
description: "disallow unreachable code after `return`, `throw`, `continue`, and `break` statements",
|
106
108
|
category: "Possible Errors",
|
@@ -180,7 +182,6 @@ module.exports = {
|
|
180
182
|
ContinueStatement: reportIfUnreachable,
|
181
183
|
DebuggerStatement: reportIfUnreachable,
|
182
184
|
DoWhileStatement: reportIfUnreachable,
|
183
|
-
EmptyStatement: reportIfUnreachable,
|
184
185
|
ExpressionStatement: reportIfUnreachable,
|
185
186
|
ForInStatement: reportIfUnreachable,
|
186
187
|
ForOfStatement: reportIfUnreachable,
|
@@ -41,12 +41,15 @@ function isNegation(node) {
|
|
41
41
|
|
42
42
|
module.exports = {
|
43
43
|
meta: {
|
44
|
+
type: "problem",
|
45
|
+
|
44
46
|
docs: {
|
45
47
|
description: "disallow negating the left operand of relational operators",
|
46
48
|
category: "Possible Errors",
|
47
49
|
recommended: true,
|
48
50
|
url: "https://eslint.org/docs/rules/no-unsafe-negation"
|
49
51
|
},
|
52
|
+
|
50
53
|
schema: [],
|
51
54
|
fixable: "code"
|
52
55
|
},
|
@@ -18,6 +18,8 @@ const astUtils = require("../util/ast-utils");
|
|
18
18
|
|
19
19
|
module.exports = {
|
20
20
|
meta: {
|
21
|
+
type: "problem",
|
22
|
+
|
21
23
|
docs: {
|
22
24
|
description: "disallow unused variables",
|
23
25
|
category: "Variables",
|
@@ -223,6 +225,32 @@ module.exports = {
|
|
223
225
|
return false;
|
224
226
|
}
|
225
227
|
|
228
|
+
/**
|
229
|
+
* Gets a list of function definitions for a specified variable.
|
230
|
+
* @param {Variable} variable - eslint-scope variable object.
|
231
|
+
* @returns {ASTNode[]} Function nodes.
|
232
|
+
* @private
|
233
|
+
*/
|
234
|
+
function getFunctionDefinitions(variable) {
|
235
|
+
const functionDefinitions = [];
|
236
|
+
|
237
|
+
variable.defs.forEach(def => {
|
238
|
+
const { type, node } = def;
|
239
|
+
|
240
|
+
// FunctionDeclarations
|
241
|
+
if (type === "FunctionName") {
|
242
|
+
functionDefinitions.push(node);
|
243
|
+
}
|
244
|
+
|
245
|
+
// FunctionExpressions
|
246
|
+
if (type === "Variable" && node.init &&
|
247
|
+
(node.init.type === "FunctionExpression" || node.init.type === "ArrowFunctionExpression")) {
|
248
|
+
functionDefinitions.push(node.init);
|
249
|
+
}
|
250
|
+
});
|
251
|
+
return functionDefinitions;
|
252
|
+
}
|
253
|
+
|
226
254
|
/**
|
227
255
|
* Checks the position of given nodes.
|
228
256
|
*
|
@@ -372,22 +400,18 @@ module.exports = {
|
|
372
400
|
return ref.isRead() && (
|
373
401
|
|
374
402
|
// self update. e.g. `a += 1`, `a++`
|
375
|
-
(
|
376
|
-
|
403
|
+
(// in RHS of an assignment for itself. e.g. `a = a + 1`
|
404
|
+
((
|
405
|
+
parent.type === "AssignmentExpression" &&
|
377
406
|
granpa.type === "ExpressionStatement" &&
|
378
407
|
parent.left === id
|
379
|
-
|
408
|
+
) ||
|
380
409
|
(
|
381
410
|
parent.type === "UpdateExpression" &&
|
382
411
|
granpa.type === "ExpressionStatement"
|
383
|
-
) ||
|
384
|
-
|
385
|
-
|
386
|
-
(
|
387
|
-
rhsNode &&
|
388
|
-
isInside(id, rhsNode) &&
|
389
|
-
!isInsideOfStorableFunction(id, rhsNode)
|
390
|
-
)
|
412
|
+
) || rhsNode &&
|
413
|
+
isInside(id, rhsNode) &&
|
414
|
+
!isInsideOfStorableFunction(id, rhsNode)))
|
391
415
|
);
|
392
416
|
}
|
393
417
|
|
@@ -435,7 +459,7 @@ module.exports = {
|
|
435
459
|
* @private
|
436
460
|
*/
|
437
461
|
function isUsedVariable(variable) {
|
438
|
-
const functionNodes = variable
|
462
|
+
const functionNodes = getFunctionDefinitions(variable),
|
439
463
|
isFunctionDefinition = functionNodes.length > 0;
|
440
464
|
let rhsNode = null;
|
441
465
|
|
@@ -0,0 +1,51 @@
|
|
1
|
+
/**
|
2
|
+
* @fileoverview Reports useless `catch` clauses that just rethrow their error.
|
3
|
+
* @author Teddy Katz
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
//------------------------------------------------------------------------------
|
9
|
+
// Rule Definition
|
10
|
+
//------------------------------------------------------------------------------
|
11
|
+
|
12
|
+
module.exports = {
|
13
|
+
meta: {
|
14
|
+
type: "suggestion",
|
15
|
+
|
16
|
+
docs: {
|
17
|
+
description: "disallow unnecessary `catch` clauses",
|
18
|
+
category: "Best Practices",
|
19
|
+
recommended: false,
|
20
|
+
url: "https://eslint.org/docs/rules/no-useless-catch"
|
21
|
+
},
|
22
|
+
|
23
|
+
schema: []
|
24
|
+
},
|
25
|
+
|
26
|
+
create(context) {
|
27
|
+
return {
|
28
|
+
CatchClause(node) {
|
29
|
+
if (
|
30
|
+
node.param.type === "Identifier" &&
|
31
|
+
node.body.body.length &&
|
32
|
+
node.body.body[0].type === "ThrowStatement" &&
|
33
|
+
node.body.body[0].argument.type === "Identifier" &&
|
34
|
+
node.body.body[0].argument.name === node.param.name
|
35
|
+
) {
|
36
|
+
if (node.parent.finalizer) {
|
37
|
+
context.report({
|
38
|
+
node,
|
39
|
+
message: "Unnecessary catch clause."
|
40
|
+
});
|
41
|
+
} else {
|
42
|
+
context.report({
|
43
|
+
node: node.parent,
|
44
|
+
message: "Unnecessary try/catch wrapper."
|
45
|
+
});
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}
|
49
|
+
};
|
50
|
+
}
|
51
|
+
};
|
@@ -18,6 +18,8 @@ const MESSAGE_UNNECESSARY_COMPUTED = "Unnecessarily computed property [{{propert
|
|
18
18
|
|
19
19
|
module.exports = {
|
20
20
|
meta: {
|
21
|
+
type: "suggestion",
|
22
|
+
|
21
23
|
docs: {
|
22
24
|
description: "disallow unnecessary computed property keys in object literals",
|
23
25
|
category: "ECMAScript 6",
|
@@ -26,7 +28,6 @@ module.exports = {
|
|
26
28
|
},
|
27
29
|
|
28
30
|
schema: [],
|
29
|
-
|
30
31
|
fixable: "code"
|
31
32
|
},
|
32
33
|
create(context) {
|