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
@@ -24,12 +24,51 @@ function createReferenceMap(scope, outReferenceMap = new Map()) {
|
|
24
24
|
return outReferenceMap;
|
25
25
|
}
|
26
26
|
|
27
|
+
/**
|
28
|
+
* Get `reference.writeExpr` of a given reference.
|
29
|
+
* If it's the read reference of MemberExpression in LHS, returns RHS in order to address `a.b = await a`
|
30
|
+
* @param {escope.Reference} reference The reference to get.
|
31
|
+
* @returns {Expression|null} The `reference.writeExpr`.
|
32
|
+
*/
|
33
|
+
function getWriteExpr(reference) {
|
34
|
+
if (reference.writeExpr) {
|
35
|
+
return reference.writeExpr;
|
36
|
+
}
|
37
|
+
let node = reference.identifier;
|
38
|
+
|
39
|
+
while (node) {
|
40
|
+
const t = node.parent.type;
|
41
|
+
|
42
|
+
if (t === "AssignmentExpression" && node.parent.left === node) {
|
43
|
+
return node.parent.right;
|
44
|
+
}
|
45
|
+
if (t === "MemberExpression" && node.parent.object === node) {
|
46
|
+
node = node.parent;
|
47
|
+
continue;
|
48
|
+
}
|
49
|
+
|
50
|
+
break;
|
51
|
+
}
|
52
|
+
|
53
|
+
return null;
|
54
|
+
}
|
55
|
+
|
27
56
|
/**
|
28
57
|
* Checks if an expression is a variable that can only be observed within the given function.
|
29
|
-
* @param {
|
58
|
+
* @param {Variable|null} variable The variable to check
|
59
|
+
* @param {boolean} isMemberAccess If `true` then this is a member access.
|
30
60
|
* @returns {boolean} `true` if the variable is local to the given function, and is never referenced in a closure.
|
31
61
|
*/
|
32
|
-
function isLocalVariableWithoutEscape(variable) {
|
62
|
+
function isLocalVariableWithoutEscape(variable, isMemberAccess) {
|
63
|
+
if (!variable) {
|
64
|
+
return false; // A global variable which was not defined.
|
65
|
+
}
|
66
|
+
|
67
|
+
// If the reference is a property access and the variable is a parameter, it handles the variable is not local.
|
68
|
+
if (isMemberAccess && variable.defs.some(d => d.type === "Parameter")) {
|
69
|
+
return false;
|
70
|
+
}
|
71
|
+
|
33
72
|
const functionScope = variable.scope.variableScope;
|
34
73
|
|
35
74
|
return variable.references.every(reference =>
|
@@ -47,52 +86,49 @@ class SegmentInfo {
|
|
47
86
|
* @returns {void}
|
48
87
|
*/
|
49
88
|
initialize(segment) {
|
50
|
-
const
|
51
|
-
const
|
89
|
+
const outdatedReadVariableNames = new Set();
|
90
|
+
const freshReadVariableNames = new Set();
|
52
91
|
|
53
92
|
for (const prevSegment of segment.prevSegments) {
|
54
93
|
const info = this.info.get(prevSegment);
|
55
94
|
|
56
95
|
if (info) {
|
57
|
-
info.
|
58
|
-
info.
|
96
|
+
info.outdatedReadVariableNames.forEach(Set.prototype.add, outdatedReadVariableNames);
|
97
|
+
info.freshReadVariableNames.forEach(Set.prototype.add, freshReadVariableNames);
|
59
98
|
}
|
60
99
|
}
|
61
100
|
|
62
|
-
this.info.set(segment, {
|
101
|
+
this.info.set(segment, { outdatedReadVariableNames, freshReadVariableNames });
|
63
102
|
}
|
64
103
|
|
65
104
|
/**
|
66
105
|
* Mark a given variable as read on given segments.
|
67
106
|
* @param {PathSegment[]} segments The segments that it read the variable on.
|
68
|
-
* @param {
|
107
|
+
* @param {string} variableName The variable name to be read.
|
69
108
|
* @returns {void}
|
70
109
|
*/
|
71
|
-
markAsRead(segments,
|
110
|
+
markAsRead(segments, variableName) {
|
72
111
|
for (const segment of segments) {
|
73
112
|
const info = this.info.get(segment);
|
74
113
|
|
75
114
|
if (info) {
|
76
|
-
info.
|
115
|
+
info.freshReadVariableNames.add(variableName);
|
77
116
|
}
|
78
117
|
}
|
79
118
|
}
|
80
119
|
|
81
120
|
/**
|
82
|
-
* Move `
|
121
|
+
* Move `freshReadVariableNames` to `outdatedReadVariableNames`.
|
83
122
|
* @param {PathSegment[]} segments The segments to process.
|
84
123
|
* @returns {void}
|
85
124
|
*/
|
86
125
|
makeOutdated(segments) {
|
87
|
-
const vars = new Set();
|
88
|
-
|
89
126
|
for (const segment of segments) {
|
90
127
|
const info = this.info.get(segment);
|
91
128
|
|
92
129
|
if (info) {
|
93
|
-
info.
|
94
|
-
info.
|
95
|
-
info.freshReadVariables.clear();
|
130
|
+
info.freshReadVariableNames.forEach(Set.prototype.add, info.outdatedReadVariableNames);
|
131
|
+
info.freshReadVariableNames.clear();
|
96
132
|
}
|
97
133
|
}
|
98
134
|
}
|
@@ -100,14 +136,14 @@ class SegmentInfo {
|
|
100
136
|
/**
|
101
137
|
* Check if a given variable is outdated on the current segments.
|
102
138
|
* @param {PathSegment[]} segments The current segments.
|
103
|
-
* @param {
|
139
|
+
* @param {string} variableName The variable name to check.
|
104
140
|
* @returns {boolean} `true` if the variable is outdated on the segments.
|
105
141
|
*/
|
106
|
-
isOutdated(segments,
|
142
|
+
isOutdated(segments, variableName) {
|
107
143
|
for (const segment of segments) {
|
108
144
|
const info = this.info.get(segment);
|
109
145
|
|
110
|
-
if (info && info.
|
146
|
+
if (info && info.outdatedReadVariableNames.has(variableName)) {
|
111
147
|
return true;
|
112
148
|
}
|
113
149
|
}
|
@@ -140,69 +176,10 @@ module.exports = {
|
|
140
176
|
|
141
177
|
create(context) {
|
142
178
|
const sourceCode = context.getSourceCode();
|
143
|
-
const globalScope = context.getScope();
|
144
|
-
const dummyVariables = new Map();
|
145
179
|
const assignmentReferences = new Map();
|
146
180
|
const segmentInfo = new SegmentInfo();
|
147
181
|
let stack = null;
|
148
182
|
|
149
|
-
/**
|
150
|
-
* Get the variable of a given reference.
|
151
|
-
* If it's not defined, returns a dummy object.
|
152
|
-
* @param {escope.Reference} reference The reference to get.
|
153
|
-
* @returns {escope.Variable} The variable of the reference.
|
154
|
-
*/
|
155
|
-
function getVariable(reference) {
|
156
|
-
if (reference.resolved) {
|
157
|
-
return reference.resolved;
|
158
|
-
}
|
159
|
-
|
160
|
-
// Get or create a dummy.
|
161
|
-
const name = reference.identifier.name;
|
162
|
-
let variable = dummyVariables.get(name);
|
163
|
-
|
164
|
-
if (!variable) {
|
165
|
-
variable = {
|
166
|
-
name,
|
167
|
-
scope: globalScope,
|
168
|
-
references: []
|
169
|
-
};
|
170
|
-
dummyVariables.set(name, variable);
|
171
|
-
}
|
172
|
-
variable.references.push(reference);
|
173
|
-
|
174
|
-
return variable;
|
175
|
-
}
|
176
|
-
|
177
|
-
/**
|
178
|
-
* Get `reference.writeExpr` of a given reference.
|
179
|
-
* If it's the read reference of MemberExpression in LHS, returns RHS in order to address `a.b = await a`
|
180
|
-
* @param {escope.Reference} reference The reference to get.
|
181
|
-
* @returns {Expression|null} The `reference.writeExpr`.
|
182
|
-
*/
|
183
|
-
function getWriteExpr(reference) {
|
184
|
-
if (reference.writeExpr) {
|
185
|
-
return reference.writeExpr;
|
186
|
-
}
|
187
|
-
let node = reference.identifier;
|
188
|
-
|
189
|
-
while (node) {
|
190
|
-
const t = node.parent.type;
|
191
|
-
|
192
|
-
if (t === "AssignmentExpression" && node.parent.left === node) {
|
193
|
-
return node.parent.right;
|
194
|
-
}
|
195
|
-
if (t === "MemberExpression" && node.parent.object === node) {
|
196
|
-
node = node.parent;
|
197
|
-
continue;
|
198
|
-
}
|
199
|
-
|
200
|
-
break;
|
201
|
-
}
|
202
|
-
|
203
|
-
return null;
|
204
|
-
}
|
205
|
-
|
206
183
|
return {
|
207
184
|
onCodePathStart(codePath) {
|
208
185
|
const scope = context.getScope();
|
@@ -234,12 +211,14 @@ module.exports = {
|
|
234
211
|
if (!reference) {
|
235
212
|
return;
|
236
213
|
}
|
237
|
-
const
|
214
|
+
const name = reference.identifier.name;
|
215
|
+
const variable = reference.resolved;
|
238
216
|
const writeExpr = getWriteExpr(reference);
|
217
|
+
const isMemberAccess = reference.identifier.parent.type === "MemberExpression";
|
239
218
|
|
240
219
|
// Add a fresh read variable.
|
241
220
|
if (reference.isRead() && !(writeExpr && writeExpr.parent.operator === "=")) {
|
242
|
-
segmentInfo.markAsRead(codePath.currentSegments,
|
221
|
+
segmentInfo.markAsRead(codePath.currentSegments, name);
|
243
222
|
}
|
244
223
|
|
245
224
|
/*
|
@@ -248,7 +227,7 @@ module.exports = {
|
|
248
227
|
*/
|
249
228
|
if (writeExpr &&
|
250
229
|
writeExpr.parent.right === writeExpr && // ← exclude variable declarations.
|
251
|
-
!isLocalVariableWithoutEscape(variable)
|
230
|
+
!isLocalVariableWithoutEscape(variable, isMemberAccess)
|
252
231
|
) {
|
253
232
|
let refs = assignmentReferences.get(writeExpr);
|
254
233
|
|
@@ -263,7 +242,7 @@ module.exports = {
|
|
263
242
|
|
264
243
|
/*
|
265
244
|
* Verify assignments.
|
266
|
-
* If the reference exists in `
|
245
|
+
* If the reference exists in `outdatedReadVariableNames` list, report it.
|
267
246
|
*/
|
268
247
|
":expression:exit"(node) {
|
269
248
|
const { codePath, referenceMap } = stack;
|
@@ -285,9 +264,9 @@ module.exports = {
|
|
285
264
|
assignmentReferences.delete(node);
|
286
265
|
|
287
266
|
for (const reference of references) {
|
288
|
-
const
|
267
|
+
const name = reference.identifier.name;
|
289
268
|
|
290
|
-
if (segmentInfo.isOutdated(codePath.currentSegments,
|
269
|
+
if (segmentInfo.isOutdated(codePath.currentSegments, name)) {
|
291
270
|
context.report({
|
292
271
|
node: node.parent,
|
293
272
|
messageId: "nonAtomicUpdate",
|
@@ -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/semi-style.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
|
package/lib/rules/semi.js
CHANGED
@@ -8,8 +8,8 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const FixTracker = require("
|
12
|
-
const astUtils = require("
|
11
|
+
const FixTracker = require("./utils/fix-tracker");
|
12
|
+
const astUtils = require("./utils/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Rule Definition
|
package/lib/rules/sort-keys.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
|
naturalCompare = require("natural-compare");
|
14
14
|
|
15
15
|
//------------------------------------------------------------------------------
|
@@ -96,6 +96,11 @@ module.exports = {
|
|
96
96
|
natural: {
|
97
97
|
type: "boolean",
|
98
98
|
default: false
|
99
|
+
},
|
100
|
+
minKeys: {
|
101
|
+
type: "integer",
|
102
|
+
minimum: 2,
|
103
|
+
default: 2
|
99
104
|
}
|
100
105
|
},
|
101
106
|
additionalProperties: false
|
@@ -110,6 +115,7 @@ module.exports = {
|
|
110
115
|
const options = context.options[1];
|
111
116
|
const insensitive = options && options.caseSensitive === false;
|
112
117
|
const natual = options && options.natural;
|
118
|
+
const minKeys = options && options.minKeys;
|
113
119
|
const isValidOrder = isValidOrders[
|
114
120
|
order + (insensitive ? "I" : "") + (natual ? "N" : "")
|
115
121
|
];
|
@@ -118,10 +124,11 @@ module.exports = {
|
|
118
124
|
let stack = null;
|
119
125
|
|
120
126
|
return {
|
121
|
-
ObjectExpression() {
|
127
|
+
ObjectExpression(node) {
|
122
128
|
stack = {
|
123
129
|
upper: stack,
|
124
|
-
prevName: null
|
130
|
+
prevName: null,
|
131
|
+
numKeys: node.properties.length
|
125
132
|
};
|
126
133
|
},
|
127
134
|
|
@@ -141,11 +148,12 @@ module.exports = {
|
|
141
148
|
}
|
142
149
|
|
143
150
|
const prevName = stack.prevName;
|
151
|
+
const numKeys = stack.numKeys;
|
144
152
|
const thisName = getPropertyName(node);
|
145
153
|
|
146
154
|
stack.prevName = thisName || prevName;
|
147
155
|
|
148
|
-
if (!prevName || !thisName) {
|
156
|
+
if (!prevName || !thisName || numKeys < minKeys) {
|
149
157
|
return;
|
150
158
|
}
|
151
159
|
|
@@ -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
|
@@ -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/strict.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
|
|
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,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
|
@@ -12,6 +12,12 @@
|
|
12
12
|
const esutils = require("esutils");
|
13
13
|
const espree = require("espree");
|
14
14
|
const lodash = require("lodash");
|
15
|
+
const {
|
16
|
+
breakableTypePattern,
|
17
|
+
createGlobalLinebreakMatcher,
|
18
|
+
lineBreakPattern,
|
19
|
+
shebangPattern
|
20
|
+
} = require("../../shared/ast-utils");
|
15
21
|
|
16
22
|
//------------------------------------------------------------------------------
|
17
23
|
// Helpers
|
@@ -22,14 +28,11 @@ const anyLoopPattern = /^(?:DoWhile|For|ForIn|ForOf|While)Statement$/u;
|
|
22
28
|
const arrayOrTypedArrayPattern = /Array$/u;
|
23
29
|
const arrayMethodPattern = /^(?:every|filter|find|findIndex|forEach|map|some)$/u;
|
24
30
|
const bindOrCallOrApplyPattern = /^(?:bind|call|apply)$/u;
|
25
|
-
const breakableTypePattern = /^(?:(?:Do)?While|For(?:In|Of)?|Switch)Statement$/u;
|
26
31
|
const thisTagPattern = /^[\s*]*@this/mu;
|
27
32
|
|
28
33
|
|
29
34
|
const COMMENTS_IGNORE_PATTERN = /^\s*(?:eslint|jshint\s+|jslint\s+|istanbul\s+|globals?\s+|exported\s+|jscs)/u;
|
30
35
|
const LINEBREAKS = new Set(["\r\n", "\r", "\n", "\u2028", "\u2029"]);
|
31
|
-
const LINEBREAK_MATCHER = /\r\n|[\r\n\u2028\u2029]/u;
|
32
|
-
const SHEBANG_MATCHER = /^#!([^\r\n]+)/u;
|
33
36
|
|
34
37
|
// A set of node types that can contain a list of statements
|
35
38
|
const STATEMENT_LIST_PARENTS = new Set(["Program", "BlockStatement", "SwitchCase"]);
|
@@ -393,15 +396,6 @@ function getOpeningParenOfParams(node, sourceCode) {
|
|
393
396
|
: sourceCode.getFirstToken(node, isOpeningParenToken);
|
394
397
|
}
|
395
398
|
|
396
|
-
/**
|
397
|
-
* Creates a version of the LINEBREAK_MATCHER regex with the global flag.
|
398
|
-
* Global regexes are mutable, so this needs to be a function instead of a constant.
|
399
|
-
* @returns {RegExp} A global regular expression that matches line terminators
|
400
|
-
*/
|
401
|
-
function createGlobalLinebreakMatcher() {
|
402
|
-
return new RegExp(LINEBREAK_MATCHER.source, "gu");
|
403
|
-
}
|
404
|
-
|
405
399
|
/**
|
406
400
|
* Checks whether or not the tokens of two given nodes are same.
|
407
401
|
* @param {ASTNode} left - A node 1 to compare.
|
@@ -434,8 +428,8 @@ function equalTokens(left, right, sourceCode) {
|
|
434
428
|
module.exports = {
|
435
429
|
COMMENTS_IGNORE_PATTERN,
|
436
430
|
LINEBREAKS,
|
437
|
-
LINEBREAK_MATCHER,
|
438
|
-
SHEBANG_MATCHER,
|
431
|
+
LINEBREAK_MATCHER: lineBreakPattern,
|
432
|
+
SHEBANG_MATCHER: shebangPattern,
|
439
433
|
STATEMENT_LIST_PARENTS,
|
440
434
|
|
441
435
|
/**
|
@@ -513,19 +507,6 @@ module.exports = {
|
|
513
507
|
return breakableTypePattern.test(node.type);
|
514
508
|
},
|
515
509
|
|
516
|
-
/**
|
517
|
-
* Gets the label if the parent node of a given node is a LabeledStatement.
|
518
|
-
*
|
519
|
-
* @param {ASTNode} node - A node to get.
|
520
|
-
* @returns {string|null} The label or `null`.
|
521
|
-
*/
|
522
|
-
getLabel(node) {
|
523
|
-
if (node.parent.type === "LabeledStatement") {
|
524
|
-
return node.parent.label.name;
|
525
|
-
}
|
526
|
-
return null;
|
527
|
-
},
|
528
|
-
|
529
510
|
/**
|
530
511
|
* Gets references which are non initializer and writable.
|
531
512
|
* @param {Reference[]} references - An array of references.
|
@@ -8,7 +8,7 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const astUtils = require("
|
11
|
+
const astUtils = require("./ast-utils");
|
12
12
|
|
13
13
|
//------------------------------------------------------------------------------
|
14
14
|
// Public Interface
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -39,7 +39,7 @@ module.exports = {
|
|
39
39
|
|
40
40
|
create(context) {
|
41
41
|
|
42
|
-
const VALID_TYPES = ["symbol", "undefined", "object", "boolean", "number", "string", "function"],
|
42
|
+
const VALID_TYPES = ["symbol", "undefined", "object", "boolean", "number", "string", "function", "bigint"],
|
43
43
|
OPERATORS = ["==", "===", "!=", "!=="];
|
44
44
|
|
45
45
|
const requireStringLiterals = context.options[0] && context.options[0].requireStringLiterals;
|
package/lib/rules/wrap-iife.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
|
package/lib/rules/yoda.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
|
// Helpers
|
File without changes
|
@@ -0,0 +1,29 @@
|
|
1
|
+
/**
|
2
|
+
* @fileoverview Common utils for AST.
|
3
|
+
*
|
4
|
+
* This file contains only shared items for core and rules.
|
5
|
+
* If you make a utility for rules, please see `../rules/utils/ast-utils.js`.
|
6
|
+
*
|
7
|
+
* @author Toru Nagashima <https://github.com/mysticatea>
|
8
|
+
*/
|
9
|
+
"use strict";
|
10
|
+
|
11
|
+
const breakableTypePattern = /^(?:(?:Do)?While|For(?:In|Of)?|Switch)Statement$/u;
|
12
|
+
const lineBreakPattern = /\r\n|[\r\n\u2028\u2029]/u;
|
13
|
+
const shebangPattern = /^#!([^\r\n]+)/u;
|
14
|
+
|
15
|
+
/**
|
16
|
+
* Creates a version of the `lineBreakPattern` regex with the global flag.
|
17
|
+
* Global regexes are mutable, so this needs to be a function instead of a constant.
|
18
|
+
* @returns {RegExp} A global regular expression that matches line terminators
|
19
|
+
*/
|
20
|
+
function createGlobalLinebreakMatcher() {
|
21
|
+
return new RegExp(lineBreakPattern.source, "gu");
|
22
|
+
}
|
23
|
+
|
24
|
+
module.exports = {
|
25
|
+
breakableTypePattern,
|
26
|
+
lineBreakPattern,
|
27
|
+
createGlobalLinebreakMatcher,
|
28
|
+
shebangPattern
|
29
|
+
};
|
File without changes
|