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
package/CHANGELOG.md CHANGED
@@ -1,3 +1,75 @@
1
+ v5.5.0 - August 31, 2018
2
+
3
+ * 6e110e6 Fix: camelcase duplicate warning bug (fixes #10801) (#10802) (Julian Rosse)
4
+ * 5103ee7 Docs: Add Brackets integration (#10813) (Jan Pilzer)
5
+ * b61d2cd Update: max-params to only highlight function header (#10815) (Ian Obermiller)
6
+ * 2b2f11d Upgrade: babel-code-frame to version 7 (#10808) (Rouven Weßling)
7
+ * 2824d43 Docs: fix comment placement in a code example (#10799) (Vse Mozhet Byt)
8
+ * 10690b7 Upgrade: devdeps and deps to latest (#10622) (薛定谔的猫)
9
+ * 80c8598 Docs: gitignore syntax updates (fixes #8139) (#10776) (Gustavo Santana)
10
+ * cb946af Chore: use meta.messages in some rules (1/4) (#10764) (薛定谔的猫)
11
+
12
+ v5.4.0 - August 17, 2018
13
+
14
+ * a70909f Docs: Add jscs-dev.github.io links (#10771) (Gustavo Santana)
15
+ * 034690f Fix: no-invalid-meta crashes for non Object values (fixes #10750) (#10753) (Sandeep Kumar Ranka)
16
+ * 11a462d Docs: Broken jscs.info URLs (fixes #10732) (#10770) (Gustavo Santana)
17
+ * 985567d Chore: rm unused dep string.prototype.matchall (#10756) (薛定谔的猫)
18
+ * f3d8454 Update: Improve no-extra-parens error message (#10748) (Timo Tijhof)
19
+ * 562a03f Fix: consistent-docs-url crashes if meta.docs is empty (fixes #10722) (#10749) (Sandeep Kumar Ranka)
20
+ * 6492233 Chore: enable no-prototype-builtins in codebase (fixes #10660) (#10664) (薛定谔的猫)
21
+ * 137140f Chore: use eslintrc overrides (#10677) (薛定谔的猫)
22
+
23
+ v5.3.0 - August 3, 2018
24
+
25
+ * dd6cb19 Docs: Updated no-return-await Rule Documentation (fixes #9695) (#10699) (Marla Foreman)
26
+ * 6009239 Chore: rename utils for consistency (#10727) (薛定谔的猫)
27
+ * 6eb972c New: require-unicode-regexp rule (fixes #9961) (#10698) (Toru Nagashima)
28
+ * 5c5d64d Fix: ignored-paths for Windows path (fixes #10687) (#10691) (Toru Nagashima)
29
+ * 5f6a765 Build: ensure URL fragments remain in documentation links (fixes #10717) (#10720) (Teddy Katz)
30
+ * 863aa78 Docs: add another example for when not to use no-await-in-loop (#10714) (Valeri Karpov)
31
+ * 6e78b7d Docs: remove links to terminated jscs.info domain (#10706) (Piotr Kuczynski)
32
+ * d56c39d Fix: ESLint cache no longer stops autofix (fixes #10679) (#10694) (Kevin Partington)
33
+ * 2cc3240 New: add no-misleading-character-class (fixes #10049) (#10511) (Toru Nagashima)
34
+ * 877f4b8 Fix: The "../.." folder is always ignored (fixes #10675) (#10682) (Sridhar)
35
+ * 5984820 Chore: Move lib/file-finder.js to lib/util/ (refs #10559) (#10695) (Kevin Partington)
36
+ * e37a593 Update: Fix incorrect default value for position (#10670) (Iulian Onofrei)
37
+ * 8084bfc Docs: change when not to use object spread (#10621) (Benny Powers)
38
+ * 7f496e2 Chore: Update require path for ast-utils (#10693) (Kevin Partington)
39
+ * 648a33a Chore: reorganize code structure of utilities (refs #10599) (#10680) (薛定谔的猫)
40
+ * f026fe1 Update: Fix 'function' in padding-line-between-statements (fixes #10487) (#10676) (Kevin Partington)
41
+ * c2bb8bb Docs: Remove superfluous object option sample code (#10652) (Iulian Onofrei)
42
+ * d34a13b Docs: add subheader in configuring/configuring-rules (#10686) (薛定谔的猫)
43
+ * d8aea28 Chore: rm unnecessary plugin in eslint-config-eslint (#10685) (薛定谔的猫)
44
+ * 9e76be7 Update: indent comments w/ nearby code if no blank lines (fixes #9733) (#10640) (Kevin Partington)
45
+ * 9e93d46 New: add no-async-promise-executor rule (fixes #10217) (#10661) (Teddy Katz)
46
+ * 5a2538c New: require-atomic-updates rule (fixes #10405) (#10655) (Teddy Katz)
47
+ * 8b83d2b Fix: always resolve default ignore patterns from CWD (fixes #9227) (#10638) (Teddy Katz)
48
+ * acb6658 Fix: ESLint crash with prefer-object-spread (fixes #10646) (#10649) (薛定谔的猫)
49
+ * 99fb7d3 Docs: fix misleading no-prototype-builtins description (#10666) (薛定谔的猫)
50
+ * 005b849 Docs: fix outdated description of `baseConfig` option (#10657) (Teddy Katz)
51
+ * 15a77c4 Docs: fix broken links (fixes eslint/eslint-jp#6) (#10658) (Toru Nagashima)
52
+ * 87cd344 Docs: Make marking a default option consistent with other rules (#10650) (Iulian Onofrei)
53
+ * 0cb5e3e Chore: Replace some function application with spread operators (#10645) (Kevin Partington)
54
+ * b6daf0e Docs: Remove superfluous section from no-unsafe-negation (#10648) (Iulian Onofrei)
55
+ * e1a3cac Chore: rm deprecated experimentalObjectRestSpread option in tests (#10647) (薛定谔的猫)
56
+
57
+ v5.2.0 - July 20, 2018
58
+
59
+ * 81283d0 Update: Cache files that failed linting (fixes #9948) (#10571) (Kevin Partington)
60
+ * 13cc63e Upgrade: ignore@4.0.2 (#10619) (Rouven Weßling)
61
+ * ac77a80 Chore: Fixing a call to Object.assign.apply in Linter (#10629) (Kevin Partington)
62
+ * 761f802 Upgrade: eslint-plugin-node to 7.0.1 (#10612) (Toru Nagashima)
63
+ * c517b2a Build: fix npm run perf failing(fixes #10577) (#10607) (薛定谔的猫)
64
+ * e596939 Chore: fix redundant equality check (#10617) (Toru Nagashima)
65
+ * 9f93d5f Docs: Updated Working with Custom Formatters (fixes #9950) (#10592) (Marla Foreman)
66
+ * 9aaf195 Chore: Extract lint result cache logic (refs #9948) (#10562) (Kevin Partington)
67
+ * 80b296e Build: package.json update for eslint-config-eslint release (ESLint Jenkins)
68
+ * e4e7ff2 Chore: fix error message in eslint-config-eslint (#10588) (薛定谔的猫)
69
+ * 1e88170 Chore: Move lib/logging and lib/timing to lib/util/ (refs #10559) (#10579) (Kevin Partington)
70
+ * 64dfa21 Build: Fix prerelease logic in blog post generation (fixes #10578) (#10581) (Kevin Partington)
71
+ * 0faf633 Chore: Simplify helper method in Linter tests (#10580) (Kevin Partington)
72
+
1
73
  v5.1.0 - July 8, 2018
2
74
 
3
75
  * 7328f99 Build: package.json update for eslint-config-eslint release (ESLint Jenkins)
@@ -83,6 +83,7 @@ module.exports = {
83
83
  "newline-per-chained-call": "off",
84
84
  "no-alert": "off",
85
85
  "no-array-constructor": "off",
86
+ "no-async-promise-executor": "off",
86
87
  "no-await-in-loop": "off",
87
88
  "no-bitwise": "off",
88
89
  "no-buffer-constructor": "off",
@@ -139,6 +140,7 @@ module.exports = {
139
140
  "no-lonely-if": "off",
140
141
  "no-loop-func": "off",
141
142
  "no-magic-numbers": "off",
143
+ "no-misleading-character-class": "off",
142
144
  "no-mixed-operators": "off",
143
145
  "no-mixed-requires": "off",
144
146
  "no-mixed-spaces-and-tabs": "error",
@@ -240,8 +242,10 @@ module.exports = {
240
242
  "quote-props": "off",
241
243
  quotes: "off",
242
244
  radix: "off",
245
+ "require-atomic-updates": "off",
243
246
  "require-await": "off",
244
247
  "require-jsdoc": "off",
248
+ "require-unicode-regexp": "off",
245
249
  "require-yield": "error",
246
250
  "rest-spread-spacing": "off",
247
251
  semi: "off",
package/lib/cli-engine.js CHANGED
@@ -21,17 +21,15 @@ const fs = require("fs"),
21
21
  Linter = require("./linter"),
22
22
  IgnoredPaths = require("./ignored-paths"),
23
23
  Config = require("./config"),
24
- fileEntryCache = require("file-entry-cache"),
25
- globUtil = require("./util/glob-util"),
24
+ LintResultCache = require("./util/lint-result-cache"),
25
+ globUtils = require("./util/glob-utils"),
26
26
  validator = require("./config/config-validator"),
27
- stringify = require("json-stable-stringify-without-jsonify"),
28
27
  hash = require("./util/hash"),
29
28
  ModuleResolver = require("./util/module-resolver"),
30
29
  naming = require("./util/naming"),
31
30
  pkg = require("../package.json");
32
31
 
33
32
  const debug = require("debug")("eslint:cli-engine");
34
-
35
33
  const resolver = new ModuleResolver();
36
34
 
37
35
  //------------------------------------------------------------------------------
@@ -42,7 +40,7 @@ const resolver = new ModuleResolver();
42
40
  * The options to configure a CLI engine with.
43
41
  * @typedef {Object} CLIEngineOptions
44
42
  * @property {boolean} allowInlineConfig Enable or disable inline configuration comments.
45
- * @property {boolean|Object} baseConfig Base config object. True enables recommend rules and environments.
43
+ * @property {Object} baseConfig Base config object, extended by all configs used with this CLIEngine instance
46
44
  * @property {boolean} cache Enable result caching.
47
45
  * @property {string} cacheLocation The cache file to use instead of .eslintcache.
48
46
  * @property {string} configFile The configuration file to use.
@@ -359,8 +357,6 @@ function getCacheFile(cacheFile, cwd) {
359
357
  return resolvedCacheFile;
360
358
  }
361
359
 
362
- const configHashCache = new WeakMap();
363
-
364
360
  //------------------------------------------------------------------------------
365
361
  // Public Interface
366
362
  //------------------------------------------------------------------------------
@@ -403,18 +399,6 @@ class CLIEngine {
403
399
  this.options = options;
404
400
  this.linter = new Linter();
405
401
 
406
- if (options.cache) {
407
- const cacheFile = getCacheFile(this.options.cacheLocation || this.options.cacheFile, this.options.cwd);
408
-
409
- /**
410
- * Cache used to avoid operating on files that haven't changed since the
411
- * last successful execution (e.g., file passed linting with no errors and
412
- * no warnings).
413
- * @type {Object}
414
- */
415
- this._fileCache = fileEntryCache.create(cacheFile);
416
- }
417
-
418
402
  // load in additional rules
419
403
  if (this.options.rulePaths) {
420
404
  const cwd = this.options.cwd;
@@ -434,6 +418,17 @@ class CLIEngine {
434
418
  }
435
419
 
436
420
  this.config = new Config(this.options, this.linter);
421
+
422
+ if (this.options.cache) {
423
+ const cacheFile = getCacheFile(this.options.cacheLocation || this.options.cacheFile, this.options.cwd);
424
+
425
+ /**
426
+ * Cache used to avoid operating on files that haven't changed since the
427
+ * last successful execution.
428
+ * @type {Object}
429
+ */
430
+ this._lintResultCache = new LintResultCache(cacheFile, this.config);
431
+ }
437
432
  }
438
433
 
439
434
  getRules() {
@@ -473,7 +468,7 @@ class CLIEngine {
473
468
  * @returns {void}
474
469
  */
475
470
  static outputFixes(report) {
476
- report.results.filter(result => result.hasOwnProperty("output")).forEach(result => {
471
+ report.results.filter(result => Object.prototype.hasOwnProperty.call(result, "output")).forEach(result => {
477
472
  fs.writeFileSync(result.filePath, result.output);
478
473
  });
479
474
  }
@@ -496,7 +491,7 @@ class CLIEngine {
496
491
  * @returns {string[]} The equivalent glob patterns.
497
492
  */
498
493
  resolveFileGlobPatterns(patterns) {
499
- return globUtil.resolveFileGlobPatterns(patterns.filter(Boolean), this.options);
494
+ return globUtils.resolveFileGlobPatterns(patterns.filter(Boolean), this.options);
500
495
  }
501
496
 
502
497
  /**
@@ -506,7 +501,7 @@ class CLIEngine {
506
501
  */
507
502
  executeOnFiles(patterns) {
508
503
  const options = this.options,
509
- fileCache = this._fileCache,
504
+ lintResultCache = this._lintResultCache,
510
505
  configHelper = this.config;
511
506
  const cacheFile = getCacheFile(this.options.cacheLocation || this.options.cacheFile, this.options.cwd);
512
507
 
@@ -514,49 +509,26 @@ class CLIEngine {
514
509
  fs.unlinkSync(cacheFile);
515
510
  }
516
511
 
517
- /**
518
- * Calculates the hash of the config file used to validate a given file
519
- * @param {string} filename The path of the file to retrieve a config object for to calculate the hash
520
- * @returns {string} the hash of the config
521
- */
522
- function hashOfConfigFor(filename) {
523
- const config = configHelper.getConfig(filename);
524
-
525
- if (!configHashCache.has(config)) {
526
- configHashCache.set(config, hash(`${pkg.version}_${stringify(config)}`));
527
- }
528
-
529
- return configHashCache.get(config);
530
- }
531
-
532
512
  const startTime = Date.now();
533
- const fileList = globUtil.listFilesToProcess(patterns, options);
513
+ const fileList = globUtils.listFilesToProcess(patterns, options);
534
514
  const results = fileList.map(fileInfo => {
535
515
  if (fileInfo.ignored) {
536
516
  return createIgnoreResult(fileInfo.filename, options.cwd);
537
517
  }
538
518
 
539
519
  if (options.cache) {
520
+ const cachedLintResults = lintResultCache.getCachedLintResults(fileInfo.filename);
540
521
 
541
- /*
542
- * get the descriptor for this file
543
- * with the metadata and the flag that determines if
544
- * the file has changed
545
- */
546
- const descriptor = fileCache.getFileDescriptor(fileInfo.filename);
547
- const hashOfConfig = hashOfConfigFor(fileInfo.filename);
548
- const changed = descriptor.changed || descriptor.meta.hashOfConfig !== hashOfConfig;
549
-
550
- if (!changed) {
551
- debug(`Skipping file since hasn't changed: ${fileInfo.filename}`);
552
-
553
- /*
554
- * Add the the cached results (always will be 0 error and
555
- * 0 warnings). We should not cache results for files that
556
- * failed, in order to guarantee that next execution will
557
- * process those files as well.
558
- */
559
- return descriptor.meta.results;
522
+ if (cachedLintResults) {
523
+ const resultHadMessages = cachedLintResults.messages && cachedLintResults.messages.length;
524
+
525
+ if (resultHadMessages && options.fix) {
526
+ debug(`Reprocessing cached file to allow autofix: ${fileInfo.filename}`);
527
+ } else {
528
+ debug(`Skipping file since it hasn't changed: ${fileInfo.filename}`);
529
+
530
+ return cachedLintResults;
531
+ }
560
532
  }
561
533
  }
562
534
 
@@ -567,30 +539,18 @@ class CLIEngine {
567
539
 
568
540
  if (options.cache) {
569
541
  results.forEach(result => {
570
- if (result.messages.length) {
571
-
572
- /*
573
- * if a file contains errors or warnings we don't want to
574
- * store the file in the cache so we can guarantee that
575
- * next execution will also operate on this file
576
- */
577
- fileCache.removeEntry(result.filePath);
578
- } else {
579
-
580
- /*
581
- * since the file passed we store the result here
582
- * TODO: it might not be necessary to store the results list in the cache,
583
- * since it should always be 0 errors/warnings
584
- */
585
- const descriptor = fileCache.getFileDescriptor(result.filePath);
586
-
587
- descriptor.meta.hashOfConfig = hashOfConfigFor(result.filePath);
588
- descriptor.meta.results = result;
589
- }
542
+
543
+ /*
544
+ * Store the lint result in the LintResultCache.
545
+ * NOTE: The LintResultCache will remove the file source and any
546
+ * other properties that are difficult to serialize, and will
547
+ * hydrate those properties back in on future lint runs.
548
+ */
549
+ lintResultCache.setCachedLintResults(result.filePath, result);
590
550
  });
591
551
 
592
552
  // persist the cache to disk
593
- fileCache.reconcile();
553
+ lintResultCache.reconcile();
594
554
  }
595
555
 
596
556
  const stats = calculateStatsPerRun(results);
package/lib/cli.js CHANGED
@@ -20,7 +20,7 @@ const fs = require("fs"),
20
20
  options = require("./options"),
21
21
  CLIEngine = require("./cli-engine"),
22
22
  mkdirp = require("mkdirp"),
23
- log = require("./logging");
23
+ log = require("./util/logging");
24
24
 
25
25
  const debug = require("debug")("eslint:cli");
26
26
 
@@ -14,7 +14,7 @@ const assert = require("assert"),
14
14
  CodePathSegment = require("./code-path-segment"),
15
15
  IdGenerator = require("./id-generator"),
16
16
  debug = require("./debug-helpers"),
17
- astUtils = require("../ast-utils");
17
+ astUtils = require("../util/ast-utils");
18
18
 
19
19
  //------------------------------------------------------------------------------
20
20
  // Helpers
@@ -16,11 +16,11 @@ const util = require("util"),
16
16
  autoconfig = require("./autoconfig.js"),
17
17
  ConfigFile = require("./config-file"),
18
18
  ConfigOps = require("./config-ops"),
19
- getSourceCodeOfFiles = require("../util/source-code-util").getSourceCodeOfFiles,
19
+ getSourceCodeOfFiles = require("../util/source-code-utils").getSourceCodeOfFiles,
20
20
  ModuleResolver = require("../util/module-resolver"),
21
- npmUtil = require("../util/npm-util"),
21
+ npmUtils = require("../util/npm-utils"),
22
22
  recConfig = require("../../conf/eslint-recommended"),
23
- log = require("../logging");
23
+ log = require("../util/logging");
24
24
 
25
25
  const debug = require("debug")("eslint:config-initializer");
26
26
 
@@ -61,7 +61,7 @@ function writeFile(config, format) {
61
61
  /**
62
62
  * Get the peer dependencies of the given module.
63
63
  * This adds the gotten value to cache at the first time, then reuses it.
64
- * In a process, this function is called twice, but `npmUtil.fetchPeerDependencies` needs to access network which is relatively slow.
64
+ * In a process, this function is called twice, but `npmUtils.fetchPeerDependencies` needs to access network which is relatively slow.
65
65
  * @param {string} moduleName The module name to get.
66
66
  * @returns {Object} The peer dependencies of the given module.
67
67
  * This object is the object of `peerDependencies` field of `package.json`.
@@ -73,7 +73,7 @@ function getPeerDependencies(moduleName) {
73
73
  if (!result) {
74
74
  log.info(`Checking peerDependencies of ${moduleName}`);
75
75
 
76
- result = npmUtil.fetchPeerDependencies(moduleName);
76
+ result = npmUtils.fetchPeerDependencies(moduleName);
77
77
  getPeerDependencies.cache.set(moduleName, result);
78
78
  }
79
79
 
@@ -109,7 +109,7 @@ function getModulesList(config, installESLint) {
109
109
  if (installESLint === false) {
110
110
  delete modules.eslint;
111
111
  } else {
112
- const installStatus = npmUtil.checkDevDeps(["eslint"]);
112
+ const installStatus = npmUtils.checkDevDeps(["eslint"]);
113
113
 
114
114
  // Mark to show messages if it's new installation of eslint.
115
115
  if (installStatus.eslint === false) {
@@ -373,7 +373,7 @@ function hasESLintVersionConflict(answers) {
373
373
  */
374
374
  function installModules(modules) {
375
375
  log.info(`Installing ${modules.join(", ")}`);
376
- npmUtil.installSyncSaveDev(modules);
376
+ npmUtils.installSyncSaveDev(modules);
377
377
  }
378
378
 
379
379
  /* istanbul ignore next: no need to test inquirer */
@@ -438,7 +438,7 @@ function promptUser() {
438
438
  { name: "Google (https://github.com/google/eslint-config-google)", value: "google" }
439
439
  ],
440
440
  when(answers) {
441
- answers.packageJsonExists = npmUtil.checkPackageJson();
441
+ answers.packageJsonExists = npmUtils.checkPackageJson();
442
442
  return answers.source === "guide" && answers.packageJsonExists;
443
443
  }
444
444
  },
package/lib/config.js CHANGED
@@ -15,7 +15,7 @@ const path = require("path"),
15
15
  ConfigFile = require("./config/config-file"),
16
16
  ConfigCache = require("./config/config-cache"),
17
17
  Plugins = require("./config/plugins"),
18
- FileFinder = require("./file-finder"),
18
+ FileFinder = require("./util/file-finder"),
19
19
  isResolvable = require("is-resolvable");
20
20
 
21
21
  const debug = require("debug")("eslint:config");
@@ -5,7 +5,7 @@
5
5
  "use strict";
6
6
 
7
7
  const chalk = require("chalk");
8
- const codeFrame = require("babel-code-frame");
8
+ const { codeFrameColumns } = require("@babel/code-frame");
9
9
  const path = require("path");
10
10
 
11
11
  //------------------------------------------------------------------------------
@@ -63,7 +63,7 @@ function formatMessage(message, parentResult) {
63
63
 
64
64
  if (sourceCode) {
65
65
  result.push(
66
- codeFrame(sourceCode, message.line, message.column, { highlightCode: false })
66
+ codeFrameColumns(sourceCode, { start: { line: message.line, column: message.column } }, { highlightCode: false })
67
67
  );
68
68
  }
69
69