eslint 6.0.0-alpha.1 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +71 -0
- package/README.md +28 -21
- package/bin/eslint.js +2 -2
- package/conf/config-schema.js +38 -31
- package/conf/environments.js +1 -1
- package/conf/eslint-all.js +2 -2
- package/conf/eslint-recommended.js +1 -1
- package/lib/api.js +7 -3
- package/lib/cli-engine/cascading-config-array-factory.js +20 -8
- package/lib/{cli-engine.js → cli-engine/cli-engine.js} +44 -21
- package/lib/cli-engine/config-array/config-array.js +7 -8
- package/lib/cli-engine/config-array/config-dependency.js +2 -2
- package/lib/cli-engine/config-array/extracted-config.js +3 -3
- package/lib/cli-engine/config-array/override-tester.js +11 -1
- package/lib/cli-engine/config-array-factory.js +75 -65
- package/lib/cli-engine/file-enumerator.js +14 -6
- package/lib/{formatters → cli-engine/formatters}/checkstyle.js +1 -1
- package/lib/{formatters → cli-engine/formatters}/codeframe.js +0 -0
- package/lib/{formatters → cli-engine/formatters}/compact.js +0 -0
- package/lib/{formatters → cli-engine/formatters}/html-template-message.html +0 -0
- package/lib/{formatters → cli-engine/formatters}/html-template-page.html +0 -0
- package/lib/{formatters → cli-engine/formatters}/html-template-result.html +0 -0
- package/lib/{formatters → cli-engine/formatters}/html.js +0 -0
- package/lib/{formatters → cli-engine/formatters}/jslint-xml.js +1 -1
- package/lib/{formatters → cli-engine/formatters}/json-with-metadata.js +0 -0
- package/lib/{formatters → cli-engine/formatters}/json.js +0 -0
- package/lib/{formatters → cli-engine/formatters}/junit.js +15 -3
- package/lib/{formatters → cli-engine/formatters}/stylish.js +0 -0
- package/lib/{formatters → cli-engine/formatters}/table.js +0 -0
- package/lib/{formatters → cli-engine/formatters}/tap.js +0 -0
- package/lib/{formatters → cli-engine/formatters}/unix.js +0 -0
- package/lib/{formatters → cli-engine/formatters}/visualstudio.js +0 -0
- package/lib/{util → cli-engine}/hash.js +0 -0
- package/lib/{util → cli-engine}/ignored-paths.js +6 -1
- package/lib/cli-engine/index.js +7 -0
- package/lib/{util → cli-engine}/lint-result-cache.js +0 -0
- package/lib/{load-rules.js → cli-engine/load-rules.js} +0 -0
- package/lib/{util → cli-engine}/naming.js +0 -0
- package/lib/{util → cli-engine}/xml-escape.js +0 -0
- package/lib/cli.js +3 -3
- package/lib/{config → init}/autoconfig.js +3 -3
- package/lib/{config → init}/config-file.js +0 -0
- package/lib/{config → init}/config-initializer.js +6 -6
- package/lib/{config → init}/config-rule.js +8 -2
- package/lib/{util → init}/npm-utils.js +1 -1
- package/lib/{util → init}/source-code-utils.js +16 -1
- package/lib/{util → linter}/apply-disable-directives.js +0 -0
- package/lib/{code-path-analysis → linter/code-path-analysis}/code-path-analyzer.js +19 -6
- package/lib/{code-path-analysis → linter/code-path-analysis}/code-path-segment.js +0 -0
- package/lib/{code-path-analysis → linter/code-path-analysis}/code-path-state.js +0 -0
- package/lib/{code-path-analysis → linter/code-path-analysis}/code-path.js +0 -0
- package/lib/{code-path-analysis → linter/code-path-analysis}/debug-helpers.js +0 -0
- package/lib/{code-path-analysis → linter/code-path-analysis}/fork-context.js +0 -0
- package/lib/{code-path-analysis → linter/code-path-analysis}/id-generator.js +0 -0
- package/lib/{util → linter}/config-comment-parser.js +1 -1
- package/lib/linter/index.js +13 -0
- package/lib/{util → linter}/interpolate.js +0 -0
- package/lib/{linter.js → linter/linter.js} +298 -152
- package/lib/{util → linter}/node-event-generator.js +7 -5
- package/lib/{util → linter}/report-translator.js +0 -0
- package/lib/{util → linter}/rule-fixer.js +0 -0
- package/lib/{rules.js → linter/rules.js} +3 -29
- package/lib/{util → linter}/safe-emitter.js +0 -0
- package/lib/{util → linter}/source-code-fixer.js +0 -0
- package/lib/{util → linter}/timing.js +1 -1
- package/lib/rule-tester/index.js +5 -0
- package/lib/{testers → rule-tester}/rule-tester.js +43 -15
- package/lib/rules/array-bracket-newline.js +1 -1
- package/lib/rules/array-bracket-spacing.js +1 -1
- package/lib/rules/array-callback-return.js +1 -1
- package/lib/rules/array-element-newline.js +1 -1
- package/lib/rules/arrow-body-style.js +1 -1
- package/lib/rules/arrow-parens.js +22 -1
- package/lib/rules/arrow-spacing.js +1 -1
- package/lib/rules/block-spacing.js +1 -1
- package/lib/rules/brace-style.js +1 -1
- package/lib/rules/capitalized-comments.js +2 -2
- package/lib/rules/comma-dangle.js +1 -1
- package/lib/rules/comma-spacing.js +1 -1
- package/lib/rules/comma-style.js +1 -1
- package/lib/rules/complexity.js +3 -3
- package/lib/rules/computed-property-spacing.js +1 -1
- package/lib/rules/consistent-return.js +1 -1
- package/lib/rules/curly.js +1 -1
- package/lib/rules/dot-location.js +1 -1
- package/lib/rules/dot-notation.js +2 -2
- package/lib/rules/eqeqeq.js +1 -1
- package/lib/rules/func-call-spacing.js +1 -1
- package/lib/rules/func-name-matching.js +1 -1
- package/lib/rules/func-names.js +1 -1
- package/lib/rules/function-paren-newline.js +1 -1
- package/lib/rules/getter-return.js +1 -1
- package/lib/rules/implicit-arrow-linebreak.js +1 -1
- package/lib/rules/indent-legacy.js +1 -1
- package/lib/rules/indent.js +1 -1
- package/lib/rules/index.js +281 -0
- package/lib/rules/jsx-quotes.js +1 -1
- package/lib/rules/key-spacing.js +1 -1
- package/lib/rules/keyword-spacing.js +2 -2
- package/lib/rules/line-comment-position.js +1 -1
- package/lib/rules/linebreak-style.js +1 -1
- package/lib/rules/lines-around-comment.js +1 -1
- package/lib/rules/lines-around-directive.js +1 -1
- package/lib/rules/lines-between-class-members.js +1 -1
- package/lib/rules/max-classes-per-file.js +2 -1
- package/lib/rules/max-depth.js +2 -2
- package/lib/rules/max-len.js +11 -4
- package/lib/rules/max-lines-per-function.js +4 -2
- package/lib/rules/max-lines.js +2 -2
- package/lib/rules/max-params.js +1 -1
- package/lib/rules/max-statements-per-line.js +1 -1
- package/lib/rules/max-statements.js +1 -1
- package/lib/rules/multiline-comment-style.js +3 -2
- package/lib/rules/multiline-ternary.js +1 -1
- package/lib/rules/new-parens.js +43 -11
- package/lib/rules/newline-after-var.js +1 -1
- package/lib/rules/newline-per-chained-call.js +1 -1
- package/lib/rules/no-alert.js +1 -1
- package/lib/rules/no-catch-shadow.js +1 -1
- package/lib/rules/no-class-assign.js +1 -1
- package/lib/rules/no-cond-assign.js +1 -1
- package/lib/rules/no-confusing-arrow.js +1 -1
- package/lib/rules/no-console.js +1 -1
- package/lib/rules/no-const-assign.js +1 -1
- package/lib/rules/no-div-regex.js +9 -1
- package/lib/rules/no-dupe-keys.js +1 -1
- package/lib/rules/no-else-return.js +129 -2
- package/lib/rules/no-empty-function.js +1 -1
- package/lib/rules/no-empty.js +1 -1
- package/lib/rules/no-eval.js +1 -1
- package/lib/rules/no-ex-assign.js +1 -1
- package/lib/rules/no-extend-native.js +1 -1
- package/lib/rules/no-extra-bind.js +1 -1
- package/lib/rules/no-extra-boolean-cast.js +1 -1
- package/lib/rules/no-extra-label.js +1 -1
- package/lib/rules/no-extra-parens.js +1 -1
- package/lib/rules/no-extra-semi.js +2 -2
- package/lib/rules/no-floating-decimal.js +1 -1
- package/lib/rules/no-func-assign.js +1 -1
- package/lib/rules/no-implicit-coercion.js +1 -1
- package/lib/rules/no-inline-comments.js +1 -1
- package/lib/rules/no-invalid-this.js +1 -1
- package/lib/rules/no-irregular-whitespace.js +1 -1
- package/lib/rules/no-label-var.js +1 -1
- package/lib/rules/no-labels.js +1 -1
- package/lib/rules/no-misleading-character-class.js +1 -1
- package/lib/rules/no-mixed-operators.js +1 -1
- package/lib/rules/no-multi-spaces.js +1 -1
- package/lib/rules/no-multi-str.js +1 -1
- package/lib/rules/no-octal.js +1 -1
- package/lib/rules/no-redeclare.js +1 -1
- package/lib/rules/no-regex-spaces.js +1 -1
- package/lib/rules/no-restricted-imports.js +18 -14
- package/lib/rules/no-restricted-properties.js +1 -1
- package/lib/rules/no-return-assign.js +1 -1
- package/lib/rules/no-return-await.js +1 -1
- package/lib/rules/no-self-assign.js +1 -1
- package/lib/rules/no-sequences.js +1 -1
- package/lib/rules/no-shadow.js +1 -1
- package/lib/rules/no-this-before-super.js +1 -1
- package/lib/rules/no-throw-literal.js +1 -1
- package/lib/rules/no-trailing-spaces.js +1 -1
- package/lib/rules/no-undef-init.js +1 -1
- package/lib/rules/no-unexpected-multiline.js +1 -1
- package/lib/rules/no-unmodified-loop-condition.js +2 -2
- package/lib/rules/no-unneeded-ternary.js +1 -1
- package/lib/rules/no-unsafe-negation.js +1 -1
- package/lib/rules/no-unused-vars.js +1 -1
- package/lib/rules/no-useless-call.js +1 -1
- package/lib/rules/no-useless-computed-key.js +1 -1
- package/lib/rules/no-useless-concat.js +1 -1
- package/lib/rules/no-useless-escape.js +7 -2
- package/lib/rules/no-useless-return.js +2 -2
- package/lib/rules/no-var.js +15 -2
- package/lib/rules/no-warning-comments.js +1 -1
- package/lib/rules/no-whitespace-before-property.js +1 -1
- package/lib/rules/object-curly-newline.js +1 -1
- package/lib/rules/object-curly-spacing.js +1 -1
- package/lib/rules/object-shorthand.js +1 -1
- package/lib/rules/operator-assignment.js +1 -1
- package/lib/rules/operator-linebreak.js +1 -1
- package/lib/rules/padded-blocks.js +1 -1
- package/lib/rules/padding-line-between-statements.js +1 -1
- package/lib/rules/prefer-const.js +1 -1
- package/lib/rules/prefer-object-spread.js +1 -1
- package/lib/rules/prefer-promise-reject-errors.js +1 -1
- package/lib/rules/prefer-spread.js +1 -1
- package/lib/rules/prefer-template.js +1 -1
- package/lib/rules/quote-props.js +1 -1
- package/lib/rules/quotes.js +1 -1
- package/lib/rules/radix.js +1 -1
- package/lib/rules/require-atomic-updates.js +63 -84
- package/lib/rules/require-await.js +1 -1
- package/lib/rules/semi-spacing.js +1 -1
- package/lib/rules/semi-style.js +1 -1
- package/lib/rules/semi.js +2 -2
- package/lib/rules/sort-keys.js +12 -4
- package/lib/rules/space-before-blocks.js +1 -1
- package/lib/rules/space-before-function-paren.js +1 -1
- package/lib/rules/space-in-parens.js +1 -1
- package/lib/rules/space-unary-ops.js +1 -1
- package/lib/rules/spaced-comment.js +1 -1
- package/lib/rules/strict.js +1 -1
- package/lib/rules/switch-colon-spacing.js +1 -1
- package/lib/rules/symbol-description.js +1 -1
- package/lib/rules/template-curly-spacing.js +1 -1
- package/lib/{util → rules/utils}/ast-utils.js +8 -27
- package/lib/{util → rules/utils}/fix-tracker.js +1 -1
- package/lib/{util → rules/utils}/keywords.js +0 -0
- package/lib/{util → rules/utils}/lazy-loading-rule-map.js +0 -0
- package/lib/{util → rules/utils}/patterns/letters.js +0 -0
- package/lib/{util → rules/utils}/unicode/index.js +0 -0
- package/lib/{util → rules/utils}/unicode/is-combining-character.js +0 -0
- package/lib/{util → rules/utils}/unicode/is-emoji-modifier.js +0 -0
- package/lib/{util → rules/utils}/unicode/is-regional-indicator-symbol.js +0 -0
- package/lib/{util → rules/utils}/unicode/is-surrogate-pair.js +0 -0
- package/lib/rules/valid-typeof.js +1 -1
- package/lib/rules/wrap-iife.js +1 -1
- package/lib/rules/yoda.js +1 -1
- package/lib/{util → shared}/ajv.js +0 -0
- package/lib/shared/ast-utils.js +29 -0
- package/lib/{config → shared}/config-ops.js +0 -0
- package/lib/{config → shared}/config-validator.js +22 -7
- package/lib/{util → shared}/logging.js +0 -0
- package/lib/{util → shared}/relative-module-resolver.js +10 -3
- package/lib/{util → shared}/traverser.js +0 -0
- package/lib/{util → shared}/types.js +4 -0
- package/lib/source-code/index.js +5 -0
- package/lib/{util → source-code}/source-code.js +10 -8
- package/lib/{token-store → source-code/token-store}/backward-token-comment-cursor.js +0 -0
- package/lib/{token-store → source-code/token-store}/backward-token-cursor.js +0 -0
- package/lib/{token-store → source-code/token-store}/cursor.js +0 -0
- package/lib/{token-store → source-code/token-store}/cursors.js +0 -0
- package/lib/{token-store → source-code/token-store}/decorative-cursor.js +0 -0
- package/lib/{token-store → source-code/token-store}/filter-cursor.js +0 -0
- package/lib/{token-store → source-code/token-store}/forward-token-comment-cursor.js +0 -0
- package/lib/{token-store → source-code/token-store}/forward-token-cursor.js +0 -0
- package/lib/{token-store → source-code/token-store}/index.js +3 -3
- package/lib/{token-store → source-code/token-store}/limit-cursor.js +0 -0
- package/lib/{token-store → source-code/token-store}/padded-token-cursor.js +0 -0
- package/lib/{token-store → source-code/token-store}/skip-cursor.js +0 -0
- package/lib/{token-store → source-code/token-store}/utils.js +0 -0
- package/messages/extend-config-missing.txt +2 -0
- package/messages/print-config-with-directory-path.txt +2 -0
- package/package.json +8 -11
- package/lib/built-in-rules-index.js +0 -281
@@ -10,7 +10,7 @@
|
|
10
10
|
// Requirements
|
11
11
|
//------------------------------------------------------------------------------
|
12
12
|
|
13
|
-
const astUtils = require("
|
13
|
+
const astUtils = require("./utils/ast-utils");
|
14
14
|
|
15
15
|
//------------------------------------------------------------------------------
|
16
16
|
// Rule Definition
|
package/lib/rules/no-alert.js
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const getPropertyName = require("
|
11
|
+
const getPropertyName = require("./utils/ast-utils").getStaticPropertyName;
|
12
12
|
|
13
13
|
//------------------------------------------------------------------------------
|
14
14
|
// Helpers
|
@@ -10,7 +10,7 @@
|
|
10
10
|
// Requirements
|
11
11
|
//------------------------------------------------------------------------------
|
12
12
|
|
13
|
-
const astUtils = require("
|
13
|
+
const astUtils = require("./utils/ast-utils");
|
14
14
|
|
15
15
|
//------------------------------------------------------------------------------
|
16
16
|
// Rule Definition
|
package/lib/rules/no-console.js
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("
|
12
|
+
const astUtils = require("./utils/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Rule Definition
|
@@ -20,6 +20,8 @@ module.exports = {
|
|
20
20
|
url: "https://eslint.org/docs/rules/no-div-regex"
|
21
21
|
},
|
22
22
|
|
23
|
+
fixable: "code",
|
24
|
+
|
23
25
|
schema: [],
|
24
26
|
|
25
27
|
messages: {
|
@@ -36,7 +38,13 @@ module.exports = {
|
|
36
38
|
const token = sourceCode.getFirstToken(node);
|
37
39
|
|
38
40
|
if (token.type === "RegularExpression" && token.value[1] === "=") {
|
39
|
-
context.report({
|
41
|
+
context.report({
|
42
|
+
node,
|
43
|
+
messageId: "unexpected",
|
44
|
+
fix(fixer) {
|
45
|
+
return fixer.replaceTextRange([token.range[0] + 1, token.range[0] + 2], "[=]");
|
46
|
+
}
|
47
|
+
});
|
40
48
|
}
|
41
49
|
}
|
42
50
|
};
|
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("
|
12
|
+
const astUtils = require("./utils/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Helpers
|
@@ -9,8 +9,8 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("
|
13
|
-
const FixTracker = require("
|
12
|
+
const astUtils = require("./utils/ast-utils");
|
13
|
+
const FixTracker = require("./utils/fix-tracker");
|
14
14
|
|
15
15
|
//------------------------------------------------------------------------------
|
16
16
|
// Rule Definition
|
@@ -51,6 +51,124 @@ module.exports = {
|
|
51
51
|
// Helpers
|
52
52
|
//--------------------------------------------------------------------------
|
53
53
|
|
54
|
+
/**
|
55
|
+
* Checks whether the given names can be safely used to declare block-scoped variables
|
56
|
+
* in the given scope. Name collisions can produce redeclaration syntax errors,
|
57
|
+
* or silently change references and modify behavior of the original code.
|
58
|
+
*
|
59
|
+
* This is not a generic function. In particular, it is assumed that the scope is a function scope or
|
60
|
+
* a function's inner scope, and that the names can be valid identifiers in the given scope.
|
61
|
+
*
|
62
|
+
* @param {string[]} names Array of variable names.
|
63
|
+
* @param {eslint-scope.Scope} scope Function scope or a function's inner scope.
|
64
|
+
* @returns {boolean} True if all names can be safely declared, false otherwise.
|
65
|
+
*/
|
66
|
+
function isSafeToDeclare(names, scope) {
|
67
|
+
|
68
|
+
if (names.length === 0) {
|
69
|
+
return true;
|
70
|
+
}
|
71
|
+
|
72
|
+
const functionScope = scope.variableScope;
|
73
|
+
|
74
|
+
/*
|
75
|
+
* If this is a function scope, scope.variables will contain parameters, implicit variables such as "arguments",
|
76
|
+
* all function-scoped variables ('var'), and block-scoped variables defined in the scope.
|
77
|
+
* If this is an inner scope, scope.variables will contain block-scoped variables defined in the scope.
|
78
|
+
*
|
79
|
+
* Redeclaring any of these would cause a syntax error, except for the implicit variables.
|
80
|
+
*/
|
81
|
+
const declaredVariables = scope.variables.filter(({ defs }) => defs.length > 0);
|
82
|
+
|
83
|
+
if (declaredVariables.some(({ name }) => names.includes(name))) {
|
84
|
+
return false;
|
85
|
+
}
|
86
|
+
|
87
|
+
// Redeclaring a catch variable would also cause a syntax error.
|
88
|
+
if (scope !== functionScope && scope.upper.type === "catch") {
|
89
|
+
if (scope.upper.variables.some(({ name }) => names.includes(name))) {
|
90
|
+
return false;
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
/*
|
95
|
+
* Redeclaring an implicit variable, such as "arguments", would not cause a syntax error.
|
96
|
+
* However, if the variable was used, declaring a new one with the same name would change references
|
97
|
+
* and modify behavior.
|
98
|
+
*/
|
99
|
+
const usedImplicitVariables = scope.variables.filter(({ defs, references }) =>
|
100
|
+
defs.length === 0 && references.length > 0);
|
101
|
+
|
102
|
+
if (usedImplicitVariables.some(({ name }) => names.includes(name))) {
|
103
|
+
return false;
|
104
|
+
}
|
105
|
+
|
106
|
+
/*
|
107
|
+
* Declaring a variable with a name that was already used to reference a variable from an upper scope
|
108
|
+
* would change references and modify behavior.
|
109
|
+
*/
|
110
|
+
if (scope.through.some(t => names.includes(t.identifier.name))) {
|
111
|
+
return false;
|
112
|
+
}
|
113
|
+
|
114
|
+
/*
|
115
|
+
* If the scope is an inner scope (not the function scope), an uninitialized `var` variable declared inside
|
116
|
+
* the scope node (directly or in one of its descendants) is neither declared nor 'through' in the scope.
|
117
|
+
*
|
118
|
+
* For example, this would be a syntax error "Identifier 'a' has already been declared":
|
119
|
+
* function foo() { if (bar) { let a; if (baz) { var a; } } }
|
120
|
+
*/
|
121
|
+
if (scope !== functionScope) {
|
122
|
+
const scopeNodeRange = scope.block.range;
|
123
|
+
const variablesToCheck = functionScope.variables.filter(({ name }) => names.includes(name));
|
124
|
+
|
125
|
+
if (variablesToCheck.some(v => v.defs.some(({ node: { range } }) =>
|
126
|
+
scopeNodeRange[0] <= range[0] && range[1] <= scopeNodeRange[1]))) {
|
127
|
+
return false;
|
128
|
+
}
|
129
|
+
}
|
130
|
+
|
131
|
+
return true;
|
132
|
+
}
|
133
|
+
|
134
|
+
|
135
|
+
/**
|
136
|
+
* Checks whether the removal of `else` and its braces is safe from variable name collisions.
|
137
|
+
*
|
138
|
+
* @param {Node} node The 'else' node.
|
139
|
+
* @param {eslint-scope.Scope} scope The scope in which the node and the whole 'if' statement is.
|
140
|
+
* @returns {boolean} True if it is safe, false otherwise.
|
141
|
+
*/
|
142
|
+
function isSafeFromNameCollisions(node, scope) {
|
143
|
+
|
144
|
+
if (node.type === "FunctionDeclaration") {
|
145
|
+
|
146
|
+
// Conditional function declaration. Scope and hoisting are unpredictable, different engines work differently.
|
147
|
+
return false;
|
148
|
+
}
|
149
|
+
|
150
|
+
if (node.type !== "BlockStatement") {
|
151
|
+
return true;
|
152
|
+
}
|
153
|
+
|
154
|
+
const elseBlockScope = scope.childScopes.find(({ block }) => block === node);
|
155
|
+
|
156
|
+
if (!elseBlockScope) {
|
157
|
+
|
158
|
+
// ecmaVersion < 6, `else` block statement cannot have its own scope, no possible collisions.
|
159
|
+
return true;
|
160
|
+
}
|
161
|
+
|
162
|
+
/*
|
163
|
+
* elseBlockScope is supposed to merge into its upper scope. elseBlockScope.variables array contains
|
164
|
+
* only block-scoped variables (such as let and const variables or class and function declarations)
|
165
|
+
* defined directly in the elseBlockScope. These are exactly the only names that could cause collisions.
|
166
|
+
*/
|
167
|
+
const namesToCheck = elseBlockScope.variables.map(({ name }) => name);
|
168
|
+
|
169
|
+
return isSafeToDeclare(namesToCheck, scope);
|
170
|
+
}
|
171
|
+
|
54
172
|
/**
|
55
173
|
* Display the context report if rule is violated
|
56
174
|
*
|
@@ -58,10 +176,17 @@ module.exports = {
|
|
58
176
|
* @returns {void}
|
59
177
|
*/
|
60
178
|
function displayReport(node) {
|
179
|
+
const currentScope = context.getScope();
|
180
|
+
|
61
181
|
context.report({
|
62
182
|
node,
|
63
183
|
messageId: "unexpected",
|
64
184
|
fix: fixer => {
|
185
|
+
|
186
|
+
if (!isSafeFromNameCollisions(node, currentScope)) {
|
187
|
+
return null;
|
188
|
+
}
|
189
|
+
|
65
190
|
const sourceCode = context.getSourceCode();
|
66
191
|
const startToken = sourceCode.getFirstToken(node);
|
67
192
|
const elseToken = sourceCode.getTokenBefore(startToken);
|
@@ -118,6 +243,8 @@ module.exports = {
|
|
118
243
|
* Extend the replacement range to include the entire
|
119
244
|
* function to avoid conflicting with no-useless-return.
|
120
245
|
* https://github.com/eslint/eslint/issues/8026
|
246
|
+
*
|
247
|
+
* Also, to avoid name collisions between two else blocks.
|
121
248
|
*/
|
122
249
|
return new FixTracker(fixer, sourceCode)
|
123
250
|
.retainEnclosingFunction(node)
|
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("
|
12
|
+
const astUtils = require("./utils/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Helpers
|
package/lib/rules/no-empty.js
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const astUtils = require("
|
11
|
+
const astUtils = require("./utils/ast-utils");
|
12
12
|
|
13
13
|
//------------------------------------------------------------------------------
|
14
14
|
// Rule Definition
|
package/lib/rules/no-eval.js
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("
|
12
|
+
const astUtils = require("./utils/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Helpers
|
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("
|
12
|
+
const astUtils = require("./utils/ast-utils");
|
13
13
|
const globals = require("globals");
|
14
14
|
|
15
15
|
//------------------------------------------------------------------------------
|
@@ -8,7 +8,7 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const astUtils = require("
|
11
|
+
const astUtils = require("./utils/ast-utils");
|
12
12
|
|
13
13
|
//------------------------------------------------------------------------------
|
14
14
|
// Helpers
|
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("
|
12
|
+
const astUtils = require("./utils/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Rule Definition
|
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("
|
12
|
+
const astUtils = require("./utils/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Rule Definition
|
@@ -9,8 +9,8 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const FixTracker = require("
|
13
|
-
const astUtils = require("
|
12
|
+
const FixTracker = require("./utils/fix-tracker");
|
13
|
+
const astUtils = require("./utils/ast-utils");
|
14
14
|
|
15
15
|
//------------------------------------------------------------------------------
|
16
16
|
// Rule Definition
|
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("
|
12
|
+
const astUtils = require("./utils/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Rule Definition
|
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("
|
12
|
+
const astUtils = require("./utils/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Rule Definition
|
@@ -10,7 +10,7 @@
|
|
10
10
|
// Requirements
|
11
11
|
//------------------------------------------------------------------------------
|
12
12
|
|
13
|
-
const astUtils = require("
|
13
|
+
const astUtils = require("./utils/ast-utils");
|
14
14
|
|
15
15
|
//------------------------------------------------------------------------------
|
16
16
|
// Constants
|
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("
|
12
|
+
const astUtils = require("./utils/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Rule Definition
|
package/lib/rules/no-labels.js
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const astUtils = require("
|
11
|
+
const astUtils = require("./utils/ast-utils");
|
12
12
|
|
13
13
|
//------------------------------------------------------------------------------
|
14
14
|
// Rule Definition
|
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
const { CALL, CONSTRUCT, ReferenceTracker, getStringIfConstant } = require("eslint-utils");
|
7
7
|
const { RegExpParser, visitRegExpAST } = require("regexpp");
|
8
|
-
const { isCombiningCharacter, isEmojiModifier, isRegionalIndicatorSymbol, isSurrogatePair } = require("
|
8
|
+
const { isCombiningCharacter, isEmojiModifier, isRegionalIndicatorSymbol, isSurrogatePair } = require("./utils/unicode");
|
9
9
|
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
// Helpers
|
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("
|
12
|
+
const astUtils = require("./utils/ast-utils.js");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Helpers
|
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("
|
12
|
+
const astUtils = require("./utils/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Rule Definition
|
package/lib/rules/no-octal.js
CHANGED
@@ -28,7 +28,7 @@ module.exports = {
|
|
28
28
|
return {
|
29
29
|
|
30
30
|
Literal(node) {
|
31
|
-
if (typeof node.value === "number" && /^0[0-
|
31
|
+
if (typeof node.value === "number" && /^0[0-9]/u.test(node.raw)) {
|
32
32
|
context.report({ node, message: "Octal literals should not be used." });
|
33
33
|
}
|
34
34
|
}
|
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("
|
12
|
+
const astUtils = require("./utils/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Rule Definition
|
@@ -4,13 +4,6 @@
|
|
4
4
|
*/
|
5
5
|
"use strict";
|
6
6
|
|
7
|
-
//------------------------------------------------------------------------------
|
8
|
-
// Helpers
|
9
|
-
//------------------------------------------------------------------------------
|
10
|
-
|
11
|
-
const DEFAULT_MESSAGE_TEMPLATE = "'{{importSource}}' import is restricted from being used.";
|
12
|
-
const CUSTOM_MESSAGE_TEMPLATE = "'{{importSource}}' import is restricted from being used. {{customMessage}}";
|
13
|
-
|
14
7
|
//------------------------------------------------------------------------------
|
15
8
|
// Rule Definition
|
16
9
|
//------------------------------------------------------------------------------
|
@@ -62,6 +55,18 @@ module.exports = {
|
|
62
55
|
url: "https://eslint.org/docs/rules/no-restricted-imports"
|
63
56
|
},
|
64
57
|
|
58
|
+
messages: {
|
59
|
+
path: "'{{importSource}}' import is restricted from being used.",
|
60
|
+
// eslint-disable-next-line eslint-plugin/report-message-format
|
61
|
+
pathWithCustomMessage: "'{{importSource}}' import is restricted from being used. {{customMessage}}",
|
62
|
+
|
63
|
+
patterns: "'{{importSource}}' import is restricted from being used by a pattern.",
|
64
|
+
|
65
|
+
everything: "* import is invalid because '{{importNames}}' from '{{importSource}}' is restricted.",
|
66
|
+
// eslint-disable-next-line eslint-plugin/report-message-format
|
67
|
+
everythingWithCustomMessage: "* import is invalid because '{{importNames}}' from '{{importSource}}' is restricted. {{customMessage}}"
|
68
|
+
},
|
69
|
+
|
65
70
|
schema: {
|
66
71
|
anyOf: [
|
67
72
|
arrayOfStringsOrObjects,
|
@@ -127,13 +132,10 @@ module.exports = {
|
|
127
132
|
function reportPath(node) {
|
128
133
|
const importSource = node.source.value.trim();
|
129
134
|
const customMessage = restrictedPathMessages[importSource] && restrictedPathMessages[importSource].message;
|
130
|
-
const message = customMessage
|
131
|
-
? CUSTOM_MESSAGE_TEMPLATE
|
132
|
-
: DEFAULT_MESSAGE_TEMPLATE;
|
133
135
|
|
134
136
|
context.report({
|
135
137
|
node,
|
136
|
-
|
138
|
+
messageId: customMessage ? "pathWithCustomMessage" : "path",
|
137
139
|
data: {
|
138
140
|
importSource,
|
139
141
|
customMessage
|
@@ -152,7 +154,7 @@ module.exports = {
|
|
152
154
|
|
153
155
|
context.report({
|
154
156
|
node,
|
155
|
-
|
157
|
+
messageId: "patterns",
|
156
158
|
data: {
|
157
159
|
importSource
|
158
160
|
}
|
@@ -168,13 +170,15 @@ module.exports = {
|
|
168
170
|
*/
|
169
171
|
function reportPathForEverythingImported(importSource, node) {
|
170
172
|
const importNames = restrictedPathMessages[importSource].importNames;
|
173
|
+
const customMessage = restrictedPathMessages[importSource] && restrictedPathMessages[importSource].message;
|
171
174
|
|
172
175
|
context.report({
|
173
176
|
node,
|
174
|
-
|
177
|
+
messageId: customMessage ? "everythingWithCustomMessage" : "everything",
|
175
178
|
data: {
|
176
179
|
importSource,
|
177
|
-
importNames
|
180
|
+
importNames,
|
181
|
+
customMessage
|
178
182
|
}
|
179
183
|
});
|
180
184
|
}
|
@@ -8,7 +8,7 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const astUtils = require("
|
11
|
+
const astUtils = require("./utils/ast-utils");
|
12
12
|
|
13
13
|
//------------------------------------------------------------------------------
|
14
14
|
// Helpers
|