eslint 5.0.1 → 5.4.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 (179) hide show
  1. package/CHANGELOG.md +84 -0
  2. package/README.md +1 -1
  3. package/conf/eslint-recommended.js +4 -0
  4. package/lib/cli-engine.js +38 -78
  5. package/lib/cli.js +1 -1
  6. package/lib/code-path-analysis/code-path-analyzer.js +2 -2
  7. package/lib/config/config-initializer.js +8 -8
  8. package/lib/config/config-validator.js +13 -6
  9. package/lib/config.js +1 -1
  10. package/lib/formatters/stylish.js +1 -1
  11. package/lib/ignored-paths.js +125 -37
  12. package/lib/linter.js +6 -7
  13. package/lib/rules/array-bracket-newline.js +1 -1
  14. package/lib/rules/array-bracket-spacing.js +1 -1
  15. package/lib/rules/array-callback-return.js +1 -1
  16. package/lib/rules/array-element-newline.js +1 -1
  17. package/lib/rules/arrow-body-style.js +1 -1
  18. package/lib/rules/arrow-parens.js +1 -1
  19. package/lib/rules/arrow-spacing.js +1 -1
  20. package/lib/rules/block-spacing.js +1 -1
  21. package/lib/rules/brace-style.js +1 -1
  22. package/lib/rules/capitalized-comments.js +1 -1
  23. package/lib/rules/comma-dangle.js +1 -1
  24. package/lib/rules/comma-spacing.js +1 -1
  25. package/lib/rules/comma-style.js +2 -2
  26. package/lib/rules/complexity.js +3 -3
  27. package/lib/rules/computed-property-spacing.js +1 -1
  28. package/lib/rules/consistent-return.js +1 -1
  29. package/lib/rules/curly.js +1 -1
  30. package/lib/rules/dot-location.js +1 -1
  31. package/lib/rules/dot-notation.js +1 -1
  32. package/lib/rules/eqeqeq.js +1 -1
  33. package/lib/rules/func-call-spacing.js +1 -1
  34. package/lib/rules/func-name-matching.js +1 -1
  35. package/lib/rules/func-names.js +1 -1
  36. package/lib/rules/function-paren-newline.js +1 -1
  37. package/lib/rules/getter-return.js +1 -1
  38. package/lib/rules/indent-legacy.js +1 -1
  39. package/lib/rules/indent.js +43 -7
  40. package/lib/rules/jsx-quotes.js +1 -1
  41. package/lib/rules/key-spacing.js +2 -2
  42. package/lib/rules/keyword-spacing.js +1 -1
  43. package/lib/rules/line-comment-position.js +3 -3
  44. package/lib/rules/linebreak-style.js +1 -1
  45. package/lib/rules/lines-around-comment.js +1 -1
  46. package/lib/rules/lines-around-directive.js +1 -1
  47. package/lib/rules/lines-between-class-members.js +1 -1
  48. package/lib/rules/max-depth.js +2 -2
  49. package/lib/rules/max-len.js +1 -1
  50. package/lib/rules/max-lines-per-function.js +1 -1
  51. package/lib/rules/max-lines.js +2 -2
  52. package/lib/rules/max-nested-callbacks.js +2 -2
  53. package/lib/rules/max-params.js +3 -3
  54. package/lib/rules/max-statements-per-line.js +1 -1
  55. package/lib/rules/max-statements.js +3 -3
  56. package/lib/rules/multiline-comment-style.js +1 -1
  57. package/lib/rules/multiline-ternary.js +1 -1
  58. package/lib/rules/new-parens.js +1 -1
  59. package/lib/rules/newline-after-var.js +1 -1
  60. package/lib/rules/newline-per-chained-call.js +1 -1
  61. package/lib/rules/no-alert.js +1 -1
  62. package/lib/rules/no-async-promise-executor.js +33 -0
  63. package/lib/rules/no-catch-shadow.js +5 -2
  64. package/lib/rules/no-class-assign.js +1 -1
  65. package/lib/rules/no-cond-assign.js +1 -1
  66. package/lib/rules/no-confusing-arrow.js +1 -1
  67. package/lib/rules/no-console.js +1 -1
  68. package/lib/rules/no-const-assign.js +1 -1
  69. package/lib/rules/no-debugger.js +2 -10
  70. package/lib/rules/no-dupe-keys.js +1 -1
  71. package/lib/rules/no-else-return.js +1 -1
  72. package/lib/rules/no-empty-function.js +1 -1
  73. package/lib/rules/no-empty.js +1 -1
  74. package/lib/rules/no-eval.js +1 -1
  75. package/lib/rules/no-ex-assign.js +1 -1
  76. package/lib/rules/no-extend-native.js +1 -1
  77. package/lib/rules/no-extra-bind.js +1 -1
  78. package/lib/rules/no-extra-boolean-cast.js +1 -1
  79. package/lib/rules/no-extra-label.js +1 -1
  80. package/lib/rules/no-extra-parens.js +2 -2
  81. package/lib/rules/no-extra-semi.js +1 -1
  82. package/lib/rules/no-floating-decimal.js +1 -1
  83. package/lib/rules/no-func-assign.js +1 -1
  84. package/lib/rules/no-implicit-coercion.js +1 -1
  85. package/lib/rules/no-inline-comments.js +1 -1
  86. package/lib/rules/no-invalid-this.js +1 -1
  87. package/lib/rules/no-irregular-whitespace.js +1 -1
  88. package/lib/rules/no-label-var.js +1 -1
  89. package/lib/rules/no-labels.js +1 -1
  90. package/lib/rules/no-misleading-character-class.js +189 -0
  91. package/lib/rules/no-mixed-operators.js +1 -1
  92. package/lib/rules/no-multi-spaces.js +1 -1
  93. package/lib/rules/no-multi-str.js +1 -1
  94. package/lib/rules/no-regex-spaces.js +1 -1
  95. package/lib/rules/no-restricted-globals.js +1 -1
  96. package/lib/rules/no-restricted-imports.js +1 -1
  97. package/lib/rules/no-restricted-modules.js +1 -1
  98. package/lib/rules/no-restricted-properties.js +1 -1
  99. package/lib/rules/no-return-assign.js +1 -1
  100. package/lib/rules/no-return-await.js +1 -1
  101. package/lib/rules/no-self-assign.js +1 -1
  102. package/lib/rules/no-sequences.js +1 -1
  103. package/lib/rules/no-shadow.js +1 -1
  104. package/lib/rules/no-this-before-super.js +1 -1
  105. package/lib/rules/no-throw-literal.js +1 -1
  106. package/lib/rules/no-trailing-spaces.js +1 -1
  107. package/lib/rules/no-undef-init.js +1 -1
  108. package/lib/rules/no-unexpected-multiline.js +1 -1
  109. package/lib/rules/no-unmodified-loop-condition.js +2 -3
  110. package/lib/rules/no-unneeded-ternary.js +1 -1
  111. package/lib/rules/no-unsafe-negation.js +1 -1
  112. package/lib/rules/no-unused-vars.js +1 -1
  113. package/lib/rules/no-useless-call.js +1 -1
  114. package/lib/rules/no-useless-computed-key.js +1 -1
  115. package/lib/rules/no-useless-concat.js +1 -1
  116. package/lib/rules/no-useless-escape.js +1 -1
  117. package/lib/rules/no-useless-return.js +2 -11
  118. package/lib/rules/no-var.js +1 -1
  119. package/lib/rules/no-warning-comments.js +1 -1
  120. package/lib/rules/no-whitespace-before-property.js +1 -1
  121. package/lib/rules/object-curly-newline.js +1 -1
  122. package/lib/rules/object-curly-spacing.js +1 -1
  123. package/lib/rules/object-shorthand.js +1 -1
  124. package/lib/rules/one-var.js +6 -6
  125. package/lib/rules/operator-assignment.js +1 -1
  126. package/lib/rules/operator-linebreak.js +1 -1
  127. package/lib/rules/padded-blocks.js +6 -6
  128. package/lib/rules/padding-line-between-statements.js +2 -2
  129. package/lib/rules/prefer-const.js +3 -12
  130. package/lib/rules/prefer-object-spread.js +154 -197
  131. package/lib/rules/prefer-promise-reject-errors.js +1 -1
  132. package/lib/rules/prefer-reflect.js +1 -1
  133. package/lib/rules/prefer-spread.js +1 -1
  134. package/lib/rules/prefer-template.js +1 -1
  135. package/lib/rules/quotes.js +1 -1
  136. package/lib/rules/radix.js +1 -1
  137. package/lib/rules/require-atomic-updates.js +239 -0
  138. package/lib/rules/require-await.js +1 -1
  139. package/lib/rules/require-unicode-regexp.js +65 -0
  140. package/lib/rules/semi-spacing.js +3 -3
  141. package/lib/rules/semi-style.js +1 -1
  142. package/lib/rules/semi.js +1 -1
  143. package/lib/rules/sort-keys.js +2 -2
  144. package/lib/rules/space-before-blocks.js +1 -1
  145. package/lib/rules/space-before-function-paren.js +1 -1
  146. package/lib/rules/space-in-parens.js +1 -1
  147. package/lib/rules/space-unary-ops.js +2 -2
  148. package/lib/rules/spaced-comment.js +1 -1
  149. package/lib/rules/strict.js +1 -1
  150. package/lib/rules/switch-colon-spacing.js +1 -1
  151. package/lib/rules/symbol-description.js +1 -1
  152. package/lib/rules/template-curly-spacing.js +1 -1
  153. package/lib/rules/valid-jsdoc.js +1 -1
  154. package/lib/rules/wrap-iife.js +1 -1
  155. package/lib/rules/wrap-regex.js +8 -4
  156. package/lib/rules/yoda.js +1 -1
  157. package/lib/testers/rule-tester.js +8 -10
  158. package/lib/token-store/index.js +1 -1
  159. package/lib/{ast-utils.js → util/ast-utils.js} +0 -0
  160. package/lib/{file-finder.js → util/file-finder.js} +2 -2
  161. package/lib/util/fix-tracker.js +1 -1
  162. package/lib/util/{glob-util.js → glob-utils.js} +4 -4
  163. package/lib/util/lint-result-cache.js +146 -0
  164. package/lib/{logging.js → util/logging.js} +0 -0
  165. package/lib/util/naming.js +2 -2
  166. package/lib/util/node-event-generator.js +3 -3
  167. package/lib/util/{npm-util.js → npm-utils.js} +1 -1
  168. package/lib/util/{path-util.js → path-utils.js} +1 -1
  169. package/lib/util/source-code-fixer.js +1 -1
  170. package/lib/util/{source-code-util.js → source-code-utils.js} +3 -3
  171. package/lib/util/source-code.js +1 -1
  172. package/lib/{timing.js → util/timing.js} +0 -0
  173. package/lib/util/unicode/index.js +11 -0
  174. package/lib/util/unicode/is-combining-character.js +13 -0
  175. package/lib/util/unicode/is-emoji-modifier.js +13 -0
  176. package/lib/util/unicode/is-regional-indicator-symbol.js +13 -0
  177. package/lib/util/unicode/is-surrogate-pair.js +14 -0
  178. package/package.json +6 -6
  179. package/lib/rules/.eslintrc.yml +0 -4
package/CHANGELOG.md CHANGED
@@ -1,3 +1,87 @@
1
+ v5.4.0 - August 17, 2018
2
+
3
+ * a70909f Docs: Add jscs-dev.github.io links (#10771) (Gustavo Santana)
4
+ * 034690f Fix: no-invalid-meta crashes for non Object values (fixes #10750) (#10753) (Sandeep Kumar Ranka)
5
+ * 11a462d Docs: Broken jscs.info URLs (fixes #10732) (#10770) (Gustavo Santana)
6
+ * 985567d Chore: rm unused dep string.prototype.matchall (#10756) (薛定谔的猫)
7
+ * f3d8454 Update: Improve no-extra-parens error message (#10748) (Timo Tijhof)
8
+ * 562a03f Fix: consistent-docs-url crashes if meta.docs is empty (fixes #10722) (#10749) (Sandeep Kumar Ranka)
9
+ * 6492233 Chore: enable no-prototype-builtins in codebase (fixes #10660) (#10664) (薛定谔的猫)
10
+ * 137140f Chore: use eslintrc overrides (#10677) (薛定谔的猫)
11
+
12
+ v5.3.0 - August 3, 2018
13
+
14
+ * dd6cb19 Docs: Updated no-return-await Rule Documentation (fixes #9695) (#10699) (Marla Foreman)
15
+ * 6009239 Chore: rename utils for consistency (#10727) (薛定谔的猫)
16
+ * 6eb972c New: require-unicode-regexp rule (fixes #9961) (#10698) (Toru Nagashima)
17
+ * 5c5d64d Fix: ignored-paths for Windows path (fixes #10687) (#10691) (Toru Nagashima)
18
+ * 5f6a765 Build: ensure URL fragments remain in documentation links (fixes #10717) (#10720) (Teddy Katz)
19
+ * 863aa78 Docs: add another example for when not to use no-await-in-loop (#10714) (Valeri Karpov)
20
+ * 6e78b7d Docs: remove links to terminated jscs.info domain (#10706) (Piotr Kuczynski)
21
+ * d56c39d Fix: ESLint cache no longer stops autofix (fixes #10679) (#10694) (Kevin Partington)
22
+ * 2cc3240 New: add no-misleading-character-class (fixes #10049) (#10511) (Toru Nagashima)
23
+ * 877f4b8 Fix: The "../.." folder is always ignored (fixes #10675) (#10682) (Sridhar)
24
+ * 5984820 Chore: Move lib/file-finder.js to lib/util/ (refs #10559) (#10695) (Kevin Partington)
25
+ * e37a593 Update: Fix incorrect default value for position (#10670) (Iulian Onofrei)
26
+ * 8084bfc Docs: change when not to use object spread (#10621) (Benny Powers)
27
+ * 7f496e2 Chore: Update require path for ast-utils (#10693) (Kevin Partington)
28
+ * 648a33a Chore: reorganize code structure of utilities (refs #10599) (#10680) (薛定谔的猫)
29
+ * f026fe1 Update: Fix 'function' in padding-line-between-statements (fixes #10487) (#10676) (Kevin Partington)
30
+ * c2bb8bb Docs: Remove superfluous object option sample code (#10652) (Iulian Onofrei)
31
+ * d34a13b Docs: add subheader in configuring/configuring-rules (#10686) (薛定谔的猫)
32
+ * d8aea28 Chore: rm unnecessary plugin in eslint-config-eslint (#10685) (薛定谔的猫)
33
+ * 9e76be7 Update: indent comments w/ nearby code if no blank lines (fixes #9733) (#10640) (Kevin Partington)
34
+ * 9e93d46 New: add no-async-promise-executor rule (fixes #10217) (#10661) (Teddy Katz)
35
+ * 5a2538c New: require-atomic-updates rule (fixes #10405) (#10655) (Teddy Katz)
36
+ * 8b83d2b Fix: always resolve default ignore patterns from CWD (fixes #9227) (#10638) (Teddy Katz)
37
+ * acb6658 Fix: ESLint crash with prefer-object-spread (fixes #10646) (#10649) (薛定谔的猫)
38
+ * 99fb7d3 Docs: fix misleading no-prototype-builtins description (#10666) (薛定谔的猫)
39
+ * 005b849 Docs: fix outdated description of `baseConfig` option (#10657) (Teddy Katz)
40
+ * 15a77c4 Docs: fix broken links (fixes eslint/eslint-jp#6) (#10658) (Toru Nagashima)
41
+ * 87cd344 Docs: Make marking a default option consistent with other rules (#10650) (Iulian Onofrei)
42
+ * 0cb5e3e Chore: Replace some function application with spread operators (#10645) (Kevin Partington)
43
+ * b6daf0e Docs: Remove superfluous section from no-unsafe-negation (#10648) (Iulian Onofrei)
44
+ * e1a3cac Chore: rm deprecated experimentalObjectRestSpread option in tests (#10647) (薛定谔的猫)
45
+
46
+ v5.2.0 - July 20, 2018
47
+
48
+ * 81283d0 Update: Cache files that failed linting (fixes #9948) (#10571) (Kevin Partington)
49
+ * 13cc63e Upgrade: ignore@4.0.2 (#10619) (Rouven Weßling)
50
+ * ac77a80 Chore: Fixing a call to Object.assign.apply in Linter (#10629) (Kevin Partington)
51
+ * 761f802 Upgrade: eslint-plugin-node to 7.0.1 (#10612) (Toru Nagashima)
52
+ * c517b2a Build: fix npm run perf failing(fixes #10577) (#10607) (薛定谔的猫)
53
+ * e596939 Chore: fix redundant equality check (#10617) (Toru Nagashima)
54
+ * 9f93d5f Docs: Updated Working with Custom Formatters (fixes #9950) (#10592) (Marla Foreman)
55
+ * 9aaf195 Chore: Extract lint result cache logic (refs #9948) (#10562) (Kevin Partington)
56
+ * 80b296e Build: package.json update for eslint-config-eslint release (ESLint Jenkins)
57
+ * e4e7ff2 Chore: fix error message in eslint-config-eslint (#10588) (薛定谔的猫)
58
+ * 1e88170 Chore: Move lib/logging and lib/timing to lib/util/ (refs #10559) (#10579) (Kevin Partington)
59
+ * 64dfa21 Build: Fix prerelease logic in blog post generation (fixes #10578) (#10581) (Kevin Partington)
60
+ * 0faf633 Chore: Simplify helper method in Linter tests (#10580) (Kevin Partington)
61
+
62
+ v5.1.0 - July 8, 2018
63
+
64
+ * 7328f99 Build: package.json update for eslint-config-eslint release (ESLint Jenkins)
65
+ * b161f6b Build: Include prerelease install info in release blog post (#10463) (Kevin Partington)
66
+ * b2df738 Fix: prefer-object-spread duplicated comma (fixes #10512, fixes #10532) (#10524) (Toru Nagashima)
67
+ * d8c3a25 Fix: wrap-regex doesn't work in some expression(fixes #10573) (#10576) (薛定谔的猫)
68
+ * 114f42e Docs: Clarify option defaults in max-lines-per-function docs (#10569) (Chris Harwood)
69
+ * 63f36f7 Fix: sort-keys in an object that contains spread (fixes #10261) (#10495) (katerberg)
70
+ * 601a5c4 Fix: Prefer-const rule crashing on array destructuring (fixes #10520) (#10527) (Michael Mason)
71
+ * 143890a Update: Adjust grammar of error/warnings fixable (#10546) (Matt Mischuk)
72
+ * 8ee39c5 Chore: small refactor config-validator (#10565) (薛定谔的猫)
73
+ * 100f1be Docs: add note about release issues to readme (#10572) (Teddy Katz)
74
+ * 02efeac Fix: do not fail on nested unknown operators (#10561) (Rubén Norte)
75
+ * 92b19ca Chore: use eslintrc overrides(dogfooding) (#10566) (薛定谔的猫)
76
+ * 076a6b6 Docs: add actionable fix to no-irregular-whitespace (#10558) (Matteo Collina)
77
+ * de663ec Docs: Only successfully linted files are cached (fixes #9802) (#10557) (Kevin Partington)
78
+ * f0e22fc Upgrade: globals@11.7.0 (#10497) (薛定谔的猫)
79
+ * 8a2ff2c Docs: adding a section about disable rules for some files (#10536) (Wellington Soares)
80
+ * f22a3f8 Docs: fix a word in no-implied-eval (#10539) (Dan Homola)
81
+ * 20d8bbd Docs: add missing paragraph about "custom parsers" (#10547) (Pig Fang)
82
+ * b7addf6 Update: deprecate no-catch-shadow (fixes #10466) (#10526) (Toru Nagashima)
83
+ * e862dc3 Fix: Remove autofixer for no-debugger (fixes #10242) (#10509) (Teddy Katz)
84
+
1
85
  v5.0.1 - June 25, 2018
2
86
 
3
87
  * 196c102 Fix: valid-jsdoc should allow optional returns for async (fixes #10386) (#10480) (Mark Banner)
package/README.md CHANGED
@@ -157,7 +157,7 @@ Join our [Mailing List](https://groups.google.com/group/eslint) or [Chatroom](ht
157
157
 
158
158
  ## Releases
159
159
 
160
- We have scheduled releases every two weeks on Friday or Saturday.
160
+ We have scheduled releases every two weeks on Friday or Saturday. You can follow a [release issue](https://github.com/eslint/eslint/issues?q=is%3Aopen+is%3Aissue+label%3Arelease) for updates about the scheduling of any particular release.
161
161
 
162
162
  ## Semantic Versioning Policy
163
163
 
@@ -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
@@ -60,7 +60,7 @@ function isForkingByTrueOrFalse(node) {
60
60
  return parent.test === node;
61
61
 
62
62
  case "LogicalExpression":
63
- return true;
63
+ return isHandledLogicalOperator(parent.operator);
64
64
 
65
65
  default:
66
66
  return false;
@@ -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
  },
@@ -23,10 +23,15 @@ const ruleValidators = new WeakMap();
23
23
  let validateSchema;
24
24
 
25
25
  // Defitions for deprecation warnings.
26
- const deprecationWarningMessages = Object.freeze({
26
+ const deprecationWarningMessages = {
27
27
  ESLINT_LEGACY_ECMAFEATURES: "The 'ecmaFeatures' config file property is deprecated, and has no effect.",
28
28
  ESLINT_LEGACY_OBJECT_REST_SPREAD: "The 'parserOptions.ecmaFeatures.experimentalObjectRestSpread' option is deprecated. Use 'parserOptions.ecmaVersion' instead."
29
- });
29
+ };
30
+ const severityMap = {
31
+ error: 2,
32
+ warn: 1,
33
+ off: 0
34
+ };
30
35
 
31
36
  /**
32
37
  * Gets a complete options schema for a rule.
@@ -65,12 +70,14 @@ function getRuleOptionsSchema(rule) {
65
70
  */
66
71
  function validateRuleSeverity(options) {
67
72
  const severity = Array.isArray(options) ? options[0] : options;
73
+ const normSeverity = typeof severity === "string" ? severityMap[severity.toLowerCase()] : severity;
68
74
 
69
- if (severity !== 0 && severity !== 1 && severity !== 2 && !(typeof severity === "string" && /^(?:off|warn|error)$/i.test(severity))) {
70
- throw new Error(`\tSeverity should be one of the following: 0 = off, 1 = warn, 2 = error (you passed '${util.inspect(severity).replace(/'/g, "\"").replace(/\n/g, "")}').\n`);
75
+ if (normSeverity === 0 || normSeverity === 1 || normSeverity === 2) {
76
+ return normSeverity;
71
77
  }
72
78
 
73
- return severity;
79
+ throw new Error(`\tSeverity should be one of the following: 0 = off, 1 = warn, 2 = error (you passed '${util.inspect(severity).replace(/'/g, "\"").replace(/\n/g, "")}').\n`);
80
+
74
81
  }
75
82
 
76
83
  /**
@@ -116,7 +123,7 @@ function validateRuleOptions(rule, ruleId, options, source) {
116
123
  try {
117
124
  const severity = validateRuleSeverity(options);
118
125
 
119
- if (severity !== 0 && !(typeof severity === "string" && severity.toLowerCase() === "off")) {
126
+ if (severity !== 0) {
120
127
  validateRuleSchema(rule, Array.isArray(options) ? options.slice(1) : []);
121
128
  }
122
129
  } catch (err) {
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");
@@ -89,7 +89,7 @@ module.exports = function(results) {
89
89
 
90
90
  if (fixableErrorCount > 0 || fixableWarningCount > 0) {
91
91
  output += chalk[summaryColor].bold([
92
- " ", fixableErrorCount, pluralize(" error", fixableErrorCount), ", ",
92
+ " ", fixableErrorCount, pluralize(" error", fixableErrorCount), " and ",
93
93
  fixableWarningCount, pluralize(" warning", fixableWarningCount),
94
94
  " potentially fixable with the `--fix` option.\n"
95
95
  ].join(""));