eslint 5.2.0 → 5.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/conf/eslint-recommended.js +4 -0
  3. package/lib/cli-engine.js +12 -12
  4. package/lib/code-path-analysis/code-path-analyzer.js +1 -1
  5. package/lib/config/config-initializer.js +7 -7
  6. package/lib/config.js +1 -1
  7. package/lib/ignored-paths.js +125 -37
  8. package/lib/linter.js +1 -1
  9. package/lib/rules/array-bracket-newline.js +1 -1
  10. package/lib/rules/array-bracket-spacing.js +1 -1
  11. package/lib/rules/array-callback-return.js +1 -1
  12. package/lib/rules/array-element-newline.js +1 -1
  13. package/lib/rules/arrow-body-style.js +1 -1
  14. package/lib/rules/arrow-parens.js +1 -1
  15. package/lib/rules/arrow-spacing.js +1 -1
  16. package/lib/rules/block-spacing.js +1 -1
  17. package/lib/rules/brace-style.js +1 -1
  18. package/lib/rules/capitalized-comments.js +1 -1
  19. package/lib/rules/comma-dangle.js +1 -1
  20. package/lib/rules/comma-spacing.js +1 -1
  21. package/lib/rules/comma-style.js +1 -1
  22. package/lib/rules/complexity.js +1 -1
  23. package/lib/rules/computed-property-spacing.js +1 -1
  24. package/lib/rules/consistent-return.js +1 -1
  25. package/lib/rules/curly.js +1 -1
  26. package/lib/rules/dot-location.js +1 -1
  27. package/lib/rules/dot-notation.js +1 -1
  28. package/lib/rules/eqeqeq.js +1 -1
  29. package/lib/rules/func-call-spacing.js +1 -1
  30. package/lib/rules/func-name-matching.js +1 -1
  31. package/lib/rules/func-names.js +1 -1
  32. package/lib/rules/function-paren-newline.js +1 -1
  33. package/lib/rules/getter-return.js +1 -1
  34. package/lib/rules/indent-legacy.js +1 -1
  35. package/lib/rules/indent.js +37 -5
  36. package/lib/rules/jsx-quotes.js +1 -1
  37. package/lib/rules/key-spacing.js +2 -2
  38. package/lib/rules/keyword-spacing.js +1 -1
  39. package/lib/rules/line-comment-position.js +2 -2
  40. package/lib/rules/linebreak-style.js +1 -1
  41. package/lib/rules/lines-around-comment.js +1 -1
  42. package/lib/rules/lines-around-directive.js +1 -1
  43. package/lib/rules/lines-between-class-members.js +1 -1
  44. package/lib/rules/max-len.js +1 -1
  45. package/lib/rules/max-lines-per-function.js +1 -1
  46. package/lib/rules/max-lines.js +1 -1
  47. package/lib/rules/max-params.js +1 -1
  48. package/lib/rules/max-statements-per-line.js +1 -1
  49. package/lib/rules/max-statements.js +1 -1
  50. package/lib/rules/multiline-comment-style.js +1 -1
  51. package/lib/rules/multiline-ternary.js +1 -1
  52. package/lib/rules/new-parens.js +1 -1
  53. package/lib/rules/newline-after-var.js +1 -1
  54. package/lib/rules/newline-per-chained-call.js +1 -1
  55. package/lib/rules/no-alert.js +1 -1
  56. package/lib/rules/no-async-promise-executor.js +33 -0
  57. package/lib/rules/no-catch-shadow.js +1 -1
  58. package/lib/rules/no-class-assign.js +1 -1
  59. package/lib/rules/no-cond-assign.js +1 -1
  60. package/lib/rules/no-confusing-arrow.js +1 -1
  61. package/lib/rules/no-console.js +1 -1
  62. package/lib/rules/no-const-assign.js +1 -1
  63. package/lib/rules/no-dupe-keys.js +1 -1
  64. package/lib/rules/no-else-return.js +1 -1
  65. package/lib/rules/no-empty-function.js +1 -1
  66. package/lib/rules/no-empty.js +1 -1
  67. package/lib/rules/no-eval.js +1 -1
  68. package/lib/rules/no-ex-assign.js +1 -1
  69. package/lib/rules/no-extend-native.js +1 -1
  70. package/lib/rules/no-extra-bind.js +1 -1
  71. package/lib/rules/no-extra-boolean-cast.js +1 -1
  72. package/lib/rules/no-extra-label.js +1 -1
  73. package/lib/rules/no-extra-parens.js +1 -1
  74. package/lib/rules/no-extra-semi.js +1 -1
  75. package/lib/rules/no-floating-decimal.js +1 -1
  76. package/lib/rules/no-func-assign.js +1 -1
  77. package/lib/rules/no-implicit-coercion.js +1 -1
  78. package/lib/rules/no-inline-comments.js +1 -1
  79. package/lib/rules/no-invalid-this.js +1 -1
  80. package/lib/rules/no-irregular-whitespace.js +1 -1
  81. package/lib/rules/no-label-var.js +1 -1
  82. package/lib/rules/no-labels.js +1 -1
  83. package/lib/rules/no-misleading-character-class.js +189 -0
  84. package/lib/rules/no-mixed-operators.js +1 -1
  85. package/lib/rules/no-multi-spaces.js +1 -1
  86. package/lib/rules/no-multi-str.js +1 -1
  87. package/lib/rules/no-regex-spaces.js +1 -1
  88. package/lib/rules/no-restricted-properties.js +1 -1
  89. package/lib/rules/no-return-assign.js +1 -1
  90. package/lib/rules/no-return-await.js +1 -1
  91. package/lib/rules/no-self-assign.js +1 -1
  92. package/lib/rules/no-sequences.js +1 -1
  93. package/lib/rules/no-shadow.js +1 -1
  94. package/lib/rules/no-this-before-super.js +1 -1
  95. package/lib/rules/no-throw-literal.js +1 -1
  96. package/lib/rules/no-trailing-spaces.js +1 -1
  97. package/lib/rules/no-undef-init.js +1 -1
  98. package/lib/rules/no-unexpected-multiline.js +1 -1
  99. package/lib/rules/no-unmodified-loop-condition.js +2 -3
  100. package/lib/rules/no-unneeded-ternary.js +1 -1
  101. package/lib/rules/no-unsafe-negation.js +1 -1
  102. package/lib/rules/no-unused-vars.js +1 -1
  103. package/lib/rules/no-useless-call.js +1 -1
  104. package/lib/rules/no-useless-computed-key.js +1 -1
  105. package/lib/rules/no-useless-concat.js +1 -1
  106. package/lib/rules/no-useless-escape.js +1 -1
  107. package/lib/rules/no-useless-return.js +2 -11
  108. package/lib/rules/no-var.js +1 -1
  109. package/lib/rules/no-warning-comments.js +1 -1
  110. package/lib/rules/no-whitespace-before-property.js +1 -1
  111. package/lib/rules/object-curly-newline.js +1 -1
  112. package/lib/rules/object-curly-spacing.js +1 -1
  113. package/lib/rules/object-shorthand.js +1 -1
  114. package/lib/rules/operator-assignment.js +1 -1
  115. package/lib/rules/operator-linebreak.js +1 -1
  116. package/lib/rules/padding-line-between-statements.js +2 -2
  117. package/lib/rules/prefer-const.js +2 -11
  118. package/lib/rules/prefer-object-spread.js +9 -3
  119. package/lib/rules/prefer-promise-reject-errors.js +1 -1
  120. package/lib/rules/prefer-spread.js +1 -1
  121. package/lib/rules/prefer-template.js +1 -1
  122. package/lib/rules/quotes.js +1 -1
  123. package/lib/rules/radix.js +1 -1
  124. package/lib/rules/require-atomic-updates.js +239 -0
  125. package/lib/rules/require-await.js +1 -1
  126. package/lib/rules/require-unicode-regexp.js +65 -0
  127. package/lib/rules/semi-spacing.js +1 -1
  128. package/lib/rules/semi-style.js +1 -1
  129. package/lib/rules/semi.js +1 -1
  130. package/lib/rules/sort-keys.js +1 -1
  131. package/lib/rules/space-before-blocks.js +1 -1
  132. package/lib/rules/space-before-function-paren.js +1 -1
  133. package/lib/rules/space-in-parens.js +1 -1
  134. package/lib/rules/space-unary-ops.js +1 -1
  135. package/lib/rules/spaced-comment.js +1 -1
  136. package/lib/rules/strict.js +1 -1
  137. package/lib/rules/switch-colon-spacing.js +1 -1
  138. package/lib/rules/symbol-description.js +1 -1
  139. package/lib/rules/template-curly-spacing.js +1 -1
  140. package/lib/rules/wrap-iife.js +1 -1
  141. package/lib/rules/yoda.js +1 -1
  142. package/lib/testers/rule-tester.js +2 -2
  143. package/lib/token-store/index.js +1 -1
  144. package/lib/{ast-utils.js → util/ast-utils.js} +0 -0
  145. package/lib/{file-finder.js → util/file-finder.js} +0 -0
  146. package/lib/util/fix-tracker.js +1 -1
  147. package/lib/util/{glob-util.js → glob-utils.js} +4 -4
  148. package/lib/util/naming.js +2 -2
  149. package/lib/util/node-event-generator.js +3 -3
  150. package/lib/util/{npm-util.js → npm-utils.js} +0 -0
  151. package/lib/util/{path-util.js → path-utils.js} +1 -1
  152. package/lib/util/{source-code-util.js → source-code-utils.js} +3 -3
  153. package/lib/util/source-code.js +1 -1
  154. package/lib/util/unicode/index.js +11 -0
  155. package/lib/util/unicode/is-combining-character.js +13 -0
  156. package/lib/util/unicode/is-emoji-modifier.js +13 -0
  157. package/lib/util/unicode/is-regional-indicator-symbol.js +13 -0
  158. package/lib/util/unicode/is-surrogate-pair.js +14 -0
  159. package/package.json +2 -2
@@ -5,7 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const astUtils = require("../ast-utils");
8
+ const astUtils = require("../util/ast-utils");
9
9
 
10
10
  //------------------------------------------------------------------------------
11
11
  // Helpers
@@ -15,15 +15,6 @@ const PATTERN_TYPE = /^(?:.+?Pattern|RestElement|SpreadProperty|ExperimentalRest
15
15
  const DECLARATION_HOST_TYPE = /^(?:Program|BlockStatement|SwitchCase)$/;
16
16
  const DESTRUCTURING_HOST_TYPE = /^(?:VariableDeclarator|AssignmentExpression)$/;
17
17
 
18
- /**
19
- * Adds multiple items to the tail of an array.
20
- *
21
- * @param {any[]} array - A destination to add.
22
- * @param {any[]} values - Items to be added.
23
- * @returns {void}
24
- */
25
- const pushAll = Function.apply.bind(Array.prototype.push);
26
-
27
18
  /**
28
19
  * Checks whether a given node is located at `ForStatement.init` or not.
29
20
  *
@@ -364,7 +355,7 @@ module.exports = {
364
355
 
365
356
  VariableDeclaration(node) {
366
357
  if (node.kind === "let" && !isInitOfForStatement(node)) {
367
- pushAll(variables, context.getDeclaredVariables(node));
358
+ variables.push(...context.getDeclaredVariables(node));
368
359
  }
369
360
  }
370
361
  };
@@ -12,7 +12,7 @@ const {
12
12
  isOpeningParenToken,
13
13
  isClosingParenToken,
14
14
  isParenthesised
15
- } = require("../ast-utils");
15
+ } = require("../util/ast-utils");
16
16
 
17
17
  const ANY_SPACE = /\s/;
18
18
 
@@ -180,8 +180,14 @@ function defineFixer(node, sourceCode) {
180
180
  for (const innerParen of innerParens) {
181
181
  yield fixer.remove(innerParen);
182
182
  }
183
- yield fixer.removeRange([left.range[0], getEndWithSpaces(left, sourceCode)]);
184
- yield fixer.removeRange([getStartWithSpaces(right, sourceCode), right.range[1]]);
183
+ const leftRange = [left.range[0], getEndWithSpaces(left, sourceCode)];
184
+ const rightRange = [
185
+ Math.max(getStartWithSpaces(right, sourceCode), leftRange[1]), // Ensure ranges don't overlap
186
+ right.range[1]
187
+ ];
188
+
189
+ yield fixer.removeRange(leftRange);
190
+ yield fixer.removeRange(rightRange);
185
191
 
186
192
  // Remove the comma of this argument if it's duplication.
187
193
  if (
@@ -4,7 +4,7 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
- const astUtils = require("../ast-utils");
7
+ const astUtils = require("../util/ast-utils");
8
8
 
9
9
  //------------------------------------------------------------------------------
10
10
  // Rule Definition
@@ -5,7 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const astUtils = require("../ast-utils");
8
+ const astUtils = require("../util/ast-utils");
9
9
 
10
10
  //------------------------------------------------------------------------------
11
11
  // Helpers
@@ -9,7 +9,7 @@
9
9
  // Requirements
10
10
  //------------------------------------------------------------------------------
11
11
 
12
- const astUtils = require("../ast-utils");
12
+ const astUtils = require("../util/ast-utils");
13
13
 
14
14
  //------------------------------------------------------------------------------
15
15
  // Helpers
@@ -9,7 +9,7 @@
9
9
  // Requirements
10
10
  //------------------------------------------------------------------------------
11
11
 
12
- const astUtils = require("../ast-utils");
12
+ const astUtils = require("../util/ast-utils");
13
13
 
14
14
  //------------------------------------------------------------------------------
15
15
  // Constants
@@ -9,7 +9,7 @@
9
9
  // Requirements
10
10
  //------------------------------------------------------------------------------
11
11
 
12
- const astUtils = require("../ast-utils");
12
+ const astUtils = require("../util/ast-utils");
13
13
 
14
14
  //------------------------------------------------------------------------------
15
15
  // Helpers
@@ -0,0 +1,239 @@
1
+ /**
2
+ * @fileoverview disallow assignments that can lead to race conditions due to usage of `await` or `yield`
3
+ * @author Teddy Katz
4
+ */
5
+ "use strict";
6
+
7
+ const astUtils = require("../util/ast-utils");
8
+
9
+ //------------------------------------------------------------------------------
10
+ // Rule Definition
11
+ //------------------------------------------------------------------------------
12
+
13
+ module.exports = {
14
+ meta: {
15
+ docs: {
16
+ description: "disallow assignments that can lead to race conditions due to usage of `await` or `yield`",
17
+ category: "Possible Errors",
18
+ recommended: false,
19
+ url: "https://eslint.org/docs/rules/require-atomic-updates"
20
+ },
21
+ fixable: null,
22
+ schema: [],
23
+ messages: {
24
+ nonAtomicUpdate: "Possible race condition: `{{value}}` might be reassigned based on an outdated value of `{{value}}`."
25
+ }
26
+ },
27
+
28
+ create(context) {
29
+ const sourceCode = context.getSourceCode();
30
+ const identifierToSurroundingFunctionMap = new WeakMap();
31
+ const expressionsByCodePathSegment = new Map();
32
+
33
+ //----------------------------------------------------------------------
34
+ // Helpers
35
+ //----------------------------------------------------------------------
36
+
37
+ const resolvedVariableCache = new WeakMap();
38
+
39
+ /**
40
+ * Gets the variable scope around this variable reference
41
+ * @param {ASTNode} identifier An `Identifier` AST node
42
+ * @returns {Scope|null} An escope Scope
43
+ */
44
+ function getScope(identifier) {
45
+ for (let currentNode = identifier; currentNode; currentNode = currentNode.parent) {
46
+ const scope = sourceCode.scopeManager.acquire(currentNode, true);
47
+
48
+ if (scope) {
49
+ return scope;
50
+ }
51
+ }
52
+ return null;
53
+ }
54
+
55
+ /**
56
+ * Resolves a given identifier to a given scope
57
+ * @param {ASTNode} identifier An `Identifier` AST node
58
+ * @param {Scope} scope An escope Scope
59
+ * @returns {Variable|null} An escope Variable corresponding to the given identifier
60
+ */
61
+ function resolveVariableInScope(identifier, scope) {
62
+ return scope.variables.find(variable => variable.name === identifier.name) ||
63
+ (scope.upper ? resolveVariableInScope(identifier, scope.upper) : null);
64
+ }
65
+
66
+ /**
67
+ * Resolves an identifier to a variable
68
+ * @param {ASTNode} identifier An identifier node
69
+ * @returns {Variable|null} The escope Variable that uses this identifier
70
+ */
71
+ function resolveVariable(identifier) {
72
+ if (!resolvedVariableCache.has(identifier)) {
73
+ const surroundingScope = getScope(identifier);
74
+
75
+ if (surroundingScope) {
76
+ resolvedVariableCache.set(identifier, resolveVariableInScope(identifier, surroundingScope));
77
+ } else {
78
+ resolvedVariableCache.set(identifier, null);
79
+ }
80
+ }
81
+
82
+ return resolvedVariableCache.get(identifier);
83
+ }
84
+
85
+ /**
86
+ * Checks if an expression is a variable that can only be observed within the given function.
87
+ * @param {ASTNode} expression The expression to check
88
+ * @param {ASTNode} surroundingFunction The function node
89
+ * @returns {boolean} `true` if the expression is a variable which is local to the given function, and is never
90
+ * referenced in a closure.
91
+ */
92
+ function isLocalVariableWithoutEscape(expression, surroundingFunction) {
93
+ if (expression.type !== "Identifier") {
94
+ return false;
95
+ }
96
+
97
+ const variable = resolveVariable(expression);
98
+
99
+ if (!variable) {
100
+ return false;
101
+ }
102
+
103
+ return variable.references.every(reference => identifierToSurroundingFunctionMap.get(reference.identifier) === surroundingFunction) &&
104
+ variable.defs.every(def => identifierToSurroundingFunctionMap.get(def.name) === surroundingFunction);
105
+ }
106
+
107
+ /**
108
+ * Reports an AssignmentExpression node that has a non-atomic update
109
+ * @param {ASTNode} assignmentExpression The assignment that is potentially unsafe
110
+ * @returns {void}
111
+ */
112
+ function reportAssignment(assignmentExpression) {
113
+ context.report({
114
+ node: assignmentExpression,
115
+ messageId: "nonAtomicUpdate",
116
+ data: {
117
+ value: sourceCode.getText(assignmentExpression.left)
118
+ }
119
+ });
120
+ }
121
+
122
+ /**
123
+ * If the control flow graph of a function enters an assignment expression, then does the
124
+ * both of the following steps in order (possibly with other steps in between) before exiting the
125
+ * assignment expression, then the assignment might be using an outdated value.
126
+ * 1. Enters a read of the variable or property assigned in the expression (not necessary if operator assignment is used)
127
+ * 2. Exits an `await` or `yield` expression
128
+ *
129
+ * This function checks for the outdated values and reports them.
130
+ * @param {CodePathSegment} codePathSegment The current code path segment to traverse
131
+ * @param {ASTNode} surroundingFunction The function node containing the code path segment
132
+ * @returns {void}
133
+ */
134
+ function findOutdatedReads(
135
+ codePathSegment,
136
+ surroundingFunction,
137
+ {
138
+ seenSegments = new Set(),
139
+ openAssignmentsWithoutReads = new Set(),
140
+ openAssignmentsWithReads = new Set()
141
+ } = {}
142
+ ) {
143
+ if (seenSegments.has(codePathSegment)) {
144
+
145
+ // An AssignmentExpression can't contain loops, so it's not necessary to reenter them with new state.
146
+ return;
147
+ }
148
+
149
+ expressionsByCodePathSegment.get(codePathSegment).forEach(({ entering, node }) => {
150
+ if (node.type === "AssignmentExpression") {
151
+ if (entering) {
152
+ (node.operator === "=" ? openAssignmentsWithoutReads : openAssignmentsWithReads).add(node);
153
+ } else {
154
+ openAssignmentsWithoutReads.delete(node);
155
+ openAssignmentsWithReads.delete(node);
156
+ }
157
+ } else if (!entering && (node.type === "AwaitExpression" || node.type === "YieldExpression")) {
158
+ [...openAssignmentsWithReads]
159
+ .filter(assignment => !isLocalVariableWithoutEscape(assignment.left, surroundingFunction))
160
+ .forEach(reportAssignment);
161
+
162
+ openAssignmentsWithReads.clear();
163
+ } else if (!entering && (node.type === "Identifier" || node.type === "MemberExpression")) {
164
+ [...openAssignmentsWithoutReads]
165
+ .filter(assignment => (
166
+ assignment.left !== node &&
167
+ assignment.left.type === node.type &&
168
+ astUtils.equalTokens(assignment.left, node, sourceCode)
169
+ ))
170
+ .forEach(assignment => {
171
+ openAssignmentsWithoutReads.delete(assignment);
172
+ openAssignmentsWithReads.add(assignment);
173
+ });
174
+ }
175
+ });
176
+
177
+ codePathSegment.nextSegments.forEach(nextSegment => {
178
+ findOutdatedReads(
179
+ nextSegment,
180
+ surroundingFunction,
181
+ {
182
+ seenSegments: new Set(seenSegments).add(codePathSegment),
183
+ openAssignmentsWithoutReads: new Set(openAssignmentsWithoutReads),
184
+ openAssignmentsWithReads: new Set(openAssignmentsWithReads)
185
+ }
186
+ );
187
+ });
188
+ }
189
+
190
+ //----------------------------------------------------------------------
191
+ // Public
192
+ //----------------------------------------------------------------------
193
+
194
+ const currentCodePathSegmentStack = [];
195
+ let currentCodePathSegment = null;
196
+ const functionStack = [];
197
+
198
+ return {
199
+ onCodePathStart() {
200
+ currentCodePathSegmentStack.push(currentCodePathSegment);
201
+ },
202
+
203
+ onCodePathEnd(codePath, node) {
204
+ currentCodePathSegment = currentCodePathSegmentStack.pop();
205
+
206
+ if (astUtils.isFunction(node) && (node.async || node.generator)) {
207
+ findOutdatedReads(codePath.initialSegment, node);
208
+ }
209
+ },
210
+
211
+ onCodePathSegmentStart(segment) {
212
+ currentCodePathSegment = segment;
213
+ expressionsByCodePathSegment.set(segment, []);
214
+ },
215
+
216
+ "AssignmentExpression, Identifier, MemberExpression, AwaitExpression, YieldExpression"(node) {
217
+ expressionsByCodePathSegment.get(currentCodePathSegment).push({ entering: true, node });
218
+ },
219
+
220
+ "AssignmentExpression, Identifier, MemberExpression, AwaitExpression, YieldExpression:exit"(node) {
221
+ expressionsByCodePathSegment.get(currentCodePathSegment).push({ entering: false, node });
222
+ },
223
+
224
+ ":function"(node) {
225
+ functionStack.push(node);
226
+ },
227
+
228
+ ":function:exit"() {
229
+ functionStack.pop();
230
+ },
231
+
232
+ Identifier(node) {
233
+ if (functionStack.length) {
234
+ identifierToSurroundingFunctionMap.set(node, functionStack[functionStack.length - 1]);
235
+ }
236
+ }
237
+ };
238
+ }
239
+ };
@@ -9,7 +9,7 @@
9
9
  // Requirements
10
10
  //------------------------------------------------------------------------------
11
11
 
12
- const astUtils = require("../ast-utils");
12
+ const astUtils = require("../util/ast-utils");
13
13
 
14
14
  //------------------------------------------------------------------------------
15
15
  // Helpers
@@ -0,0 +1,65 @@
1
+ /**
2
+ * @fileoverview Rule to enforce the use of `u` flag on RegExp.
3
+ * @author Toru Nagashima
4
+ */
5
+
6
+ "use strict";
7
+
8
+ //------------------------------------------------------------------------------
9
+ // Requirements
10
+ //------------------------------------------------------------------------------
11
+
12
+ const {
13
+ CALL,
14
+ CONSTRUCT,
15
+ ReferenceTracker,
16
+ getStringIfConstant
17
+ } = require("eslint-utils");
18
+
19
+ //------------------------------------------------------------------------------
20
+ // Rule Definition
21
+ //------------------------------------------------------------------------------
22
+
23
+ module.exports = {
24
+ meta: {
25
+ docs: {
26
+ description: "enforce the use of `u` flag on RegExp",
27
+ category: "Best Practices",
28
+ recommended: false,
29
+ url: "https://eslint.org/docs/rules/require-unicode-regexp"
30
+ },
31
+ messages: {
32
+ requireUFlag: "Use the 'u' flag."
33
+ },
34
+ schema: []
35
+ },
36
+
37
+ create(context) {
38
+ return {
39
+ "Literal[regex]"(node) {
40
+ const flags = node.regex.flags || "";
41
+
42
+ if (!flags.includes("u")) {
43
+ context.report({ node, messageId: "requireUFlag" });
44
+ }
45
+ },
46
+
47
+ Program() {
48
+ const scope = context.getScope();
49
+ const tracker = new ReferenceTracker(scope);
50
+ const trackMap = {
51
+ RegExp: { [CALL]: true, [CONSTRUCT]: true }
52
+ };
53
+
54
+ for (const { node } of tracker.iterateGlobalReferences(trackMap)) {
55
+ const flagsNode = node.arguments[1];
56
+ const flags = getStringIfConstant(flagsNode, scope);
57
+
58
+ if (!flagsNode || (typeof flags === "string" && !flags.includes("u"))) {
59
+ context.report({ node, messageId: "requireUFlag" });
60
+ }
61
+ }
62
+ }
63
+ };
64
+ }
65
+ };
@@ -5,7 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const astUtils = require("../ast-utils");
8
+ const astUtils = require("../util/ast-utils");
9
9
 
10
10
  //------------------------------------------------------------------------------
11
11
  // Rule Definition
@@ -9,7 +9,7 @@
9
9
  // Requirements
10
10
  //------------------------------------------------------------------------------
11
11
 
12
- const astUtils = require("../ast-utils");
12
+ const astUtils = require("../util/ast-utils");
13
13
 
14
14
  //------------------------------------------------------------------------------
15
15
  // Rule Definition
package/lib/rules/semi.js CHANGED
@@ -9,7 +9,7 @@
9
9
  //------------------------------------------------------------------------------
10
10
 
11
11
  const FixTracker = require("../util/fix-tracker");
12
- const astUtils = require("../ast-utils");
12
+ const astUtils = require("../util/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("../ast-utils"),
12
+ const astUtils = require("../util/ast-utils"),
13
13
  naturalCompare = require("natural-compare");
14
14
 
15
15
  //------------------------------------------------------------------------------
@@ -5,7 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const astUtils = require("../ast-utils");
8
+ const astUtils = require("../util/ast-utils");
9
9
 
10
10
  //------------------------------------------------------------------------------
11
11
  // Rule Definition
@@ -8,7 +8,7 @@
8
8
  // Requirements
9
9
  //------------------------------------------------------------------------------
10
10
 
11
- const astUtils = require("../ast-utils");
11
+ const astUtils = require("../util/ast-utils");
12
12
 
13
13
  //------------------------------------------------------------------------------
14
14
  // Rule Definition
@@ -4,7 +4,7 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
- const astUtils = require("../ast-utils");
7
+ const astUtils = require("../util/ast-utils");
8
8
 
9
9
  //------------------------------------------------------------------------------
10
10
  // Rule Definition
@@ -8,7 +8,7 @@
8
8
  // Requirements
9
9
  //------------------------------------------------------------------------------
10
10
 
11
- const astUtils = require("../ast-utils");
11
+ const astUtils = require("../util/ast-utils");
12
12
 
13
13
  //------------------------------------------------------------------------------
14
14
  // Rule Definition
@@ -5,7 +5,7 @@
5
5
  "use strict";
6
6
 
7
7
  const lodash = require("lodash");
8
- const astUtils = require("../ast-utils");
8
+ const astUtils = require("../util/ast-utils");
9
9
 
10
10
  //------------------------------------------------------------------------------
11
11
  // Helpers
@@ -9,7 +9,7 @@
9
9
  // Requirements
10
10
  //------------------------------------------------------------------------------
11
11
 
12
- const astUtils = require("../ast-utils");
12
+ const astUtils = require("../util/ast-utils");
13
13
 
14
14
  //------------------------------------------------------------------------------
15
15
  // Helpers
@@ -9,7 +9,7 @@
9
9
  // Requirements
10
10
  //------------------------------------------------------------------------------
11
11
 
12
- const astUtils = require("../ast-utils");
12
+ const astUtils = require("../util/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("../ast-utils");
12
+ const astUtils = require("../util/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("../ast-utils");
12
+ const astUtils = require("../util/ast-utils");
13
13
 
14
14
  //------------------------------------------------------------------------------
15
15
  // Helpers
@@ -9,7 +9,7 @@
9
9
  // Requirements
10
10
  //------------------------------------------------------------------------------
11
11
 
12
- const astUtils = require("../ast-utils");
12
+ const astUtils = require("../util/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("../ast-utils");
11
+ const astUtils = require("../util/ast-utils");
12
12
 
13
13
  //--------------------------------------------------------------------------
14
14
  // Helpers
@@ -140,7 +140,7 @@ const IT = Symbol("it");
140
140
  */
141
141
  function itDefaultHandler(text, method) {
142
142
  try {
143
- return method.apply(this);
143
+ return method.call(this);
144
144
  } catch (err) {
145
145
  if (err instanceof assert.AssertionError) {
146
146
  err.message += ` (${util.inspect(err.actual)} ${err.operator} ${util.inspect(err.expected)})`;
@@ -157,7 +157,7 @@ function itDefaultHandler(text, method) {
157
157
  * @returns {any} Returned value of `method`.
158
158
  */
159
159
  function describeDefaultHandler(text, method) {
160
- return method.apply(this);
160
+ return method.call(this);
161
161
  }
162
162
 
163
163
  class RuleTester {
@@ -13,7 +13,7 @@ const cursors = require("./cursors");
13
13
  const ForwardTokenCursor = require("./forward-token-cursor");
14
14
  const PaddedTokenCursor = require("./padded-token-cursor");
15
15
  const utils = require("./utils");
16
- const astUtils = require("../ast-utils");
16
+ const astUtils = require("../util/ast-utils");
17
17
 
18
18
  //------------------------------------------------------------------------------
19
19
  // Helpers
File without changes
File without changes
@@ -8,7 +8,7 @@
8
8
  // Requirements
9
9
  //------------------------------------------------------------------------------
10
10
 
11
- const astUtils = require("../ast-utils");
11
+ const astUtils = require("../util/ast-utils");
12
12
 
13
13
  //------------------------------------------------------------------------------
14
14
  // Public Interface
@@ -13,10 +13,10 @@ const lodash = require("lodash"),
13
13
  path = require("path"),
14
14
  GlobSync = require("./glob"),
15
15
 
16
- pathUtil = require("./path-util"),
16
+ pathUtils = require("./path-utils"),
17
17
  IgnoredPaths = require("../ignored-paths");
18
18
 
19
- const debug = require("debug")("eslint:glob-util");
19
+ const debug = require("debug")("eslint:glob-utils");
20
20
 
21
21
  //------------------------------------------------------------------------------
22
22
  // Helpers
@@ -77,7 +77,7 @@ function processPath(options) {
77
77
  newPath = pathname.replace(/[/\\]$/, "") + suffix;
78
78
  }
79
79
 
80
- return pathUtil.convertPathToPosix(newPath);
80
+ return pathUtils.convertPathToPosix(newPath);
81
81
  };
82
82
  }
83
83
 
@@ -194,7 +194,7 @@ function listFilesToProcess(globPatterns, providedOptions) {
194
194
  );
195
195
 
196
196
  /*
197
- * The test "should use default options if none are provided" (source-code-util.js) checks that 'module.exports.resolveFileGlobPatterns' was called.
197
+ * The test "should use default options if none are provided" (source-code-utils.js) checks that 'module.exports.resolveFileGlobPatterns' was called.
198
198
  * So it cannot use the local function "resolveFileGlobPatterns".
199
199
  */
200
200
  const resolvedGlobPatterns = module.exports.resolveFileGlobPatterns(globPatterns, options);