eslint 5.1.0 → 5.5.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 (180) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/conf/eslint-recommended.js +4 -0
  3. package/lib/cli-engine.js +38 -78
  4. package/lib/cli.js +1 -1
  5. package/lib/code-path-analysis/code-path-analyzer.js +1 -1
  6. package/lib/config/config-initializer.js +8 -8
  7. package/lib/config.js +1 -1
  8. package/lib/formatters/codeframe.js +2 -2
  9. package/lib/ignored-paths.js +125 -37
  10. package/lib/linter.js +6 -7
  11. package/lib/rules/array-bracket-newline.js +1 -1
  12. package/lib/rules/array-bracket-spacing.js +1 -1
  13. package/lib/rules/array-callback-return.js +1 -1
  14. package/lib/rules/array-element-newline.js +1 -1
  15. package/lib/rules/arrow-body-style.js +1 -1
  16. package/lib/rules/arrow-parens.js +1 -1
  17. package/lib/rules/arrow-spacing.js +1 -1
  18. package/lib/rules/block-spacing.js +1 -1
  19. package/lib/rules/brace-style.js +1 -1
  20. package/lib/rules/camelcase.js +1 -1
  21. package/lib/rules/capitalized-comments.js +1 -1
  22. package/lib/rules/comma-dangle.js +1 -1
  23. package/lib/rules/comma-spacing.js +1 -1
  24. package/lib/rules/comma-style.js +2 -2
  25. package/lib/rules/complexity.js +3 -3
  26. package/lib/rules/computed-property-spacing.js +1 -1
  27. package/lib/rules/consistent-return.js +1 -1
  28. package/lib/rules/curly.js +1 -1
  29. package/lib/rules/dot-location.js +1 -1
  30. package/lib/rules/dot-notation.js +1 -1
  31. package/lib/rules/eqeqeq.js +1 -1
  32. package/lib/rules/for-direction.js +5 -2
  33. package/lib/rules/func-call-spacing.js +8 -4
  34. package/lib/rules/func-name-matching.js +13 -7
  35. package/lib/rules/func-names.js +8 -4
  36. package/lib/rules/func-style.js +8 -4
  37. package/lib/rules/function-paren-newline.js +12 -6
  38. package/lib/rules/generator-star-spacing.js +18 -9
  39. package/lib/rules/getter-return.js +8 -6
  40. package/lib/rules/indent-legacy.js +1 -1
  41. package/lib/rules/indent.js +43 -7
  42. package/lib/rules/jsx-quotes.js +1 -1
  43. package/lib/rules/key-spacing.js +2 -2
  44. package/lib/rules/keyword-spacing.js +1 -1
  45. package/lib/rules/line-comment-position.js +3 -3
  46. package/lib/rules/linebreak-style.js +1 -1
  47. package/lib/rules/lines-around-comment.js +1 -1
  48. package/lib/rules/lines-around-directive.js +1 -1
  49. package/lib/rules/lines-between-class-members.js +1 -1
  50. package/lib/rules/max-depth.js +2 -2
  51. package/lib/rules/max-len.js +1 -1
  52. package/lib/rules/max-lines-per-function.js +1 -1
  53. package/lib/rules/max-lines.js +2 -2
  54. package/lib/rules/max-nested-callbacks.js +2 -2
  55. package/lib/rules/max-params.js +5 -4
  56. package/lib/rules/max-statements-per-line.js +1 -1
  57. package/lib/rules/max-statements.js +3 -3
  58. package/lib/rules/multiline-comment-style.js +1 -1
  59. package/lib/rules/multiline-ternary.js +1 -1
  60. package/lib/rules/new-parens.js +1 -1
  61. package/lib/rules/newline-after-var.js +1 -1
  62. package/lib/rules/newline-per-chained-call.js +1 -1
  63. package/lib/rules/no-alert.js +1 -1
  64. package/lib/rules/no-async-promise-executor.js +33 -0
  65. package/lib/rules/no-catch-shadow.js +1 -1
  66. package/lib/rules/no-class-assign.js +1 -1
  67. package/lib/rules/no-cond-assign.js +1 -1
  68. package/lib/rules/no-confusing-arrow.js +1 -1
  69. package/lib/rules/no-console.js +1 -1
  70. package/lib/rules/no-const-assign.js +1 -1
  71. package/lib/rules/no-dupe-keys.js +1 -1
  72. package/lib/rules/no-else-return.js +1 -1
  73. package/lib/rules/no-empty-function.js +1 -1
  74. package/lib/rules/no-empty.js +1 -1
  75. package/lib/rules/no-eval.js +1 -1
  76. package/lib/rules/no-ex-assign.js +1 -1
  77. package/lib/rules/no-extend-native.js +1 -1
  78. package/lib/rules/no-extra-bind.js +1 -1
  79. package/lib/rules/no-extra-boolean-cast.js +1 -1
  80. package/lib/rules/no-extra-label.js +1 -1
  81. package/lib/rules/no-extra-parens.js +2 -2
  82. package/lib/rules/no-extra-semi.js +1 -1
  83. package/lib/rules/no-floating-decimal.js +1 -1
  84. package/lib/rules/no-func-assign.js +1 -1
  85. package/lib/rules/no-implicit-coercion.js +1 -1
  86. package/lib/rules/no-inline-comments.js +1 -1
  87. package/lib/rules/no-invalid-this.js +1 -1
  88. package/lib/rules/no-irregular-whitespace.js +1 -1
  89. package/lib/rules/no-label-var.js +1 -1
  90. package/lib/rules/no-labels.js +1 -1
  91. package/lib/rules/no-magic-numbers.js +7 -3
  92. package/lib/rules/no-misleading-character-class.js +189 -0
  93. package/lib/rules/no-mixed-operators.js +1 -1
  94. package/lib/rules/no-multi-spaces.js +1 -1
  95. package/lib/rules/no-multi-str.js +1 -1
  96. package/lib/rules/no-regex-spaces.js +1 -1
  97. package/lib/rules/no-restricted-globals.js +1 -1
  98. package/lib/rules/no-restricted-imports.js +1 -1
  99. package/lib/rules/no-restricted-modules.js +1 -1
  100. package/lib/rules/no-restricted-properties.js +1 -1
  101. package/lib/rules/no-return-assign.js +1 -1
  102. package/lib/rules/no-return-await.js +1 -1
  103. package/lib/rules/no-self-assign.js +1 -1
  104. package/lib/rules/no-sequences.js +1 -1
  105. package/lib/rules/no-shadow.js +1 -1
  106. package/lib/rules/no-this-before-super.js +1 -1
  107. package/lib/rules/no-throw-literal.js +1 -1
  108. package/lib/rules/no-trailing-spaces.js +1 -1
  109. package/lib/rules/no-undef-init.js +1 -1
  110. package/lib/rules/no-unexpected-multiline.js +1 -1
  111. package/lib/rules/no-unmodified-loop-condition.js +2 -3
  112. package/lib/rules/no-unneeded-ternary.js +1 -1
  113. package/lib/rules/no-unsafe-negation.js +1 -1
  114. package/lib/rules/no-unused-vars.js +1 -1
  115. package/lib/rules/no-useless-call.js +1 -1
  116. package/lib/rules/no-useless-computed-key.js +1 -1
  117. package/lib/rules/no-useless-concat.js +1 -1
  118. package/lib/rules/no-useless-escape.js +1 -1
  119. package/lib/rules/no-useless-return.js +2 -11
  120. package/lib/rules/no-var.js +1 -1
  121. package/lib/rules/no-warning-comments.js +1 -1
  122. package/lib/rules/no-whitespace-before-property.js +1 -1
  123. package/lib/rules/object-curly-newline.js +1 -1
  124. package/lib/rules/object-curly-spacing.js +1 -1
  125. package/lib/rules/object-shorthand.js +1 -1
  126. package/lib/rules/one-var.js +6 -6
  127. package/lib/rules/operator-assignment.js +1 -1
  128. package/lib/rules/operator-linebreak.js +1 -1
  129. package/lib/rules/padded-blocks.js +6 -6
  130. package/lib/rules/padding-line-between-statements.js +2 -2
  131. package/lib/rules/prefer-const.js +2 -11
  132. package/lib/rules/prefer-object-spread.js +9 -3
  133. package/lib/rules/prefer-promise-reject-errors.js +1 -1
  134. package/lib/rules/prefer-reflect.js +1 -1
  135. package/lib/rules/prefer-spread.js +1 -1
  136. package/lib/rules/prefer-template.js +1 -1
  137. package/lib/rules/quotes.js +1 -1
  138. package/lib/rules/radix.js +1 -1
  139. package/lib/rules/require-atomic-updates.js +239 -0
  140. package/lib/rules/require-await.js +1 -1
  141. package/lib/rules/require-unicode-regexp.js +65 -0
  142. package/lib/rules/semi-spacing.js +3 -3
  143. package/lib/rules/semi-style.js +1 -1
  144. package/lib/rules/semi.js +1 -1
  145. package/lib/rules/sort-keys.js +1 -1
  146. package/lib/rules/space-before-blocks.js +1 -1
  147. package/lib/rules/space-before-function-paren.js +1 -1
  148. package/lib/rules/space-in-parens.js +1 -1
  149. package/lib/rules/space-unary-ops.js +2 -2
  150. package/lib/rules/spaced-comment.js +1 -1
  151. package/lib/rules/strict.js +1 -1
  152. package/lib/rules/switch-colon-spacing.js +1 -1
  153. package/lib/rules/symbol-description.js +1 -1
  154. package/lib/rules/template-curly-spacing.js +1 -1
  155. package/lib/rules/valid-jsdoc.js +1 -1
  156. package/lib/rules/wrap-iife.js +1 -1
  157. package/lib/rules/yoda.js +1 -1
  158. package/lib/testers/rule-tester.js +8 -10
  159. package/lib/token-store/index.js +1 -1
  160. package/lib/{ast-utils.js → util/ast-utils.js} +0 -0
  161. package/lib/{file-finder.js → util/file-finder.js} +2 -2
  162. package/lib/util/fix-tracker.js +1 -1
  163. package/lib/util/{glob-util.js → glob-utils.js} +4 -4
  164. package/lib/util/lint-result-cache.js +146 -0
  165. package/lib/{logging.js → util/logging.js} +0 -0
  166. package/lib/util/naming.js +2 -2
  167. package/lib/util/node-event-generator.js +3 -3
  168. package/lib/util/{npm-util.js → npm-utils.js} +1 -1
  169. package/lib/util/{path-util.js → path-utils.js} +1 -1
  170. package/lib/util/source-code-fixer.js +1 -1
  171. package/lib/util/{source-code-util.js → source-code-utils.js} +3 -3
  172. package/lib/util/source-code.js +1 -1
  173. package/lib/{timing.js → util/timing.js} +0 -0
  174. package/lib/util/unicode/index.js +11 -0
  175. package/lib/util/unicode/is-combining-character.js +13 -0
  176. package/lib/util/unicode/is-emoji-modifier.js +13 -0
  177. package/lib/util/unicode/is-regional-indicator-symbol.js +13 -0
  178. package/lib/util/unicode/is-surrogate-pair.js +14 -0
  179. package/package.json +14 -15
  180. package/lib/rules/.eslintrc.yml +0 -4
@@ -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
@@ -46,10 +46,10 @@ module.exports = {
46
46
  requireSpaceAfter = true;
47
47
 
48
48
  if (typeof config === "object") {
49
- if (config.hasOwnProperty("before")) {
49
+ if (Object.prototype.hasOwnProperty.call(config, "before")) {
50
50
  requireSpaceBefore = config.before;
51
51
  }
52
- if (config.hasOwnProperty("after")) {
52
+ if (Object.prototype.hasOwnProperty.call(config, "after")) {
53
53
  requireSpaceAfter = config.after;
54
54
  }
55
55
  }
@@ -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
@@ -72,7 +72,7 @@ module.exports = {
72
72
  * @returns {boolean} Whether or not an override has been provided for the operator
73
73
  */
74
74
  function overrideExistsForOperator(operator) {
75
- return options.overrides && options.overrides.hasOwnProperty(operator);
75
+ return options.overrides && Object.prototype.hasOwnProperty.call(options.overrides, operator);
76
76
  }
77
77
 
78
78
  /**
@@ -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
@@ -322,7 +322,7 @@ module.exports = {
322
322
  }
323
323
 
324
324
  // check tag preferences
325
- if (prefer.hasOwnProperty(tag.title) && tag.title !== prefer[tag.title]) {
325
+ if (Object.prototype.hasOwnProperty.call(prefer, tag.title) && tag.title !== prefer[tag.title]) {
326
326
  const entireTagRange = getAbsoluteRange(jsdocNode, tag);
327
327
 
328
328
  context.report({
@@ -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 {
@@ -396,9 +396,7 @@ class RuleTester {
396
396
  * @private
397
397
  */
398
398
  function assertASTDidntChange(beforeAST, afterAST) {
399
-
400
- // Feature detect the Node.js implementation and use that if available.
401
- if ((util.isDeepStrictEqual && !util.isDeepStrictEqual(beforeAST, afterAST)) || !lodash.isEqual(beforeAST, afterAST)) {
399
+ if (!lodash.isEqual(beforeAST, afterAST)) {
402
400
  assert.fail(null, null, "Rule should not modify AST.");
403
401
  }
404
402
  }
@@ -535,19 +533,19 @@ class RuleTester {
535
533
  assert.strictEqual(message.nodeType, error.type, `Error type should be ${error.type}, found ${message.nodeType}`);
536
534
  }
537
535
 
538
- if (error.hasOwnProperty("line")) {
536
+ if (Object.prototype.hasOwnProperty.call(error, "line")) {
539
537
  assert.strictEqual(message.line, error.line, `Error line should be ${error.line}`);
540
538
  }
541
539
 
542
- if (error.hasOwnProperty("column")) {
540
+ if (Object.prototype.hasOwnProperty.call(error, "column")) {
543
541
  assert.strictEqual(message.column, error.column, `Error column should be ${error.column}`);
544
542
  }
545
543
 
546
- if (error.hasOwnProperty("endLine")) {
544
+ if (Object.prototype.hasOwnProperty.call(error, "endLine")) {
547
545
  assert.strictEqual(message.endLine, error.endLine, `Error endLine should be ${error.endLine}`);
548
546
  }
549
547
 
550
- if (error.hasOwnProperty("endColumn")) {
548
+ if (Object.prototype.hasOwnProperty.call(error, "endColumn")) {
551
549
  assert.strictEqual(message.endColumn, error.endColumn, `Error endColumn should be ${error.endColumn}`);
552
550
  }
553
551
  } else {
@@ -558,7 +556,7 @@ class RuleTester {
558
556
  }
559
557
  }
560
558
 
561
- if (item.hasOwnProperty("output")) {
559
+ if (Object.prototype.hasOwnProperty.call(item, "output")) {
562
560
  if (item.output === null) {
563
561
  assert.strictEqual(
564
562
  messages.filter(message => message.fix).length,
@@ -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
@@ -89,7 +89,7 @@ class FileFinder {
89
89
  ? path.resolve(this.cwd, relativeDirectory)
90
90
  : this.cwd;
91
91
 
92
- if (cache.hasOwnProperty(initialDirectory)) {
92
+ if (Object.prototype.hasOwnProperty.call(cache, initialDirectory)) {
93
93
  yield* cache[initialDirectory];
94
94
  return; // to avoid doing the normal loop afterwards
95
95
  }
@@ -130,7 +130,7 @@ class FileFinder {
130
130
  return;
131
131
  }
132
132
 
133
- } while (!cache.hasOwnProperty(directory));
133
+ } while (!Object.prototype.hasOwnProperty.call(cache, directory));
134
134
 
135
135
  // Add what has been cached previously to the cache of each directory searched.
136
136
  for (let i = 0; i < searched; i++) {
@@ -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);