eslint 6.5.1 → 6.7.2
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 +118 -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 +65 -34
- 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-unexpected-multiline.js +8 -0
- 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 +7 -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 +94 -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
@@ -78,8 +78,7 @@ const hasOwnProperty = Function.call.bind(Object.hasOwnProperty);
|
|
78
78
|
/**
|
79
79
|
* Clones a given value deeply.
|
80
80
|
* Note: This ignores `parent` property.
|
81
|
-
*
|
82
|
-
* @param {any} x - A value to clone.
|
81
|
+
* @param {any} x A value to clone.
|
83
82
|
* @returns {any} A cloned value.
|
84
83
|
*/
|
85
84
|
function cloneDeeplyExcludesParent(x) {
|
@@ -104,8 +103,7 @@ function cloneDeeplyExcludesParent(x) {
|
|
104
103
|
|
105
104
|
/**
|
106
105
|
* Freezes a given value deeply.
|
107
|
-
*
|
108
|
-
* @param {any} x - A value to freeze.
|
106
|
+
* @param {any} x A value to freeze.
|
109
107
|
* @returns {void}
|
110
108
|
*/
|
111
109
|
function freezeDeeply(x) {
|
@@ -146,8 +144,8 @@ const IT = Symbol("it");
|
|
146
144
|
/**
|
147
145
|
* This is `it` default handler if `it` don't exist.
|
148
146
|
* @this {Mocha}
|
149
|
-
* @param {string} text
|
150
|
-
* @param {Function} method
|
147
|
+
* @param {string} text The description of the test case.
|
148
|
+
* @param {Function} method The logic of the test case.
|
151
149
|
* @returns {any} Returned value of `method`.
|
152
150
|
*/
|
153
151
|
function itDefaultHandler(text, method) {
|
@@ -164,8 +162,8 @@ function itDefaultHandler(text, method) {
|
|
164
162
|
/**
|
165
163
|
* This is `describe` default handler if `describe` don't exist.
|
166
164
|
* @this {Mocha}
|
167
|
-
* @param {string} text
|
168
|
-
* @param {Function} method
|
165
|
+
* @param {string} text The description of the test case.
|
166
|
+
* @param {Function} method The logic of the test case.
|
169
167
|
* @returns {any} Returned value of `method`.
|
170
168
|
*/
|
171
169
|
function describeDefaultHandler(text, method) {
|
@@ -351,7 +349,7 @@ class RuleTester {
|
|
351
349
|
filename = item.filename;
|
352
350
|
}
|
353
351
|
|
354
|
-
if (
|
352
|
+
if (hasOwnProperty(item, "options")) {
|
355
353
|
assert(Array.isArray(item.options), "options must be an array");
|
356
354
|
config.rules[ruleName] = [1].concat(item.options);
|
357
355
|
} else {
|
@@ -579,21 +577,55 @@ class RuleTester {
|
|
579
577
|
assert.strictEqual(message.nodeType, error.type, `Error type should be ${error.type}, found ${message.nodeType}`);
|
580
578
|
}
|
581
579
|
|
582
|
-
if (
|
580
|
+
if (hasOwnProperty(error, "line")) {
|
583
581
|
assert.strictEqual(message.line, error.line, `Error line should be ${error.line}`);
|
584
582
|
}
|
585
583
|
|
586
|
-
if (
|
584
|
+
if (hasOwnProperty(error, "column")) {
|
587
585
|
assert.strictEqual(message.column, error.column, `Error column should be ${error.column}`);
|
588
586
|
}
|
589
587
|
|
590
|
-
if (
|
588
|
+
if (hasOwnProperty(error, "endLine")) {
|
591
589
|
assert.strictEqual(message.endLine, error.endLine, `Error endLine should be ${error.endLine}`);
|
592
590
|
}
|
593
591
|
|
594
|
-
if (
|
592
|
+
if (hasOwnProperty(error, "endColumn")) {
|
595
593
|
assert.strictEqual(message.endColumn, error.endColumn, `Error endColumn should be ${error.endColumn}`);
|
596
594
|
}
|
595
|
+
|
596
|
+
if (hasOwnProperty(error, "suggestions")) {
|
597
|
+
|
598
|
+
// Support asserting there are no suggestions
|
599
|
+
if (!error.suggestions) {
|
600
|
+
assert.strictEqual(message.suggestions, error.suggestions, `Error should have no suggestions on error with message: "${message.message}"`);
|
601
|
+
} else {
|
602
|
+
assert.strictEqual(Array.isArray(message.suggestions), true, `Error should have an array of suggestions. Instead received "${message.suggestions}" on error with message: "${message.message}"`);
|
603
|
+
assert.strictEqual(message.suggestions.length, error.suggestions.length, `Error should have ${error.suggestions.length} suggestions. Instead found ${message.suggestions.length} suggestions`);
|
604
|
+
|
605
|
+
error.suggestions.forEach((expectedSuggestion, index) => {
|
606
|
+
const actualSuggestion = message.suggestions[index];
|
607
|
+
|
608
|
+
/**
|
609
|
+
* Tests equality of a suggestion key if that key is defined in the expected output.
|
610
|
+
* @param {string} key Key to validate from the suggestion object
|
611
|
+
* @returns {void}
|
612
|
+
*/
|
613
|
+
function assertSuggestionKeyEquals(key) {
|
614
|
+
if (hasOwnProperty(expectedSuggestion, key)) {
|
615
|
+
assert.deepStrictEqual(actualSuggestion[key], expectedSuggestion[key], `Error suggestion at index: ${index} should have desc of: "${actualSuggestion[key]}"`);
|
616
|
+
}
|
617
|
+
}
|
618
|
+
assertSuggestionKeyEquals("desc");
|
619
|
+
assertSuggestionKeyEquals("messageId");
|
620
|
+
|
621
|
+
if (hasOwnProperty(expectedSuggestion, "output")) {
|
622
|
+
const codeWithAppliedSuggestion = SourceCodeFixer.applyFixes(item.code, [actualSuggestion]).output;
|
623
|
+
|
624
|
+
assert.strictEqual(codeWithAppliedSuggestion, expectedSuggestion.output, `Expected the applied suggestion fix to match the test suggestion output for suggestion at index: ${index} on error with message: "${message.message}"`);
|
625
|
+
}
|
626
|
+
});
|
627
|
+
}
|
628
|
+
}
|
597
629
|
} else {
|
598
630
|
|
599
631
|
// Message was an unexpected type
|
@@ -602,7 +634,7 @@ class RuleTester {
|
|
602
634
|
}
|
603
635
|
}
|
604
636
|
|
605
|
-
if (
|
637
|
+
if (hasOwnProperty(item, "output")) {
|
606
638
|
if (item.output === null) {
|
607
639
|
assert.strictEqual(
|
608
640
|
result.output,
|
@@ -79,7 +79,7 @@ function areEqualKeys(left, right) {
|
|
79
79
|
|
80
80
|
/**
|
81
81
|
* Checks whether or not a given node is of an accessor kind ('get' or 'set').
|
82
|
-
* @param {ASTNode} node
|
82
|
+
* @param {ASTNode} node A node to check.
|
83
83
|
* @returns {boolean} `true` if the node is of an accessor kind.
|
84
84
|
*/
|
85
85
|
function isAccessorKind(node) {
|
@@ -88,8 +88,8 @@ function isAccessorKind(node) {
|
|
88
88
|
|
89
89
|
/**
|
90
90
|
* Checks whether or not a given node is an `Identifier` node which was named a given name.
|
91
|
-
* @param {ASTNode} node
|
92
|
-
* @param {string} name
|
91
|
+
* @param {ASTNode} node A node to check.
|
92
|
+
* @param {string} name An expected name of the node.
|
93
93
|
* @returns {boolean} `true` if the node is an `Identifier` node which was named as expected.
|
94
94
|
*/
|
95
95
|
function isIdentifier(node, name) {
|
@@ -98,10 +98,10 @@ function isIdentifier(node, name) {
|
|
98
98
|
|
99
99
|
/**
|
100
100
|
* Checks whether or not a given node is an argument of a specified method call.
|
101
|
-
* @param {ASTNode} node
|
102
|
-
* @param {number} index
|
103
|
-
* @param {string} object
|
104
|
-
* @param {string} property
|
101
|
+
* @param {ASTNode} node A node to check.
|
102
|
+
* @param {number} index An expected index of the node in arguments.
|
103
|
+
* @param {string} object An expected name of the object of the method.
|
104
|
+
* @param {string} property An expected name of the method.
|
105
105
|
* @returns {boolean} `true` if the node is an argument of the specified method call.
|
106
106
|
*/
|
107
107
|
function isArgumentOfMethodCall(node, index, object, property) {
|
@@ -119,7 +119,7 @@ function isArgumentOfMethodCall(node, index, object, property) {
|
|
119
119
|
|
120
120
|
/**
|
121
121
|
* Checks whether or not a given node is a property descriptor.
|
122
|
-
* @param {ASTNode} node
|
122
|
+
* @param {ASTNode} node A node to check.
|
123
123
|
* @returns {boolean} `true` if the node is a property descriptor.
|
124
124
|
*/
|
125
125
|
function isPropertyDescriptor(node) {
|
@@ -65,8 +65,7 @@ module.exports = {
|
|
65
65
|
|
66
66
|
/**
|
67
67
|
* Normalizes a given option value.
|
68
|
-
*
|
69
|
-
* @param {string|Object|undefined} option - An option value to parse.
|
68
|
+
* @param {string|Object|undefined} option An option value to parse.
|
70
69
|
* @returns {{multiline: boolean, minItems: number}} Normalized option object.
|
71
70
|
*/
|
72
71
|
function normalizeOptionValue(option) {
|
@@ -97,8 +96,7 @@ module.exports = {
|
|
97
96
|
|
98
97
|
/**
|
99
98
|
* Normalizes a given option value.
|
100
|
-
*
|
101
|
-
* @param {string|Object|undefined} options - An option value to parse.
|
99
|
+
* @param {string|Object|undefined} options An option value to parse.
|
102
100
|
* @returns {{ArrayExpression: {multiline: boolean, minItems: number}, ArrayPattern: {multiline: boolean, minItems: number}}} Normalized option object.
|
103
101
|
*/
|
104
102
|
function normalizeOptions(options) {
|
@@ -109,8 +107,8 @@ module.exports = {
|
|
109
107
|
|
110
108
|
/**
|
111
109
|
* Reports that there shouldn't be a linebreak after the first token
|
112
|
-
* @param {ASTNode} node
|
113
|
-
* @param {Token} token
|
110
|
+
* @param {ASTNode} node The node to report in the event of an error.
|
111
|
+
* @param {Token} token The token to use for the report.
|
114
112
|
* @returns {void}
|
115
113
|
*/
|
116
114
|
function reportNoBeginningLinebreak(node, token) {
|
@@ -132,8 +130,8 @@ module.exports = {
|
|
132
130
|
|
133
131
|
/**
|
134
132
|
* Reports that there shouldn't be a linebreak before the last token
|
135
|
-
* @param {ASTNode} node
|
136
|
-
* @param {Token} token
|
133
|
+
* @param {ASTNode} node The node to report in the event of an error.
|
134
|
+
* @param {Token} token The token to use for the report.
|
137
135
|
* @returns {void}
|
138
136
|
*/
|
139
137
|
function reportNoEndingLinebreak(node, token) {
|
@@ -155,8 +153,8 @@ module.exports = {
|
|
155
153
|
|
156
154
|
/**
|
157
155
|
* Reports that there should be a linebreak after the first token
|
158
|
-
* @param {ASTNode} node
|
159
|
-
* @param {Token} token
|
156
|
+
* @param {ASTNode} node The node to report in the event of an error.
|
157
|
+
* @param {Token} token The token to use for the report.
|
160
158
|
* @returns {void}
|
161
159
|
*/
|
162
160
|
function reportRequiredBeginningLinebreak(node, token) {
|
@@ -172,8 +170,8 @@ module.exports = {
|
|
172
170
|
|
173
171
|
/**
|
174
172
|
* Reports that there should be a linebreak before the last token
|
175
|
-
* @param {ASTNode} node
|
176
|
-
* @param {Token} token
|
173
|
+
* @param {ASTNode} node The node to report in the event of an error.
|
174
|
+
* @param {Token} token The token to use for the report.
|
177
175
|
* @returns {void}
|
178
176
|
*/
|
179
177
|
function reportRequiredEndingLinebreak(node, token) {
|
@@ -189,8 +187,7 @@ module.exports = {
|
|
189
187
|
|
190
188
|
/**
|
191
189
|
* Reports a given node if it violated this rule.
|
192
|
-
*
|
193
|
-
* @param {ASTNode} node - A node to check. This is an ArrayExpression node or an ArrayPattern node.
|
190
|
+
* @param {ASTNode} node A node to check. This is an ArrayExpression node or an ArrayPattern node.
|
194
191
|
* @returns {void}
|
195
192
|
*/
|
196
193
|
function check(node) {
|
@@ -219,7 +216,7 @@ module.exports = {
|
|
219
216
|
) ||
|
220
217
|
(
|
221
218
|
options.consistent &&
|
222
|
-
|
219
|
+
openBracket.loc.end.line !== first.loc.start.line
|
223
220
|
)
|
224
221
|
);
|
225
222
|
|
@@ -59,7 +59,7 @@ module.exports = {
|
|
59
59
|
* Determines whether an option is set, relative to the spacing option.
|
60
60
|
* If spaced is "always", then check whether option is set to false.
|
61
61
|
* If spaced is "never", then check whether option is set to true.
|
62
|
-
* @param {Object} option
|
62
|
+
* @param {Object} option The option to exclude.
|
63
63
|
* @returns {boolean} Whether or not the property is excluded.
|
64
64
|
*/
|
65
65
|
function isOptionSet(option) {
|
@@ -79,8 +79,8 @@ module.exports = {
|
|
79
79
|
|
80
80
|
/**
|
81
81
|
* Reports that there shouldn't be a space after the first token
|
82
|
-
* @param {ASTNode} node
|
83
|
-
* @param {Token} token
|
82
|
+
* @param {ASTNode} node The node to report in the event of an error.
|
83
|
+
* @param {Token} token The token to use for the report.
|
84
84
|
* @returns {void}
|
85
85
|
*/
|
86
86
|
function reportNoBeginningSpace(node, token) {
|
@@ -101,8 +101,8 @@ module.exports = {
|
|
101
101
|
|
102
102
|
/**
|
103
103
|
* Reports that there shouldn't be a space before the last token
|
104
|
-
* @param {ASTNode} node
|
105
|
-
* @param {Token} token
|
104
|
+
* @param {ASTNode} node The node to report in the event of an error.
|
105
|
+
* @param {Token} token The token to use for the report.
|
106
106
|
* @returns {void}
|
107
107
|
*/
|
108
108
|
function reportNoEndingSpace(node, token) {
|
@@ -123,8 +123,8 @@ module.exports = {
|
|
123
123
|
|
124
124
|
/**
|
125
125
|
* Reports that there should be a space after the first token
|
126
|
-
* @param {ASTNode} node
|
127
|
-
* @param {Token} token
|
126
|
+
* @param {ASTNode} node The node to report in the event of an error.
|
127
|
+
* @param {Token} token The token to use for the report.
|
128
128
|
* @returns {void}
|
129
129
|
*/
|
130
130
|
function reportRequiredBeginningSpace(node, token) {
|
@@ -143,8 +143,8 @@ module.exports = {
|
|
143
143
|
|
144
144
|
/**
|
145
145
|
* Reports that there should be a space before the last token
|
146
|
-
* @param {ASTNode} node
|
147
|
-
* @param {Token} token
|
146
|
+
* @param {ASTNode} node The node to report in the event of an error.
|
147
|
+
* @param {Token} token The token to use for the report.
|
148
148
|
* @returns {void}
|
149
149
|
*/
|
150
150
|
function reportRequiredEndingSpace(node, token) {
|
@@ -163,7 +163,7 @@ module.exports = {
|
|
163
163
|
|
164
164
|
/**
|
165
165
|
* Determines if a node is an object type
|
166
|
-
* @param {ASTNode} node
|
166
|
+
* @param {ASTNode} node The node to check.
|
167
167
|
* @returns {boolean} Whether or not the node is an object type.
|
168
168
|
*/
|
169
169
|
function isObjectType(node) {
|
@@ -172,7 +172,7 @@ module.exports = {
|
|
172
172
|
|
173
173
|
/**
|
174
174
|
* Determines if a node is an array type
|
175
|
-
* @param {ASTNode} node
|
175
|
+
* @param {ASTNode} node The node to check.
|
176
176
|
* @returns {boolean} Whether or not the node is an array type.
|
177
177
|
*/
|
178
178
|
function isArrayType(node) {
|
@@ -181,7 +181,7 @@ module.exports = {
|
|
181
181
|
|
182
182
|
/**
|
183
183
|
* Validates the spacing around array brackets
|
184
|
-
* @param {ASTNode} node
|
184
|
+
* @param {ASTNode} node The node we're checking for spacing
|
185
185
|
* @returns {void}
|
186
186
|
*/
|
187
187
|
function validateArraySpacing(node) {
|
@@ -22,8 +22,7 @@ const TARGET_METHODS = /^(?:every|filter|find(?:Index)?|map|reduce(?:Right)?|som
|
|
22
22
|
|
23
23
|
/**
|
24
24
|
* Checks a given code path segment is reachable.
|
25
|
-
*
|
26
|
-
* @param {CodePathSegment} segment - A segment to check.
|
25
|
+
* @param {CodePathSegment} segment A segment to check.
|
27
26
|
* @returns {boolean} `true` if the segment is reachable.
|
28
27
|
*/
|
29
28
|
function isReachable(segment) {
|
@@ -35,9 +34,8 @@ function isReachable(segment) {
|
|
35
34
|
*
|
36
35
|
* - FunctionExpression -> the function name or `function` keyword.
|
37
36
|
* - ArrowFunctionExpression -> `=>` token.
|
38
|
-
*
|
39
|
-
* @param {
|
40
|
-
* @param {SourceCode} sourceCode - A source code to get tokens.
|
37
|
+
* @param {ASTNode} node A function node to get.
|
38
|
+
* @param {SourceCode} sourceCode A source code to get tokens.
|
41
39
|
* @returns {ASTNode|Token} The node or the token of a location.
|
42
40
|
*/
|
43
41
|
function getLocation(node, sourceCode) {
|
@@ -50,8 +48,7 @@ function getLocation(node, sourceCode) {
|
|
50
48
|
/**
|
51
49
|
* Checks a given node is a MemberExpression node which has the specified name's
|
52
50
|
* property.
|
53
|
-
*
|
54
|
-
* @param {ASTNode} node - A node to check.
|
51
|
+
* @param {ASTNode} node A node to check.
|
55
52
|
* @returns {boolean} `true` if the node is a MemberExpression node which has
|
56
53
|
* the specified name's property
|
57
54
|
*/
|
@@ -65,8 +62,7 @@ function isTargetMethod(node) {
|
|
65
62
|
/**
|
66
63
|
* Checks whether or not a given node is a function expression which is the
|
67
64
|
* callback of an array method.
|
68
|
-
*
|
69
|
-
* @param {ASTNode} node - A node to check. This is one of
|
65
|
+
* @param {ASTNode} node A node to check. This is one of
|
70
66
|
* FunctionExpression or ArrowFunctionExpression.
|
71
67
|
* @returns {boolean} `true` if the node is the callback of an array method.
|
72
68
|
*/
|
@@ -188,8 +184,7 @@ module.exports = {
|
|
188
184
|
*
|
189
185
|
* If the last code path segment is reachable, there are paths which are not
|
190
186
|
* returned or thrown.
|
191
|
-
*
|
192
|
-
* @param {ASTNode} node - A node to check.
|
187
|
+
* @param {ASTNode} node A node to check.
|
193
188
|
* @returns {void}
|
194
189
|
*/
|
195
190
|
function checkLastSegment(node) {
|
@@ -62,8 +62,7 @@ module.exports = {
|
|
62
62
|
|
63
63
|
/**
|
64
64
|
* Normalizes a given option value.
|
65
|
-
*
|
66
|
-
* @param {string|Object|undefined} providedOption - An option value to parse.
|
65
|
+
* @param {string|Object|undefined} providedOption An option value to parse.
|
67
66
|
* @returns {{multiline: boolean, minItems: number}} Normalized option object.
|
68
67
|
*/
|
69
68
|
function normalizeOptionValue(providedOption) {
|
@@ -90,8 +89,7 @@ module.exports = {
|
|
90
89
|
|
91
90
|
/**
|
92
91
|
* Normalizes a given option value.
|
93
|
-
*
|
94
|
-
* @param {string|Object|undefined} options - An option value to parse.
|
92
|
+
* @param {string|Object|undefined} options An option value to parse.
|
95
93
|
* @returns {{ArrayExpression: {multiline: boolean, minItems: number}, ArrayPattern: {multiline: boolean, minItems: number}}} Normalized option object.
|
96
94
|
*/
|
97
95
|
function normalizeOptions(options) {
|
@@ -102,7 +100,7 @@ module.exports = {
|
|
102
100
|
|
103
101
|
/**
|
104
102
|
* Reports that there shouldn't be a line break after the first token
|
105
|
-
* @param {Token} token
|
103
|
+
* @param {Token} token The token to use for the report.
|
106
104
|
* @returns {void}
|
107
105
|
*/
|
108
106
|
function reportNoLineBreak(token) {
|
@@ -151,7 +149,7 @@ module.exports = {
|
|
151
149
|
|
152
150
|
/**
|
153
151
|
* Reports that there should be a line break after the first token
|
154
|
-
* @param {Token} token
|
152
|
+
* @param {Token} token The token to use for the report.
|
155
153
|
* @returns {void}
|
156
154
|
*/
|
157
155
|
function reportRequiredLineBreak(token) {
|
@@ -171,8 +169,7 @@ module.exports = {
|
|
171
169
|
|
172
170
|
/**
|
173
171
|
* Reports a given node if it violated this rule.
|
174
|
-
*
|
175
|
-
* @param {ASTNode} node - A node to check. This is an ObjectExpression node or an ObjectPattern node.
|
172
|
+
* @param {ASTNode} node A node to check. This is an ObjectExpression node or an ObjectPattern node.
|
176
173
|
* @returns {void}
|
177
174
|
*/
|
178
175
|
function check(node) {
|
@@ -31,7 +31,7 @@ module.exports = {
|
|
31
31
|
|
32
32
|
/**
|
33
33
|
* Makes a block scope.
|
34
|
-
* @param {ASTNode} node
|
34
|
+
* @param {ASTNode} node A node of a scope.
|
35
35
|
* @returns {void}
|
36
36
|
*/
|
37
37
|
function enterScope(node) {
|
@@ -48,7 +48,7 @@ module.exports = {
|
|
48
48
|
|
49
49
|
/**
|
50
50
|
* Reports a given reference.
|
51
|
-
* @param {eslint-scope.Reference} reference
|
51
|
+
* @param {eslint-scope.Reference} reference A reference to report.
|
52
52
|
* @returns {void}
|
53
53
|
*/
|
54
54
|
function report(reference) {
|
@@ -59,7 +59,7 @@ module.exports = {
|
|
59
59
|
|
60
60
|
/**
|
61
61
|
* Finds and reports references which are outside of valid scopes.
|
62
|
-
* @param {ASTNode} node
|
62
|
+
* @param {ASTNode} node A node to get variables.
|
63
63
|
* @returns {void}
|
64
64
|
*/
|
65
65
|
function checkForVariables(node) {
|
@@ -41,7 +41,7 @@ module.exports = {
|
|
41
41
|
|
42
42
|
/**
|
43
43
|
* Gets the open brace token from a given node.
|
44
|
-
* @param {ASTNode} node
|
44
|
+
* @param {ASTNode} node A BlockStatement/SwitchStatement node to get.
|
45
45
|
* @returns {Token} The token of the open brace.
|
46
46
|
*/
|
47
47
|
function getOpenBrace(node) {
|
@@ -58,8 +58,8 @@ module.exports = {
|
|
58
58
|
* Checks whether or not:
|
59
59
|
* - given tokens are on same line.
|
60
60
|
* - there is/isn't a space between given tokens.
|
61
|
-
* @param {Token} left
|
62
|
-
* @param {Token} right
|
61
|
+
* @param {Token} left A token to check.
|
62
|
+
* @param {Token} right The token which is next to `left`.
|
63
63
|
* @returns {boolean}
|
64
64
|
* When the option is `"always"`, `true` if there are one or more spaces between given tokens.
|
65
65
|
* When the option is `"never"`, `true` if there are not any spaces between given tokens.
|
@@ -74,7 +74,7 @@ module.exports = {
|
|
74
74
|
|
75
75
|
/**
|
76
76
|
* Reports invalid spacing style inside braces.
|
77
|
-
* @param {ASTNode} node
|
77
|
+
* @param {ASTNode} node A BlockStatement/SwitchStatement node to get.
|
78
78
|
* @returns {void}
|
79
79
|
*/
|
80
80
|
function checkSpacingInsideBraces(node) {
|
package/lib/rules/camelcase.js
CHANGED
@@ -28,6 +28,10 @@ module.exports = {
|
|
28
28
|
type: "boolean",
|
29
29
|
default: false
|
30
30
|
},
|
31
|
+
ignoreImports: {
|
32
|
+
type: "boolean",
|
33
|
+
default: false
|
34
|
+
},
|
31
35
|
properties: {
|
32
36
|
enum: ["always", "never"]
|
33
37
|
},
|
@@ -56,6 +60,7 @@ module.exports = {
|
|
56
60
|
const options = context.options[0] || {};
|
57
61
|
let properties = options.properties || "";
|
58
62
|
const ignoreDestructuring = options.ignoreDestructuring;
|
63
|
+
const ignoreImports = options.ignoreImports;
|
59
64
|
const allow = options.allow || [];
|
60
65
|
|
61
66
|
if (properties !== "always" && properties !== "never") {
|
@@ -79,7 +84,7 @@ module.exports = {
|
|
79
84
|
function isUnderscored(name) {
|
80
85
|
|
81
86
|
// if there's an underscore, it might be A_CONSTANT, which is okay
|
82
|
-
return name.
|
87
|
+
return name.includes("_") && name !== name.toUpperCase();
|
83
88
|
}
|
84
89
|
|
85
90
|
/**
|
@@ -89,9 +94,9 @@ module.exports = {
|
|
89
94
|
* @private
|
90
95
|
*/
|
91
96
|
function isAllowed(name) {
|
92
|
-
return allow.
|
97
|
+
return allow.some(
|
93
98
|
entry => name === entry || name.match(new RegExp(entry, "u"))
|
94
|
-
)
|
99
|
+
);
|
95
100
|
}
|
96
101
|
|
97
102
|
/**
|
@@ -127,7 +132,7 @@ module.exports = {
|
|
127
132
|
* @private
|
128
133
|
*/
|
129
134
|
function report(node) {
|
130
|
-
if (reported.
|
135
|
+
if (!reported.includes(node)) {
|
131
136
|
reported.push(node);
|
132
137
|
context.report({ node, messageId: "notCamelCase", data: { name: node.name } });
|
133
138
|
}
|
@@ -209,10 +214,18 @@ module.exports = {
|
|
209
214
|
}
|
210
215
|
|
211
216
|
// Check if it's an import specifier
|
212
|
-
} else if (["ImportSpecifier", "ImportNamespaceSpecifier", "ImportDefaultSpecifier"].
|
217
|
+
} else if (["ImportSpecifier", "ImportNamespaceSpecifier", "ImportDefaultSpecifier"].includes(node.parent.type)) {
|
218
|
+
|
219
|
+
if (node.parent.type === "ImportSpecifier" && ignoreImports) {
|
220
|
+
return;
|
221
|
+
}
|
213
222
|
|
214
223
|
// Report only if the local imported identifier is underscored
|
215
|
-
if (
|
224
|
+
if (
|
225
|
+
node.parent.local &&
|
226
|
+
node.parent.local.name === node.name &&
|
227
|
+
nameIsUnderscored
|
228
|
+
) {
|
216
229
|
report(node);
|
217
230
|
}
|
218
231
|
|
@@ -54,7 +54,6 @@ const DEFAULTS = {
|
|
54
54
|
* set is returned. Options specified in overrides will take priority
|
55
55
|
* over options specified in the main options object, which will in
|
56
56
|
* turn take priority over the rule's defaults.
|
57
|
-
*
|
58
57
|
* @param {Object|string} rawOptions The user-provided options.
|
59
58
|
* @param {string} which Either "line" or "block".
|
60
59
|
* @returns {Object} The normalized options.
|
@@ -65,7 +64,6 @@ function getNormalizedOptions(rawOptions, which) {
|
|
65
64
|
|
66
65
|
/**
|
67
66
|
* Get normalized options for block and line comments.
|
68
|
-
*
|
69
67
|
* @param {Object|string} rawOptions The user-provided options.
|
70
68
|
* @returns {Object} An object with "Line" and "Block" keys and corresponding
|
71
69
|
* normalized options objects.
|
@@ -82,7 +80,6 @@ function getAllNormalizedOptions(rawOptions = {}) {
|
|
82
80
|
* options.
|
83
81
|
*
|
84
82
|
* This is done in order to avoid invoking the RegExp constructor repeatedly.
|
85
|
-
*
|
86
83
|
* @param {Object} normalizedOptions The normalized rule options.
|
87
84
|
* @returns {void}
|
88
85
|
*/
|
@@ -162,7 +159,6 @@ module.exports = {
|
|
162
159
|
* Also, it follows from this definition that only block comments can
|
163
160
|
* be considered as possibly inline. This is because line comments
|
164
161
|
* would consume any following tokens on the same line as the comment.
|
165
|
-
*
|
166
162
|
* @param {ASTNode} comment The comment node to check.
|
167
163
|
* @returns {boolean} True if the comment is an inline comment, false
|
168
164
|
* otherwise.
|
@@ -181,7 +177,6 @@ module.exports = {
|
|
181
177
|
|
182
178
|
/**
|
183
179
|
* Determine if a comment follows another comment.
|
184
|
-
*
|
185
180
|
* @param {ASTNode} comment The comment to check.
|
186
181
|
* @returns {boolean} True if the comment follows a valid comment.
|
187
182
|
*/
|
@@ -196,7 +191,6 @@ module.exports = {
|
|
196
191
|
|
197
192
|
/**
|
198
193
|
* Check a comment to determine if it is valid for this rule.
|
199
|
-
*
|
200
194
|
* @param {ASTNode} comment The comment node to process.
|
201
195
|
* @param {Object} options The options for checking this comment.
|
202
196
|
* @returns {boolean} True if the comment is valid, false otherwise.
|
@@ -261,7 +255,6 @@ module.exports = {
|
|
261
255
|
|
262
256
|
/**
|
263
257
|
* Process a comment to determine if it needs to be reported.
|
264
|
-
*
|
265
258
|
* @param {ASTNode} comment The comment node to process.
|
266
259
|
* @returns {void}
|
267
260
|
*/
|
@@ -61,7 +61,7 @@ module.exports = {
|
|
61
61
|
|
62
62
|
/**
|
63
63
|
* Check if the node is an instance method
|
64
|
-
* @param {ASTNode} node
|
64
|
+
* @param {ASTNode} node node to check
|
65
65
|
* @returns {boolean} True if its an instance method
|
66
66
|
* @private
|
67
67
|
*/
|
@@ -71,7 +71,7 @@ module.exports = {
|
|
71
71
|
|
72
72
|
/**
|
73
73
|
* Check if the node is an instance method not excluded by config
|
74
|
-
* @param {ASTNode} node
|
74
|
+
* @param {ASTNode} node node to check
|
75
75
|
* @returns {boolean} True if it is an instance method, and not excluded by config
|
76
76
|
* @private
|
77
77
|
*/
|
@@ -84,7 +84,7 @@ module.exports = {
|
|
84
84
|
* Checks if we are leaving a function that is a method, and reports if 'this' has not been used.
|
85
85
|
* Static methods and the constructor are exempt.
|
86
86
|
* Then pops the context off the stack.
|
87
|
-
* @param {ASTNode} node
|
87
|
+
* @param {ASTNode} node A function node that was entered.
|
88
88
|
* @returns {void}
|
89
89
|
* @private
|
90
90
|
*/
|