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
@@ -11,13 +11,17 @@
|
|
11
11
|
|
12
12
|
module.exports = {
|
13
13
|
meta: {
|
14
|
+
type: "suggestion",
|
15
|
+
|
14
16
|
docs: {
|
15
17
|
description: "disallow renaming import, export, and destructured assignments to the same name",
|
16
18
|
category: "ECMAScript 6",
|
17
19
|
recommended: false,
|
18
20
|
url: "https://eslint.org/docs/rules/no-useless-rename"
|
19
21
|
},
|
22
|
+
|
20
23
|
fixable: "code",
|
24
|
+
|
21
25
|
schema: [
|
22
26
|
{
|
23
27
|
type: "object",
|
@@ -66,12 +66,15 @@ function isInFinally(node) {
|
|
66
66
|
|
67
67
|
module.exports = {
|
68
68
|
meta: {
|
69
|
+
type: "suggestion",
|
70
|
+
|
69
71
|
docs: {
|
70
72
|
description: "disallow redundant return statements",
|
71
73
|
category: "Best Practices",
|
72
74
|
recommended: false,
|
73
75
|
url: "https://eslint.org/docs/rules/no-useless-return"
|
74
76
|
},
|
77
|
+
|
75
78
|
fixable: "code",
|
76
79
|
schema: []
|
77
80
|
},
|
package/lib/rules/no-var.js
CHANGED
package/lib/rules/no-void.js
CHANGED
package/lib/rules/no-with.js
CHANGED
@@ -12,13 +12,17 @@ const POSITION_SCHEMA = { enum: ["beside", "below", "any"] };
|
|
12
12
|
|
13
13
|
module.exports = {
|
14
14
|
meta: {
|
15
|
+
type: "layout",
|
16
|
+
|
15
17
|
docs: {
|
16
18
|
description: "enforce the location of single-line statements",
|
17
19
|
category: "Stylistic Issues",
|
18
20
|
recommended: false,
|
19
21
|
url: "https://eslint.org/docs/rules/nonblock-statement-body-position"
|
20
22
|
},
|
23
|
+
|
21
24
|
fixable: "whitespace",
|
25
|
+
|
22
26
|
schema: [
|
23
27
|
POSITION_SCHEMA,
|
24
28
|
{
|
@@ -134,13 +134,17 @@ function areLineBreaksRequired(node, options, first, last) {
|
|
134
134
|
|
135
135
|
module.exports = {
|
136
136
|
meta: {
|
137
|
+
type: "layout",
|
138
|
+
|
137
139
|
docs: {
|
138
140
|
description: "enforce consistent line breaks inside braces",
|
139
141
|
category: "Stylistic Issues",
|
140
142
|
recommended: false,
|
141
143
|
url: "https://eslint.org/docs/rules/object-curly-newline"
|
142
144
|
},
|
145
|
+
|
143
146
|
fixable: "whitespace",
|
147
|
+
|
144
148
|
schema: [
|
145
149
|
{
|
146
150
|
oneOf: [
|
@@ -168,7 +172,6 @@ module.exports = {
|
|
168
172
|
/**
|
169
173
|
* Reports a given node if it violated this rule.
|
170
174
|
* @param {ASTNode} node - A node to check. This is an ObjectExpression, ObjectPattern, ImportDeclaration or ExportNamedDeclaration node.
|
171
|
-
* @param {{multiline: boolean, minProperties: number, consistent: boolean}} options - An option object.
|
172
175
|
* @returns {void}
|
173
176
|
*/
|
174
177
|
function check(node) {
|
@@ -11,6 +11,8 @@
|
|
11
11
|
|
12
12
|
module.exports = {
|
13
13
|
meta: {
|
14
|
+
type: "layout",
|
15
|
+
|
14
16
|
docs: {
|
15
17
|
description: "enforce placing object properties on separate lines",
|
16
18
|
category: "Stylistic Issues",
|
@@ -38,8 +40,7 @@ module.exports = {
|
|
38
40
|
|
39
41
|
create(context) {
|
40
42
|
const allowSameLine = context.options[0] && (
|
41
|
-
Boolean(context.options[0].allowAllPropertiesOnSameLine) ||
|
42
|
-
Boolean(context.options[0].allowMultiplePropertiesPerLine) // Deprecated
|
43
|
+
(Boolean(context.options[0].allowAllPropertiesOnSameLine) || Boolean(context.options[0].allowMultiplePropertiesPerLine)) // Deprecated
|
43
44
|
);
|
44
45
|
const errorMessage = allowSameLine
|
45
46
|
? "Object properties must go on a new line if they aren't all on the same line."
|
@@ -24,6 +24,8 @@ const astUtils = require("../util/ast-utils");
|
|
24
24
|
//------------------------------------------------------------------------------
|
25
25
|
module.exports = {
|
26
26
|
meta: {
|
27
|
+
type: "suggestion",
|
28
|
+
|
27
29
|
docs: {
|
28
30
|
description: "require or disallow method and property shorthand syntax for object literals",
|
29
31
|
category: "ECMAScript 6",
|
package/lib/rules/one-var.js
CHANGED
@@ -11,6 +11,8 @@
|
|
11
11
|
|
12
12
|
module.exports = {
|
13
13
|
meta: {
|
14
|
+
type: "suggestion",
|
15
|
+
|
14
16
|
docs: {
|
15
17
|
description: "enforce variables to be declared either together or separately in functions",
|
16
18
|
category: "Stylistic Issues",
|
@@ -308,7 +310,6 @@ module.exports = {
|
|
308
310
|
/**
|
309
311
|
* Fixer to split a VariableDeclaration into individual declarations
|
310
312
|
* @param {VariableDeclaration} declaration The `VariableDeclaration` to split
|
311
|
-
* @param {?Function} filter Function to filter the declarations
|
312
313
|
* @returns {Function} The fixer function
|
313
314
|
*/
|
314
315
|
function splitDeclarations(declaration) {
|
@@ -36,6 +36,36 @@ function newKeywordTester(keyword) {
|
|
36
36
|
};
|
37
37
|
}
|
38
38
|
|
39
|
+
/**
|
40
|
+
* Creates tester which check if a node starts with specific keyword and spans a single line.
|
41
|
+
*
|
42
|
+
* @param {string} keyword The keyword to test.
|
43
|
+
* @returns {Object} the created tester.
|
44
|
+
* @private
|
45
|
+
*/
|
46
|
+
function newSinglelineKeywordTester(keyword) {
|
47
|
+
return {
|
48
|
+
test: (node, sourceCode) =>
|
49
|
+
node.loc.start.line === node.loc.end.line &&
|
50
|
+
sourceCode.getFirstToken(node).value === keyword
|
51
|
+
};
|
52
|
+
}
|
53
|
+
|
54
|
+
/**
|
55
|
+
* Creates tester which check if a node starts with specific keyword and spans multiple lines.
|
56
|
+
*
|
57
|
+
* @param {string} keyword The keyword to test.
|
58
|
+
* @returns {Object} the created tester.
|
59
|
+
* @private
|
60
|
+
*/
|
61
|
+
function newMultilineKeywordTester(keyword) {
|
62
|
+
return {
|
63
|
+
test: (node, sourceCode) =>
|
64
|
+
node.loc.start.line !== node.loc.end.line &&
|
65
|
+
sourceCode.getFirstToken(node).value === keyword
|
66
|
+
};
|
67
|
+
}
|
68
|
+
|
39
69
|
/**
|
40
70
|
* Creates tester which check if a node is specific type.
|
41
71
|
*
|
@@ -368,6 +398,13 @@ const StatementTypes = {
|
|
368
398
|
!isDirectivePrologue(node, sourceCode)
|
369
399
|
},
|
370
400
|
|
401
|
+
"multiline-const": newMultilineKeywordTester("const"),
|
402
|
+
"multiline-let": newMultilineKeywordTester("let"),
|
403
|
+
"multiline-var": newMultilineKeywordTester("var"),
|
404
|
+
"singleline-const": newSinglelineKeywordTester("const"),
|
405
|
+
"singleline-let": newSinglelineKeywordTester("let"),
|
406
|
+
"singleline-var": newSinglelineKeywordTester("var"),
|
407
|
+
|
371
408
|
block: newNodeTypeTester("BlockStatement"),
|
372
409
|
empty: newNodeTypeTester("EmptyStatement"),
|
373
410
|
function: newNodeTypeTester("FunctionDeclaration"),
|
@@ -400,13 +437,17 @@ const StatementTypes = {
|
|
400
437
|
|
401
438
|
module.exports = {
|
402
439
|
meta: {
|
440
|
+
type: "layout",
|
441
|
+
|
403
442
|
docs: {
|
404
443
|
description: "require or disallow padding lines between statements",
|
405
444
|
category: "Stylistic Issues",
|
406
445
|
recommended: false,
|
407
446
|
url: "https://eslint.org/docs/rules/padding-line-between-statements"
|
408
447
|
},
|
448
|
+
|
409
449
|
fixable: "whitespace",
|
450
|
+
|
410
451
|
schema: {
|
411
452
|
definitions: {
|
412
453
|
paddingType: {
|
@@ -57,6 +57,7 @@ function canBecomeVariableDeclaration(identifier) {
|
|
57
57
|
* @returns {boolean} Indicates if the variable is from outer scope or function parameters.
|
58
58
|
*/
|
59
59
|
function isOuterVariableInDestructing(name, initScope) {
|
60
|
+
|
60
61
|
if (initScope.through.find(ref => ref.resolved && ref.resolved.name === name)) {
|
61
62
|
return true;
|
62
63
|
}
|
@@ -96,6 +97,54 @@ function getDestructuringHost(reference) {
|
|
96
97
|
return node;
|
97
98
|
}
|
98
99
|
|
100
|
+
/**
|
101
|
+
* Determines if a destructuring assignment node contains
|
102
|
+
* any MemberExpression nodes. This is used to determine if a
|
103
|
+
* variable that is only written once using destructuring can be
|
104
|
+
* safely converted into a const declaration.
|
105
|
+
* @param {ASTNode} node The ObjectPattern or ArrayPattern node to check.
|
106
|
+
* @returns {boolean} True if the destructuring pattern contains
|
107
|
+
* a MemberExpression, false if not.
|
108
|
+
*/
|
109
|
+
function hasMemberExpressionAssignment(node) {
|
110
|
+
switch (node.type) {
|
111
|
+
case "ObjectPattern":
|
112
|
+
return node.properties.some(prop => {
|
113
|
+
if (prop) {
|
114
|
+
|
115
|
+
/*
|
116
|
+
* Spread elements have an argument property while
|
117
|
+
* others have a value property. Because different
|
118
|
+
* parsers use different node types for spread elements,
|
119
|
+
* we just check if there is an argument property.
|
120
|
+
*/
|
121
|
+
return hasMemberExpressionAssignment(prop.argument || prop.value);
|
122
|
+
}
|
123
|
+
|
124
|
+
return false;
|
125
|
+
});
|
126
|
+
|
127
|
+
case "ArrayPattern":
|
128
|
+
return node.elements.some(element => {
|
129
|
+
if (element) {
|
130
|
+
return hasMemberExpressionAssignment(element);
|
131
|
+
}
|
132
|
+
|
133
|
+
return false;
|
134
|
+
});
|
135
|
+
|
136
|
+
case "AssignmentPattern":
|
137
|
+
return hasMemberExpressionAssignment(node.left);
|
138
|
+
|
139
|
+
case "MemberExpression":
|
140
|
+
return true;
|
141
|
+
|
142
|
+
// no default
|
143
|
+
}
|
144
|
+
|
145
|
+
return false;
|
146
|
+
}
|
147
|
+
|
99
148
|
/**
|
100
149
|
* Gets an identifier node of a given variable.
|
101
150
|
*
|
@@ -148,7 +197,8 @@ function getIdentifierIfShouldBeConst(variable, ignoreReadBeforeAssign) {
|
|
148
197
|
|
149
198
|
if (destructuringHost !== null && destructuringHost.left !== void 0) {
|
150
199
|
const leftNode = destructuringHost.left;
|
151
|
-
let hasOuterVariables = false
|
200
|
+
let hasOuterVariables = false,
|
201
|
+
hasNonIdentifiers = false;
|
152
202
|
|
153
203
|
if (leftNode.type === "ObjectPattern") {
|
154
204
|
const properties = leftNode.properties;
|
@@ -157,16 +207,23 @@ function getIdentifierIfShouldBeConst(variable, ignoreReadBeforeAssign) {
|
|
157
207
|
.filter(prop => prop.value)
|
158
208
|
.map(prop => prop.value.name)
|
159
209
|
.some(name => isOuterVariableInDestructing(name, variable.scope));
|
210
|
+
|
211
|
+
hasNonIdentifiers = hasMemberExpressionAssignment(leftNode);
|
212
|
+
|
160
213
|
} else if (leftNode.type === "ArrayPattern") {
|
161
214
|
const elements = leftNode.elements;
|
162
215
|
|
163
216
|
hasOuterVariables = elements
|
164
217
|
.map(element => element && element.name)
|
165
218
|
.some(name => isOuterVariableInDestructing(name, variable.scope));
|
219
|
+
|
220
|
+
hasNonIdentifiers = hasMemberExpressionAssignment(leftNode);
|
166
221
|
}
|
167
|
-
|
222
|
+
|
223
|
+
if (hasOuterVariables || hasNonIdentifiers) {
|
168
224
|
return null;
|
169
225
|
}
|
226
|
+
|
170
227
|
}
|
171
228
|
|
172
229
|
writer = reference;
|
@@ -192,9 +249,11 @@ function getIdentifierIfShouldBeConst(variable, ignoreReadBeforeAssign) {
|
|
192
249
|
if (!shouldBeConst) {
|
193
250
|
return null;
|
194
251
|
}
|
252
|
+
|
195
253
|
if (isReadBeforeInit) {
|
196
254
|
return variable.defs[0].name;
|
197
255
|
}
|
256
|
+
|
198
257
|
return writer.identifier;
|
199
258
|
}
|
200
259
|
|
@@ -271,6 +330,8 @@ function findUp(node, type, shouldStop) {
|
|
271
330
|
|
272
331
|
module.exports = {
|
273
332
|
meta: {
|
333
|
+
type: "suggestion",
|
334
|
+
|
274
335
|
docs: {
|
275
336
|
description: "require `const` declarations for variables that are never reassigned after declared",
|
276
337
|
category: "ECMAScript 6",
|
@@ -295,9 +356,11 @@ module.exports = {
|
|
295
356
|
create(context) {
|
296
357
|
const options = context.options[0] || {};
|
297
358
|
const sourceCode = context.getSourceCode();
|
298
|
-
const
|
359
|
+
const shouldMatchAnyDestructuredVariable = options.destructuring !== "all";
|
299
360
|
const ignoreReadBeforeAssign = options.ignoreReadBeforeAssign === true;
|
300
361
|
const variables = [];
|
362
|
+
let reportCount = 0;
|
363
|
+
let name = "";
|
301
364
|
|
302
365
|
/**
|
303
366
|
* Reports given identifier nodes if all of the nodes should be declared
|
@@ -316,16 +379,43 @@ module.exports = {
|
|
316
379
|
function checkGroup(nodes) {
|
317
380
|
const nodesToReport = nodes.filter(Boolean);
|
318
381
|
|
319
|
-
if (nodes.length && (
|
382
|
+
if (nodes.length && (shouldMatchAnyDestructuredVariable || nodesToReport.length === nodes.length)) {
|
320
383
|
const varDeclParent = findUp(nodes[0], "VariableDeclaration", parentNode => parentNode.type.endsWith("Statement"));
|
321
|
-
const
|
384
|
+
const isVarDecParentNull = varDeclParent === null;
|
385
|
+
|
386
|
+
if (!isVarDecParentNull && varDeclParent.declarations.length > 0) {
|
387
|
+
const firstDeclaration = varDeclParent.declarations[0];
|
388
|
+
|
389
|
+
if (firstDeclaration.init) {
|
390
|
+
const firstDecParent = firstDeclaration.init.parent;
|
391
|
+
|
392
|
+
/*
|
393
|
+
* First we check the declaration type and then depending on
|
394
|
+
* if the type is a "VariableDeclarator" or its an "ObjectPattern"
|
395
|
+
* we compare the name from the first identifier, if the names are different
|
396
|
+
* we assign the new name and reset the count of reportCount and nodeCount in
|
397
|
+
* order to check each block for the number of reported errors and base our fix
|
398
|
+
* based on comparing nodes.length and nodesToReport.length.
|
399
|
+
*/
|
400
|
+
|
401
|
+
if (firstDecParent.type === "VariableDeclarator") {
|
402
|
+
|
403
|
+
if (firstDecParent.id.name !== name) {
|
404
|
+
name = firstDecParent.id.name;
|
405
|
+
reportCount = 0;
|
406
|
+
}
|
407
|
+
|
408
|
+
if (firstDecParent.id.type === "ObjectPattern") {
|
409
|
+
if (firstDecParent.init.name !== name) {
|
410
|
+
name = firstDecParent.init.name;
|
411
|
+
reportCount = 0;
|
412
|
+
}
|
413
|
+
}
|
414
|
+
}
|
415
|
+
}
|
416
|
+
}
|
322
417
|
|
323
|
-
|
324
|
-
* If there are multiple variable declarations, like {let a = 1, b = 2}, then
|
325
|
-
* do not attempt to fix if one of the declarations should be `const`. It's
|
326
|
-
* too hard to know how the developer would want to automatically resolve the issue.
|
327
|
-
*/
|
328
|
-
varDeclParent.declarations.length === 1 &&
|
418
|
+
let shouldFix = varDeclParent &&
|
329
419
|
|
330
420
|
// Don't do a fix unless the variable is initialized (or it's in a for-in or for-of loop)
|
331
421
|
(varDeclParent.parent.type === "ForInStatement" || varDeclParent.parent.type === "ForOfStatement" || varDeclParent.declarations[0].init) &&
|
@@ -337,6 +427,21 @@ module.exports = {
|
|
337
427
|
*/
|
338
428
|
nodesToReport.length === nodes.length;
|
339
429
|
|
430
|
+
if (!isVarDecParentNull && varDeclParent.declarations && varDeclParent.declarations.length !== 1) {
|
431
|
+
|
432
|
+
if (varDeclParent && varDeclParent.declarations && varDeclParent.declarations.length >= 1) {
|
433
|
+
|
434
|
+
/*
|
435
|
+
* Add nodesToReport.length to a count, then comparing the count to the length
|
436
|
+
* of the declarations in the current block.
|
437
|
+
*/
|
438
|
+
|
439
|
+
reportCount += nodesToReport.length;
|
440
|
+
|
441
|
+
shouldFix = shouldFix && (reportCount === varDeclParent.declarations.length);
|
442
|
+
}
|
443
|
+
}
|
444
|
+
|
340
445
|
nodesToReport.forEach(node => {
|
341
446
|
context.report({
|
342
447
|
node,
|
@@ -10,12 +10,15 @@
|
|
10
10
|
|
11
11
|
module.exports = {
|
12
12
|
meta: {
|
13
|
+
type: "suggestion",
|
14
|
+
|
13
15
|
docs: {
|
14
16
|
description: "require destructuring from arrays and/or objects",
|
15
17
|
category: "ECMAScript 6",
|
16
18
|
recommended: false,
|
17
19
|
url: "https://eslint.org/docs/rules/prefer-destructuring"
|
18
20
|
},
|
21
|
+
|
19
22
|
schema: [
|
20
23
|
{
|
21
24
|
|
@@ -38,6 +38,8 @@ function isParseInt(calleeNode) {
|
|
38
38
|
|
39
39
|
module.exports = {
|
40
40
|
meta: {
|
41
|
+
type: "suggestion",
|
42
|
+
|
41
43
|
docs: {
|
42
44
|
description: "disallow `parseInt()` and `Number.parseInt()` in favor of binary, octal, and hexadecimal literals",
|
43
45
|
category: "ECMAScript 6",
|
@@ -46,7 +48,6 @@ module.exports = {
|
|
46
48
|
},
|
47
49
|
|
48
50
|
schema: [],
|
49
|
-
|
50
51
|
fixable: "code"
|
51
52
|
},
|
52
53
|
|
@@ -212,6 +212,8 @@ function defineFixer(node, sourceCode) {
|
|
212
212
|
|
213
213
|
module.exports = {
|
214
214
|
meta: {
|
215
|
+
type: "suggestion",
|
216
|
+
|
215
217
|
docs: {
|
216
218
|
description:
|
217
219
|
"disallow using Object.assign with an object literal as the first argument and prefer the use of object spread instead.",
|
@@ -219,8 +221,10 @@ module.exports = {
|
|
219
221
|
recommended: false,
|
220
222
|
url: "https://eslint.org/docs/rules/prefer-object-spread"
|
221
223
|
},
|
224
|
+
|
222
225
|
schema: [],
|
223
226
|
fixable: "code",
|
227
|
+
|
224
228
|
messages: {
|
225
229
|
useSpreadMessage: "Use an object spread instead of `Object.assign` eg: `{ ...foo }`",
|
226
230
|
useLiteralMessage: "Use an object literal instead of `Object.assign`. eg: `{ foo: bar }`"
|
@@ -12,13 +12,17 @@ const astUtils = require("../util/ast-utils");
|
|
12
12
|
|
13
13
|
module.exports = {
|
14
14
|
meta: {
|
15
|
+
type: "suggestion",
|
16
|
+
|
15
17
|
docs: {
|
16
18
|
description: "require using Error objects as Promise rejection reasons",
|
17
19
|
category: "Best Practices",
|
18
20
|
recommended: false,
|
19
21
|
url: "https://eslint.org/docs/rules/prefer-promise-reject-errors"
|
20
22
|
},
|
23
|
+
|
21
24
|
fixable: null,
|
25
|
+
|
22
26
|
schema: [
|
23
27
|
{
|
24
28
|
type: "object",
|
@@ -11,16 +11,19 @@
|
|
11
11
|
|
12
12
|
module.exports = {
|
13
13
|
meta: {
|
14
|
+
type: "suggestion",
|
15
|
+
|
14
16
|
docs: {
|
15
17
|
description: "require `Reflect` methods where applicable",
|
16
18
|
category: "ECMAScript 6",
|
17
19
|
recommended: false,
|
18
|
-
replacedBy: [],
|
19
20
|
url: "https://eslint.org/docs/rules/prefer-reflect"
|
20
21
|
},
|
21
22
|
|
22
23
|
deprecated: true,
|
23
24
|
|
25
|
+
replacedBy: [],
|
26
|
+
|
24
27
|
schema: [
|
25
28
|
{
|
26
29
|
type: "object",
|
@@ -49,6 +49,8 @@ function isValidThisArg(expectedThis, thisArg, context) {
|
|
49
49
|
|
50
50
|
module.exports = {
|
51
51
|
meta: {
|
52
|
+
type: "suggestion",
|
53
|
+
|
52
54
|
docs: {
|
53
55
|
description: "require spread operators instead of `.apply()`",
|
54
56
|
category: "ECMAScript 6",
|
@@ -57,7 +59,6 @@ module.exports = {
|
|
57
59
|
},
|
58
60
|
|
59
61
|
schema: [],
|
60
|
-
|
61
62
|
fixable: "code"
|
62
63
|
},
|
63
64
|
|
@@ -141,6 +141,8 @@ function endsWithTemplateCurly(node) {
|
|
141
141
|
|
142
142
|
module.exports = {
|
143
143
|
meta: {
|
144
|
+
type: "suggestion",
|
145
|
+
|
144
146
|
docs: {
|
145
147
|
description: "require template literals instead of string concatenation",
|
146
148
|
category: "ECMAScript 6",
|
@@ -149,7 +151,6 @@ module.exports = {
|
|
149
151
|
},
|
150
152
|
|
151
153
|
schema: [],
|
152
|
-
|
153
154
|
fixable: "code"
|
154
155
|
},
|
155
156
|
|