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
@@ -12,7 +12,7 @@
12
12
  const fs = require("fs"),
13
13
  path = require("path"),
14
14
  ignore = require("ignore"),
15
- pathUtil = require("./util/path-util");
15
+ pathUtils = require("./util/path-utils");
16
16
 
17
17
  const debug = require("debug")("eslint:ignored-paths");
18
18
 
@@ -79,6 +79,40 @@ function mergeDefaultOptions(options) {
79
79
  return Object.assign({}, DEFAULT_OPTIONS, options);
80
80
  }
81
81
 
82
+ /* eslint-disable valid-jsdoc */
83
+ /**
84
+ * Normalize the path separators in a given string.
85
+ * On Windows environment, this replaces `\` by `/`.
86
+ * Otherwrise, this does nothing.
87
+ * @param {string} str The path string to normalize.
88
+ * @returns {string} The normalized path.
89
+ */
90
+ const normalizePathSeps = path.sep === "/"
91
+ ? (str => str)
92
+ : ((seps, str) => str.replace(seps, "/")).bind(null, new RegExp(`\\${path.sep}`, "g"));
93
+ /* eslint-enable valid-jsdoc */
94
+
95
+ /**
96
+ * Converts a glob pattern to a new glob pattern relative to a different directory
97
+ * @param {string} globPattern The glob pattern, relative the the old base directory
98
+ * @param {string} relativePathToOldBaseDir A relative path from the new base directory to the old one
99
+ * @returns {string} A glob pattern relative to the new base directory
100
+ */
101
+ function relativize(globPattern, relativePathToOldBaseDir) {
102
+ if (relativePathToOldBaseDir === "") {
103
+ return globPattern;
104
+ }
105
+
106
+ const prefix = globPattern.startsWith("!") ? "!" : "";
107
+ const globWithoutPrefix = globPattern.replace(/^!/, "");
108
+
109
+ if (globWithoutPrefix.startsWith("/")) {
110
+ return `${prefix}/${normalizePathSeps(relativePathToOldBaseDir)}${globWithoutPrefix}`;
111
+ }
112
+
113
+ return globPattern;
114
+ }
115
+
82
116
  //------------------------------------------------------------------------------
83
117
  // Public Interface
84
118
  //------------------------------------------------------------------------------
@@ -96,41 +130,36 @@ class IgnoredPaths {
96
130
 
97
131
  this.cache = {};
98
132
 
99
- /**
100
- * add pattern to node-ignore instance
101
- * @param {Object} ig, instance of node-ignore
102
- * @param {string} pattern, pattern do add to ig
103
- * @returns {array} raw ignore rules
104
- */
105
- function addPattern(ig, pattern) {
106
- return ig.addPattern(pattern);
107
- }
108
-
109
133
  this.defaultPatterns = [].concat(DEFAULT_IGNORE_DIRS, options.patterns || []);
110
- this.baseDir = options.cwd;
134
+
135
+ this.ignoreFileDir = options.ignore !== false && options.ignorePath
136
+ ? path.dirname(path.resolve(options.cwd, options.ignorePath))
137
+ : options.cwd;
138
+ this.options = options;
139
+ this._baseDir = null;
111
140
 
112
141
  this.ig = {
113
142
  custom: ignore(),
114
143
  default: ignore()
115
144
  };
116
145
 
117
- /*
118
- * Add a way to keep track of ignored files. This was present in node-ignore
119
- * 2.x, but dropped for now as of 3.0.10.
120
- */
121
- this.ig.custom.ignoreFiles = [];
122
- this.ig.default.ignoreFiles = [];
123
-
146
+ this.defaultPatterns.forEach(pattern => this.addPatternRelativeToCwd(this.ig.default, pattern));
124
147
  if (options.dotfiles !== true) {
125
148
 
126
149
  /*
127
150
  * ignore files beginning with a dot, but not files in a parent or
128
151
  * ancestor directory (which in relative format will begin with `../`).
129
152
  */
130
- addPattern(this.ig.default, [".*", "!../"]);
153
+ this.addPatternRelativeToCwd(this.ig.default, ".*");
154
+ this.addPatternRelativeToCwd(this.ig.default, "!../");
131
155
  }
132
156
 
133
- addPattern(this.ig.default, this.defaultPatterns);
157
+ /*
158
+ * Add a way to keep track of ignored files. This was present in node-ignore
159
+ * 2.x, but dropped for now as of 3.0.10.
160
+ */
161
+ this.ig.custom.ignoreFiles = [];
162
+ this.ig.default.ignoreFiles = [];
134
163
 
135
164
  if (options.ignore !== false) {
136
165
  let ignorePath;
@@ -154,13 +183,11 @@ class IgnoredPaths {
154
183
  debug(`Loaded ignore file ${ignorePath}`);
155
184
  } catch (e) {
156
185
  debug("Could not find ignore file in cwd");
157
- this.options = options;
158
186
  }
159
187
  }
160
188
 
161
189
  if (ignorePath) {
162
190
  debug(`Adding ${ignorePath}`);
163
- this.baseDir = path.dirname(path.resolve(options.cwd, ignorePath));
164
191
  this.addIgnoreFile(this.ig.custom, ignorePath);
165
192
  this.addIgnoreFile(this.ig.default, ignorePath);
166
193
  } else {
@@ -187,8 +214,8 @@ class IgnoredPaths {
187
214
  if (packageJSONOptions.eslintIgnore) {
188
215
  if (Array.isArray(packageJSONOptions.eslintIgnore)) {
189
216
  packageJSONOptions.eslintIgnore.forEach(pattern => {
190
- addPattern(this.ig.custom, pattern);
191
- addPattern(this.ig.default, pattern);
217
+ this.addPatternRelativeToIgnoreFile(this.ig.custom, pattern);
218
+ this.addPatternRelativeToIgnoreFile(this.ig.default, pattern);
192
219
  });
193
220
  } else {
194
221
  throw new TypeError("Package.json eslintIgnore property requires an array of paths");
@@ -202,12 +229,68 @@ class IgnoredPaths {
202
229
  }
203
230
 
204
231
  if (options.ignorePattern) {
205
- addPattern(this.ig.custom, options.ignorePattern);
206
- addPattern(this.ig.default, options.ignorePattern);
232
+ this.addPatternRelativeToCwd(this.ig.custom, options.ignorePattern);
233
+ this.addPatternRelativeToCwd(this.ig.default, options.ignorePattern);
207
234
  }
208
235
  }
236
+ }
209
237
 
210
- this.options = options;
238
+ /*
239
+ * If `ignoreFileDir` is a subdirectory of `cwd`, all paths will be normalized to be relative to `cwd`.
240
+ * Otherwise, all paths will be normalized to be relative to `ignoreFileDir`.
241
+ * This ensures that the final normalized ignore rule will not contain `..`, which is forbidden in
242
+ * ignore rules.
243
+ */
244
+
245
+ addPatternRelativeToCwd(ig, pattern) {
246
+ const baseDir = this.getBaseDir();
247
+ const cookedPattern = baseDir === this.options.cwd
248
+ ? pattern
249
+ : relativize(pattern, path.relative(baseDir, this.options.cwd));
250
+
251
+ ig.addPattern(cookedPattern);
252
+ debug("addPatternRelativeToCwd:\n original = %j\n cooked = %j", pattern, cookedPattern);
253
+ }
254
+
255
+ addPatternRelativeToIgnoreFile(ig, pattern) {
256
+ const baseDir = this.getBaseDir();
257
+ const cookedPattern = baseDir === this.ignoreFileDir
258
+ ? pattern
259
+ : relativize(pattern, path.relative(baseDir, this.ignoreFileDir));
260
+
261
+ ig.addPattern(cookedPattern);
262
+ debug("addPatternRelativeToIgnoreFile:\n original = %j\n cooked = %j", pattern, cookedPattern);
263
+ }
264
+
265
+ // Detect the common ancestor
266
+ getBaseDir() {
267
+ if (!this._baseDir) {
268
+ const a = path.resolve(this.options.cwd);
269
+ const b = path.resolve(this.ignoreFileDir);
270
+ let lastSepPos = 0;
271
+
272
+ // Set the shorter one (it's the common ancestor if one includes the other).
273
+ this._baseDir = a.length < b.length ? a : b;
274
+
275
+ // Set the common ancestor.
276
+ for (let i = 0; i < a.length && i < b.length; ++i) {
277
+ if (a[i] !== b[i]) {
278
+ this._baseDir = a.slice(0, lastSepPos);
279
+ break;
280
+ }
281
+ if (a[i] === path.sep) {
282
+ lastSepPos = i;
283
+ }
284
+ }
285
+
286
+ // If it's only Windows drive letter, it needs \
287
+ if (/^[A-Z]:$/.test(this._baseDir)) {
288
+ this._baseDir += "\\";
289
+ }
290
+
291
+ debug("baseDir = %j", this._baseDir);
292
+ }
293
+ return this._baseDir;
211
294
  }
212
295
 
213
296
  /**
@@ -217,7 +300,7 @@ class IgnoredPaths {
217
300
  */
218
301
  readIgnoreFile(filePath) {
219
302
  if (typeof this.cache[filePath] === "undefined") {
220
- this.cache[filePath] = fs.readFileSync(filePath, "utf8");
303
+ this.cache[filePath] = fs.readFileSync(filePath, "utf8").split(/\r?\n/g).filter(Boolean);
221
304
  }
222
305
  return this.cache[filePath];
223
306
  }
@@ -226,11 +309,13 @@ class IgnoredPaths {
226
309
  * add ignore file to node-ignore instance
227
310
  * @param {Object} ig, instance of node-ignore
228
311
  * @param {string} filePath, file to add to ig
229
- * @returns {array} raw ignore rules
312
+ * @returns {void}
230
313
  */
231
314
  addIgnoreFile(ig, filePath) {
232
315
  ig.ignoreFiles.push(filePath);
233
- return ig.add(this.readIgnoreFile(filePath));
316
+ this
317
+ .readIgnoreFile(filePath)
318
+ .forEach(ignoreRule => this.addPatternRelativeToIgnoreFile(ig, ignoreRule));
234
319
  }
235
320
 
236
321
  /**
@@ -243,7 +328,7 @@ class IgnoredPaths {
243
328
 
244
329
  let result = false;
245
330
  const absolutePath = path.resolve(this.options.cwd, filepath);
246
- const relativePath = pathUtil.getRelativePath(absolutePath, this.baseDir);
331
+ const relativePath = pathUtils.getRelativePath(absolutePath, this.getBaseDir());
247
332
 
248
333
  if (typeof category === "undefined") {
249
334
  result = (this.ig.default.filter([relativePath]).length === 0) ||
@@ -251,6 +336,9 @@ class IgnoredPaths {
251
336
  } else {
252
337
  result = (this.ig[category].filter([relativePath]).length === 0);
253
338
  }
339
+ debug("contains:");
340
+ debug(" target = %j", filepath);
341
+ debug(" result = %j", result);
254
342
 
255
343
  return result;
256
344
 
@@ -261,13 +349,15 @@ class IgnoredPaths {
261
349
  * @returns {function()} method to check whether a folder should be ignored by glob.
262
350
  */
263
351
  getIgnoredFoldersGlobChecker() {
352
+ const baseDir = this.getBaseDir();
353
+ const ig = ignore();
264
354
 
265
- const ig = ignore().add(DEFAULT_IGNORE_DIRS);
355
+ DEFAULT_IGNORE_DIRS.forEach(ignoreDir => this.addPatternRelativeToCwd(ig, ignoreDir));
266
356
 
267
357
  if (this.options.dotfiles !== true) {
268
358
 
269
359
  // Ignore hidden folders. (This cannot be ".*", or else it's not possible to unignore hidden files)
270
- ig.add([".*/*", "!../"]);
360
+ ig.add([".*/*", "!../*"]);
271
361
  }
272
362
 
273
363
  if (this.options.ignore) {
@@ -276,10 +366,8 @@ class IgnoredPaths {
276
366
 
277
367
  const filter = ig.createFilter();
278
368
 
279
- const base = this.baseDir;
280
-
281
369
  return function(absolutePath) {
282
- const relative = pathUtil.getRelativePath(absolutePath, base);
370
+ const relative = pathUtils.getRelativePath(absolutePath, baseDir);
283
371
 
284
372
  if (!relative) {
285
373
  return false;
package/lib/linter.js CHANGED
@@ -24,8 +24,8 @@ const eslintScope = require("eslint-scope"),
24
24
  Traverser = require("./util/traverser"),
25
25
  createReportTranslator = require("./report-translator"),
26
26
  Rules = require("./rules"),
27
- timing = require("./timing"),
28
- astUtils = require("./ast-utils"),
27
+ timing = require("./util/timing"),
28
+ astUtils = require("./util/ast-utils"),
29
29
  pkg = require("../package.json"),
30
30
  SourceCodeFixer = require("./util/source-code-fixer");
31
31
 
@@ -465,11 +465,10 @@ function resolveParserOptions(parserName, providedOptions, enabledEnvironments)
465
465
  * @returns {Object} The resolved globals object
466
466
  */
467
467
  function resolveGlobals(providedGlobals, enabledEnvironments) {
468
- return Object.assign.apply(
469
- null,
470
- [{}]
471
- .concat(enabledEnvironments.filter(env => env.globals).map(env => env.globals))
472
- .concat(providedGlobals)
468
+ return Object.assign(
469
+ {},
470
+ ...enabledEnvironments.filter(env => env.globals).map(env => env.globals),
471
+ providedGlobals
473
472
  );
474
473
  }
475
474
 
@@ -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
@@ -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
@@ -11,7 +11,7 @@
11
11
 
12
12
  const lodash = require("lodash");
13
13
 
14
- const astUtils = require("../ast-utils");
14
+ const astUtils = require("../util/ast-utils");
15
15
 
16
16
  //------------------------------------------------------------------------------
17
17
  // Helpers
@@ -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
@@ -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
@@ -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
 
6
6
  "use strict";
7
7
 
8
- const util = require("../ast-utils");
8
+ const util = require("../util/ast-utils");
9
9
 
10
10
  //------------------------------------------------------------------------------
11
11
  // 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
  // Rule Definition
@@ -145,7 +145,7 @@ module.exports = {
145
145
  const assignmentKeyEqualsValue = node.parent.key.name === node.parent.value.name;
146
146
 
147
147
  // prevent checking righthand side of destructured object
148
- if (!assignmentKeyEqualsValue && node.parent.key === node) {
148
+ if (node.parent.key === node && node.parent.value !== node) {
149
149
  return;
150
150
  }
151
151
 
@@ -9,7 +9,7 @@
9
9
  //------------------------------------------------------------------------------
10
10
 
11
11
  const LETTER_PATTERN = require("../util/patterns/letters");
12
- const astUtils = require("../ast-utils");
12
+ const astUtils = require("../util/ast-utils");
13
13
 
14
14
  //------------------------------------------------------------------------------
15
15
  // Helpers
@@ -10,7 +10,7 @@
10
10
  //------------------------------------------------------------------------------
11
11
 
12
12
  const lodash = require("lodash");
13
- const astUtils = require("../ast-utils");
13
+ const astUtils = require("../util/ast-utils");
14
14
 
15
15
  //------------------------------------------------------------------------------
16
16
  // Helpers
@@ -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
  // Rule Definition
@@ -58,7 +58,7 @@ module.exports = {
58
58
  NewExpression: true
59
59
  };
60
60
 
61
- if (context.options.length === 2 && context.options[1].hasOwnProperty("exceptions")) {
61
+ if (context.options.length === 2 && Object.prototype.hasOwnProperty.call(context.options[1], "exceptions")) {
62
62
  const keys = Object.keys(context.options[1].exceptions);
63
63
 
64
64
  for (let i = 0; i < keys.length; i++) {
@@ -12,7 +12,7 @@
12
12
 
13
13
  const lodash = require("lodash");
14
14
 
15
- const astUtils = require("../ast-utils");
15
+ const astUtils = require("../util/ast-utils");
16
16
 
17
17
  //------------------------------------------------------------------------------
18
18
  // Rule Definition
@@ -61,10 +61,10 @@ module.exports = {
61
61
  const option = context.options[0];
62
62
  let THRESHOLD = 20;
63
63
 
64
- if (typeof option === "object" && option.hasOwnProperty("maximum") && typeof option.maximum === "number") {
64
+ if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "maximum") && typeof option.maximum === "number") {
65
65
  THRESHOLD = option.maximum;
66
66
  }
67
- if (typeof option === "object" && option.hasOwnProperty("max") && typeof option.max === "number") {
67
+ if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "max") && typeof option.max === "number") {
68
68
  THRESHOLD = option.max;
69
69
  }
70
70
  if (typeof option === "number") {
@@ -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
@@ -10,7 +10,7 @@
10
10
 
11
11
  const lodash = require("lodash");
12
12
 
13
- const astUtils = require("../ast-utils");
13
+ const astUtils = require("../util/ast-utils");
14
14
 
15
15
  //------------------------------------------------------------------------------
16
16
  // Helpers
@@ -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
 
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
@@ -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
@@ -18,7 +18,10 @@ module.exports = {
18
18
  url: "https://eslint.org/docs/rules/for-direction"
19
19
  },
20
20
  fixable: null,
21
- schema: []
21
+ schema: [],
22
+ messages: {
23
+ incorrectDirection: "The update clause in this loop moves the variable in the wrong direction."
24
+ }
22
25
  },
23
26
 
24
27
  create(context) {
@@ -31,7 +34,7 @@ module.exports = {
31
34
  function report(node) {
32
35
  context.report({
33
36
  node,
34
- message: "The update clause in this loop moves the variable in the wrong direction."
37
+ messageId: "incorrectDirection"
35
38
  });
36
39
  }
37
40
 
@@ -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
@@ -57,6 +57,10 @@ module.exports = {
57
57
  maxItems: 2
58
58
  }
59
59
  ]
60
+ },
61
+ messages: {
62
+ unexpected: "Unexpected newline between function name and paren.",
63
+ missing: "Missing space between function name and paren."
60
64
  }
61
65
  },
62
66
 
@@ -116,7 +120,7 @@ module.exports = {
116
120
  context.report({
117
121
  node,
118
122
  loc: lastCalleeToken.loc.start,
119
- message: "Unexpected space between function name and paren.",
123
+ messageId: "unexpected",
120
124
  fix(fixer) {
121
125
 
122
126
  /*
@@ -134,7 +138,7 @@ module.exports = {
134
138
  context.report({
135
139
  node,
136
140
  loc: lastCalleeToken.loc.start,
137
- message: "Missing space between function name and paren.",
141
+ messageId: "missing",
138
142
  fix(fixer) {
139
143
  return fixer.insertTextBefore(parenToken, " ");
140
144
  }
@@ -143,7 +147,7 @@ module.exports = {
143
147
  context.report({
144
148
  node,
145
149
  loc: lastCalleeToken.loc.start,
146
- message: "Unexpected newline between function name and paren.",
150
+ messageId: "unexpected",
147
151
  fix(fixer) {
148
152
  return fixer.replaceTextRange([prevToken.range[1], parenToken.range[0]], " ");
149
153
  }
@@ -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
  const esutils = require("esutils");
14
14
 
15
15
  //--------------------------------------------------------------------------
@@ -87,6 +87,12 @@ module.exports = {
87
87
  additionalItems: false,
88
88
  items: [optionsObject]
89
89
  }]
90
+ },
91
+ messages: {
92
+ matchProperty: "Function name `{{funcName}}` should match property name `{{name}}`",
93
+ matchVariable: "Function name `{{funcName}}` should match variable name `{{name}}`",
94
+ notMatchProperty: "Function name `{{funcName}}` should not match property name `{{name}}`",
95
+ notMatchVariable: "Function name `{{funcName}}` should not match variable name `{{name}}`"
90
96
  }
91
97
  },
92
98
 
@@ -132,20 +138,20 @@ module.exports = {
132
138
  * @returns {void}
133
139
  */
134
140
  function report(node, name, funcName, isProp) {
135
- let message;
141
+ let messageId;
136
142
 
137
143
  if (nameMatches === "always" && isProp) {
138
- message = "Function name `{{funcName}}` should match property name `{{name}}`";
144
+ messageId = "matchProperty";
139
145
  } else if (nameMatches === "always") {
140
- message = "Function name `{{funcName}}` should match variable name `{{name}}`";
146
+ messageId = "matchVariable";
141
147
  } else if (isProp) {
142
- message = "Function name `{{funcName}}` should not match property name `{{name}}`";
148
+ messageId = "notMatchProperty";
143
149
  } else {
144
- message = "Function name `{{funcName}}` should not match variable name `{{name}}`";
150
+ messageId = "notMatchVariable";
145
151
  }
146
152
  context.report({
147
153
  node,
148
- message,
154
+ messageId,
149
155
  data: {
150
156
  name,
151
157
  funcName