eslint 7.23.0 → 7.27.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 (62) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/README.md +7 -2
  3. package/bin/eslint.js +2 -12
  4. package/lib/cli-engine/cli-engine.js +2 -7
  5. package/lib/cli-engine/file-enumerator.js +1 -1
  6. package/lib/cli-engine/formatters/html.js +193 -9
  7. package/lib/init/autoconfig.js +2 -2
  8. package/lib/init/config-file.js +1 -0
  9. package/lib/init/config-initializer.js +14 -1
  10. package/lib/init/npm-utils.js +1 -0
  11. package/lib/linter/apply-disable-directives.js +15 -3
  12. package/lib/linter/linter.js +9 -7
  13. package/lib/linter/node-event-generator.js +43 -6
  14. package/lib/rule-tester/rule-tester.js +14 -10
  15. package/lib/rules/comma-dangle.js +16 -7
  16. package/lib/rules/comma-spacing.js +1 -1
  17. package/lib/rules/complexity.js +2 -3
  18. package/lib/rules/consistent-return.js +2 -2
  19. package/lib/rules/eol-last.js +2 -7
  20. package/lib/rules/indent.js +8 -9
  21. package/lib/rules/max-lines-per-function.js +2 -3
  22. package/lib/rules/max-lines.js +32 -7
  23. package/lib/rules/max-params.js +2 -3
  24. package/lib/rules/max-statements.js +2 -3
  25. package/lib/rules/no-fallthrough.js +2 -8
  26. package/lib/rules/no-implicit-coercion.js +37 -0
  27. package/lib/rules/no-multi-assign.js +15 -2
  28. package/lib/rules/no-restricted-imports.js +61 -24
  29. package/lib/rules/no-unused-vars.js +53 -16
  30. package/lib/rules/no-useless-backreference.js +1 -2
  31. package/lib/rules/no-useless-computed-key.js +8 -2
  32. package/lib/rules/no-warning-comments.js +1 -1
  33. package/lib/rules/object-curly-newline.js +19 -4
  34. package/lib/rules/radix.js +19 -3
  35. package/lib/rules/require-atomic-updates.js +23 -20
  36. package/lib/rules/spaced-comment.js +2 -2
  37. package/lib/rules/utils/ast-utils.js +2 -2
  38. package/lib/shared/deprecation-warnings.js +12 -3
  39. package/lib/shared/string-utils.js +22 -0
  40. package/lib/source-code/source-code.js +6 -5
  41. package/lib/source-code/token-store/utils.js +4 -12
  42. package/messages/{all-files-ignored.txt → all-files-ignored.js} +10 -2
  43. package/messages/extend-config-missing.js +13 -0
  44. package/messages/failed-to-read-json.js +11 -0
  45. package/messages/file-not-found.js +10 -0
  46. package/messages/{no-config-found.txt → no-config-found.js} +9 -1
  47. package/messages/plugin-conflict.js +22 -0
  48. package/messages/plugin-invalid.js +16 -0
  49. package/messages/plugin-missing.js +19 -0
  50. package/messages/{print-config-with-directory-path.txt → print-config-with-directory-path.js} +6 -0
  51. package/messages/whitespace-found.js +11 -0
  52. package/package.json +10 -13
  53. package/lib/cli-engine/formatters/html-template-message.html +0 -8
  54. package/lib/cli-engine/formatters/html-template-page.html +0 -115
  55. package/lib/cli-engine/formatters/html-template-result.html +0 -6
  56. package/messages/extend-config-missing.txt +0 -5
  57. package/messages/failed-to-read-json.txt +0 -3
  58. package/messages/file-not-found.txt +0 -2
  59. package/messages/plugin-conflict.txt +0 -7
  60. package/messages/plugin-invalid.txt +0 -8
  61. package/messages/plugin-missing.txt +0 -11
  62. package/messages/whitespace-found.txt +0 -3
package/CHANGELOG.md CHANGED
@@ -1,3 +1,57 @@
1
+ v7.27.0 - May 21, 2021
2
+
3
+ * [`2c0868c`](https://github.com/eslint/eslint/commit/2c0868cbeadc9f42716fa1178ebdc6b4cee6d31e) Chore: merge all html formatter files into `html.js` (#14612) (Milos Djermanovic)
4
+ * [`9e9b5e0`](https://github.com/eslint/eslint/commit/9e9b5e07475564813b62cd1d7562a93c5fb4bc74) Update: no-unused-vars false negative with comma operator (fixes #14325) (#14354) (Nitin Kumar)
5
+ * [`afe9569`](https://github.com/eslint/eslint/commit/afe95693e1e4316a1c6f01d39345061d4c5921c7) Chore: use includes instead of indexOf (#14607) (Mikhail Bodrov)
6
+ * [`c0f418e`](https://github.com/eslint/eslint/commit/c0f418e2476df98519bc156b81d20431984e8704) Chore: Remove lodash (#14287) (Stephen Wade)
7
+ * [`52655dd`](https://github.com/eslint/eslint/commit/52655dd54925ee02af2ba3a0ebc09de959ae3101) Update: no-restricted-imports custom message for patterns (fixes #11843) (#14580) (Alex Holden)
8
+ * [`967b1c4`](https://github.com/eslint/eslint/commit/967b1c4ceca8f5248378477da94ff118dafaa647) Chore: Fix typo in large.js (#14589) (Ikko Ashimine)
9
+ * [`2466a05`](https://github.com/eslint/eslint/commit/2466a05160de60958457d984b79fd445c12ebc98) Sponsors: Sync README with website (ESLint Jenkins)
10
+ * [`fe29f18`](https://github.com/eslint/eslint/commit/fe29f18227fd02fd7c3da033417d621275b00d0a) Sponsors: Sync README with website (ESLint Jenkins)
11
+ * [`086c1d6`](https://github.com/eslint/eslint/commit/086c1d6e8593cf8e7851daa8f2a890c213cf6999) Chore: add more test cases for `no-sequences` (#14579) (Nitin Kumar)
12
+ * [`6a2ced8`](https://github.com/eslint/eslint/commit/6a2ced892c0dc43fa4942293b9f1c4b9151c3741) Docs: Update README team and sponsors (ESLint Jenkins)
13
+
14
+ v7.26.0 - May 7, 2021
15
+
16
+ * [`aaf65e6`](https://github.com/eslint/eslint/commit/aaf65e629adb74401092c3ccc9cb4e4bd1c8609b) Upgrade: eslintrc for ModuleResolver fix (#14577) (Brandon Mills)
17
+ * [`ae6dbd1`](https://github.com/eslint/eslint/commit/ae6dbd148aaca83e4bd04b9351b54029c50fac8a) Fix: track variables, not names in require-atomic-updates (fixes #14208) (#14282) (Patrick Ahmetovic)
18
+ * [`6a86e50`](https://github.com/eslint/eslint/commit/6a86e5018a3733049c09261bcabae422fbea893d) Chore: remove loose-parser tests (fixes #14315) (#14569) (Milos Djermanovic)
19
+ * [`ee3a3ea`](https://github.com/eslint/eslint/commit/ee3a3ead893d185cc4b1ae9041940cb0968767e1) Fix: create `.eslintrc.cjs` for `module` type (#14304) (Nitin Kumar)
20
+ * [`6791dec`](https://github.com/eslint/eslint/commit/6791decfc58b7b09cfd0aabd15a3d14148aae073) Docs: fix example for require-atomic-updates (#14562) (Milos Djermanovic)
21
+ * [`388eb7e`](https://github.com/eslint/eslint/commit/388eb7e14039b8951462b311d6121002ca5232cb) Sponsors: Sync README with website (ESLint Jenkins)
22
+ * [`f071d1e`](https://github.com/eslint/eslint/commit/f071d1ef91286bf2e3fb63d9b679ff7702819a1e) Update: Add automated suggestion to `radix` rule for parsing decimals (#14291) (Bryan Mishkin)
23
+ * [`0b6a3f3`](https://github.com/eslint/eslint/commit/0b6a3f31e6e78825114f82d4e0aed9cd72f784ac) New: Include XO style guide in `eslint --init` (#14193) (Federico Brigante)
24
+
25
+ v7.25.0 - April 23, 2021
26
+
27
+ * [`5df5e4a`](https://github.com/eslint/eslint/commit/5df5e4a9976964fcf4dc67e241d4e22ec1370fe0) Update: highlight last write reference for no-unused-vars (fixes #14324) (#14335) (Nitin Kumar)
28
+ * [`0023872`](https://github.com/eslint/eslint/commit/00238729329b86b4f8af89ebfe278da3095a6075) Docs: Add deprecated note to `working-with-rules-deprecated` page (#14344) (Michael Novotny)
29
+ * [`36fca70`](https://github.com/eslint/eslint/commit/36fca70fa29ab65080076810de98e09133254b8a) Chore: Upgrade eslump to 3.0.0 (#14350) (Stephen Wade)
30
+ * [`59b689a`](https://github.com/eslint/eslint/commit/59b689a0b3fa658b8380431007cc1facb4617a3b) Chore: add node v16 (#14355) (薛定谔的猫)
31
+ * [`35a1f5e`](https://github.com/eslint/eslint/commit/35a1f5e967e4e87360d3e70d3fca0f7adeeaa1d7) Sponsors: Sync README with website (ESLint Jenkins)
32
+ * [`fb0a92b`](https://github.com/eslint/eslint/commit/fb0a92b3d2fed4a17bc39b7f02c540cd1175ec7d) Chore: rename misspelled identifier in test (#14346) (Tobias Nießen)
33
+ * [`f2babb1`](https://github.com/eslint/eslint/commit/f2babb1069194166e0ac1afd1269bbd06ac299b6) Docs: update pull request template (#14336) (Nitin Kumar)
34
+ * [`02dde29`](https://github.com/eslint/eslint/commit/02dde29eeb523ca24bc4ae7797d38627c3ba9fe9) Docs: Fix anchor in 'docs/developer-guide/working-with-rules.md' (#14332) (Nate-Wilkins)
35
+ * [`07d14c3`](https://github.com/eslint/eslint/commit/07d14c304c358fbc9c3d318e1377d2b2bda9179f) Chore: remove extraneous command from lint-staged config (#14314) (James George)
36
+ * [`41b3570`](https://github.com/eslint/eslint/commit/41b3570b6c014c534bb3208ed00050fd99842101) Update: lint code block with same extension but different content (#14227) (JounQin)
37
+ * [`eb29996`](https://github.com/eslint/eslint/commit/eb299966bdc3920dd2c6f9774d95103d242fc409) Docs: add more examples with arrow functions for no-sequences rule (#14313) (Nitin Kumar)
38
+
39
+ v7.24.0 - April 9, 2021
40
+
41
+ * [`0c346c8`](https://github.com/eslint/eslint/commit/0c346c87fa83c6d1184fdafb9c0748c2e15a423d) Chore: ignore `pnpm-lock.yaml` (#14303) (Nitin Kumar)
42
+ * [`f06ecdf`](https://github.com/eslint/eslint/commit/f06ecdf78b6d6f366434d73a6acfe7041d575223) Update: Add disallowTemplateShorthand option in no-implicit-coercion (#13579) (Remco Haszing)
43
+ * [`71a80e3`](https://github.com/eslint/eslint/commit/71a80e38aab2dada01b808ed43d9b0e806d863c4) Docs: fix broken links in Node.js API docs toc (#14296) (u-sho (Shouhei Uechi))
44
+ * [`bd46dc4`](https://github.com/eslint/eslint/commit/bd46dc4647faa4c3bbb5f60d4c00616a64081398) Docs: Fix incorrect reference to "braces" in arrow-parens (#14300) (emclain)
45
+ * [`0d6235e`](https://github.com/eslint/eslint/commit/0d6235ea201b8b90761ee69bb4d46ae18899c28d) Docs: update header in max-lines (#14273) (Shinigami)
46
+ * [`70c9216`](https://github.com/eslint/eslint/commit/70c92164017238e329e3a2d1654a0227b8f953f7) Docs: Update issue triage to include blocked column (#14275) (Nicholas C. Zakas)
47
+ * [`abca186`](https://github.com/eslint/eslint/commit/abca186a845200fd7728c4e5f220973e640054f9) Docs: Fix typo in suggestions section (#14293) (Kevin Partington)
48
+ * [`c4d8b0d`](https://github.com/eslint/eslint/commit/c4d8b0db62b859e721105d4bc0f4044ce346995e) Fix: no-unused-vars ignoreRestSiblings check assignments (fixes #14163) (#14264) (YeonJuan)
49
+ * [`b51d077`](https://github.com/eslint/eslint/commit/b51d0778d76c2aa27578caca3ea82c867dced3e4) Update: add ignoreNonDeclaration to no-multi-assign rule (fixes #12545) (#14185) (t-mangoe)
50
+ * [`c981fb1`](https://github.com/eslint/eslint/commit/c981fb1994cd04914042ced1980aa86b68ba7be9) Chore: Upgrade mocha to 8.3.2 (#14278) (Stephen Wade)
51
+ * [`147fc04`](https://github.com/eslint/eslint/commit/147fc045e699811fab33dddf77498324ddf7e9d6) Docs: Fix `repro:needed` label in bug report template (#14285) (Milos Djermanovic)
52
+ * [`e1cfde9`](https://github.com/eslint/eslint/commit/e1cfde93eec71a15c2df1ad660a7a6171204ba80) Docs: Update bug report template (#14276) (Nicholas C. Zakas)
53
+ * [`c85c2f1`](https://github.com/eslint/eslint/commit/c85c2f1138a9e952655f19ee780ab0c8e35431a8) Docs: Add fatal to Node.js API LintMessage type (#14251) (Brandon Mills)
54
+
1
55
  v7.23.0 - March 26, 2021
2
56
 
3
57
  * [`687ccae`](https://github.com/eslint/eslint/commit/687ccae517b8b815cf21e948f80d22e2bf118a99) Update: add option "allowInParentheses" to no-sequences (fixes #14197) (#14199) (Daniel Rentz)
package/README.md CHANGED
@@ -240,6 +240,11 @@ Milos Djermanovic
240
240
  The people who review and implement new features.
241
241
 
242
242
  <table><tbody><tr><td align="center" valign="top" width="11%">
243
+ <a href="https://github.com/mysticatea">
244
+ <img src="https://github.com/mysticatea.png?s=75" width="75" height="75"><br />
245
+ Toru Nagashima
246
+ </a>
247
+ </td><td align="center" valign="top" width="11%">
243
248
  <a href="https://github.com/aladdin-add">
244
249
  <img src="https://github.com/aladdin-add.png?s=75" width="75" height="75"><br />
245
250
  薛定谔的猫
@@ -281,9 +286,9 @@ The following companies, organizations, and individuals support ESLint's ongoing
281
286
  <!--sponsorsstart-->
282
287
  <h3>Platinum Sponsors</h3>
283
288
  <p><a href="https://automattic.com"><img src="https://images.opencollective.com/photomatt/d0ef3e1/logo.png" alt="Automattic" height="undefined"></a></p><h3>Gold Sponsors</h3>
284
- <p><a href="https://nx.dev"><img src="https://images.opencollective.com/nx/0efbe42/logo.png" alt="Nx (by Nrwl)" height="96"></a> <a href="https://google.com/chrome"><img src="https://images.opencollective.com/chrome/dc55bd4/logo.png" alt="Chrome's Web Framework & Tools Performance Fund" height="96"></a> <a href="https://www.shopify.com"><img src="https://images.opencollective.com/shopify/e780cd4/logo.png" alt="Shopify" height="96"></a> <a href="https://www.salesforce.com"><img src="https://images.opencollective.com/salesforce/ca8f997/logo.png" alt="Salesforce" height="96"></a> <a href="https://www.airbnb.com/"><img src="https://images.opencollective.com/airbnb/d327d66/logo.png" alt="Airbnb" height="96"></a> <a href="https://opensource.microsoft.com"><img src="https://avatars.githubusercontent.com/u/6154722?v=4" alt="Microsoft" height="96"></a> <a href="https://substack.com/"><img src="https://avatars.githubusercontent.com/u/53023767?v=4" alt="Substack" height="96"></a></p><h3>Silver Sponsors</h3>
289
+ <p><a href="https://nx.dev"><img src="https://images.opencollective.com/nx/0efbe42/logo.png" alt="Nx (by Nrwl)" height="96"></a> <a href="https://google.com/chrome"><img src="https://images.opencollective.com/chrome/dc55bd4/logo.png" alt="Chrome's Web Framework & Tools Performance Fund" height="96"></a> <a href="https://www.salesforce.com"><img src="https://images.opencollective.com/salesforce/ca8f997/logo.png" alt="Salesforce" height="96"></a> <a href="https://www.airbnb.com/"><img src="https://images.opencollective.com/airbnb/d327d66/logo.png" alt="Airbnb" height="96"></a> <a href="https://substack.com/"><img src="https://avatars.githubusercontent.com/u/53023767?v=4" alt="Substack" height="96"></a></p><h3>Silver Sponsors</h3>
285
290
  <p><a href="https://retool.com/"><img src="https://images.opencollective.com/retool/98ea68e/logo.png" alt="Retool" height="64"></a> <a href="https://liftoff.io/"><img src="https://images.opencollective.com/liftoff/5c4fa84/logo.png" alt="Liftoff" height="64"></a></p><h3>Bronze Sponsors</h3>
286
- <p><a href="https://buy.fineproxy.org/eng/"><img src="https://images.opencollective.com/buy-fineproxy-org/b282e39/logo.png" alt="Buy.Fineproxy.Org" height="32"></a> <a href="https://www.crosswordsolver.org/anagram-solver/"><img src="https://images.opencollective.com/anagram-solver/2666271/logo.png" alt="Anagram Solver" height="32"></a> <a href="null"><img src="https://images.opencollective.com/bugsnag-stability-monitoring/c2cef36/logo.png" alt="Bugsnag Stability Monitoring" height="32"></a> <a href="https://mixpanel.com"><img src="https://images.opencollective.com/mixpanel/cd682f7/logo.png" alt="Mixpanel" height="32"></a> <a href="https://www.vpsserver.com"><img src="https://images.opencollective.com/vpsservercom/logo.png" alt="VPS Server" height="32"></a> <a href="https://icons8.com"><img src="https://images.opencollective.com/icons8/7fa1641/logo.png" alt="Icons8: free icons, photos, illustrations, and music" height="32"></a> <a href="https://discordapp.com"><img src="https://images.opencollective.com/discordapp/7e3d9a9/logo.png" alt="Discord" height="32"></a> <a href="https://themeisle.com"><img src="https://images.opencollective.com/themeisle/d5592fe/logo.png" alt="ThemeIsle" height="32"></a> <a href="https://www.firesticktricks.com"><img src="https://images.opencollective.com/fire-stick-tricks/b8fbe2c/logo.png" alt="Fire Stick Tricks" height="32"></a></p>
291
+ <p><a href="https://www.crosswordsolver.org/anagram-solver/"><img src="https://images.opencollective.com/anagram-solver/2666271/logo.png" alt="Anagram Solver" height="32"></a> <a href="null"><img src="https://images.opencollective.com/bugsnag-stability-monitoring/c2cef36/logo.png" alt="Bugsnag Stability Monitoring" height="32"></a> <a href="https://mixpanel.com"><img src="https://images.opencollective.com/mixpanel/cd682f7/logo.png" alt="Mixpanel" height="32"></a> <a href="https://www.vpsserver.com"><img src="https://images.opencollective.com/vpsservercom/logo.png" alt="VPS Server" height="32"></a> <a href="https://icons8.com"><img src="https://images.opencollective.com/icons8/7fa1641/logo.png" alt="Icons8: free icons, photos, illustrations, and music" height="32"></a> <a href="https://discord.com"><img src="https://images.opencollective.com/discordapp/7e3d9a9/logo.png" alt="Discord" height="32"></a> <a href="https://themeisle.com"><img src="https://images.opencollective.com/themeisle/d5592fe/logo.png" alt="ThemeIsle" height="32"></a> <a href="https://www.firesticktricks.com"><img src="https://images.opencollective.com/fire-stick-tricks/b8fbe2c/logo.png" alt="Fire Stick Tricks" height="32"></a></p>
287
292
  <!--sponsorsend-->
288
293
 
289
294
  ## <a name="technology-sponsors"></a>Technology Sponsors
package/bin/eslint.js CHANGED
@@ -66,11 +66,8 @@ function readStdin() {
66
66
  */
67
67
  function getErrorMessage(error) {
68
68
 
69
- // Lazy loading because those are used only if error happened.
70
- const fs = require("fs");
71
- const path = require("path");
69
+ // Lazy loading because this is used only if an error happened.
72
70
  const util = require("util");
73
- const lodash = require("lodash");
74
71
 
75
72
  // Foolproof -- thirdparty module might throw non-object.
76
73
  if (typeof error !== "object" || error === null) {
@@ -80,14 +77,7 @@ function getErrorMessage(error) {
80
77
  // Use templates if `error.messageTemplate` is present.
81
78
  if (typeof error.messageTemplate === "string") {
82
79
  try {
83
- const templateFilePath = path.resolve(
84
- __dirname,
85
- `../messages/${error.messageTemplate}.txt`
86
- );
87
-
88
- // Use sync API because Node.js should exit at this tick.
89
- const templateText = fs.readFileSync(templateFilePath, "utf-8");
90
- const template = lodash.template(templateText);
80
+ const template = require(`../messages/${error.messageTemplate}.js`);
91
81
 
92
82
  return template(error.messageData || {});
93
83
  } catch {
@@ -27,16 +27,11 @@ const {
27
27
  naming,
28
28
  CascadingConfigArrayFactory,
29
29
  IgnorePattern,
30
- getUsedExtractedConfigs
30
+ getUsedExtractedConfigs,
31
+ ModuleResolver
31
32
  }
32
33
  } = require("@eslint/eslintrc");
33
34
 
34
- /*
35
- * For some reason, ModuleResolver must be included via filepath instead of by
36
- * API exports in order to work properly. That's why this is separated out onto
37
- * its own require() statement.
38
- */
39
- const ModuleResolver = require("@eslint/eslintrc/lib/shared/relative-module-resolver");
40
35
  const { FileEnumerator } = require("./file-enumerator");
41
36
 
42
37
  const { Linter } = require("../linter");
@@ -38,7 +38,7 @@ const fs = require("fs");
38
38
  const path = require("path");
39
39
  const getGlobParent = require("glob-parent");
40
40
  const isGlob = require("is-glob");
41
- const { escapeRegExp } = require("lodash");
41
+ const escapeRegExp = require("escape-string-regexp");
42
42
  const { Minimatch } = require("minimatch");
43
43
 
44
44
  const {
@@ -4,17 +4,153 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
- const lodash = require("lodash");
8
- const fs = require("fs");
9
- const path = require("path");
10
-
11
7
  //------------------------------------------------------------------------------
12
8
  // Helpers
13
9
  //------------------------------------------------------------------------------
14
10
 
15
- const pageTemplate = lodash.template(fs.readFileSync(path.join(__dirname, "html-template-page.html"), "utf-8"));
16
- const messageTemplate = lodash.template(fs.readFileSync(path.join(__dirname, "html-template-message.html"), "utf-8"));
17
- const resultTemplate = lodash.template(fs.readFileSync(path.join(__dirname, "html-template-result.html"), "utf-8"));
11
+ const encodeHTML = (function() {
12
+ const encodeHTMLRules = {
13
+ "&": "&#38;",
14
+ "<": "&#60;",
15
+ ">": "&#62;",
16
+ '"': "&#34;",
17
+ "'": "&#39;"
18
+ };
19
+ const matchHTML = /[&<>"']/ug;
20
+
21
+ return function(code) {
22
+ return code
23
+ ? code.toString().replace(matchHTML, m => encodeHTMLRules[m] || m)
24
+ : "";
25
+ };
26
+ }());
27
+
28
+ /**
29
+ * Get the final HTML document.
30
+ * @param {Object} it data for the document.
31
+ * @returns {string} HTML document.
32
+ */
33
+ function pageTemplate(it) {
34
+ const { reportColor, reportSummary, date, results } = it;
35
+
36
+ return `
37
+ <!DOCTYPE html>
38
+ <html>
39
+ <head>
40
+ <meta charset="UTF-8">
41
+ <title>ESLint Report</title>
42
+ <style>
43
+ body {
44
+ font-family:Arial, "Helvetica Neue", Helvetica, sans-serif;
45
+ font-size:16px;
46
+ font-weight:normal;
47
+ margin:0;
48
+ padding:0;
49
+ color:#333
50
+ }
51
+ #overview {
52
+ padding:20px 30px
53
+ }
54
+ td, th {
55
+ padding:5px 10px
56
+ }
57
+ h1 {
58
+ margin:0
59
+ }
60
+ table {
61
+ margin:30px;
62
+ width:calc(100% - 60px);
63
+ max-width:1000px;
64
+ border-radius:5px;
65
+ border:1px solid #ddd;
66
+ border-spacing:0px;
67
+ }
68
+ th {
69
+ font-weight:400;
70
+ font-size:medium;
71
+ text-align:left;
72
+ cursor:pointer
73
+ }
74
+ td.clr-1, td.clr-2, th span {
75
+ font-weight:700
76
+ }
77
+ th span {
78
+ float:right;
79
+ margin-left:20px
80
+ }
81
+ th span:after {
82
+ content:"";
83
+ clear:both;
84
+ display:block
85
+ }
86
+ tr:last-child td {
87
+ border-bottom:none
88
+ }
89
+ tr td:first-child, tr td:last-child {
90
+ color:#9da0a4
91
+ }
92
+ #overview.bg-0, tr.bg-0 th {
93
+ color:#468847;
94
+ background:#dff0d8;
95
+ border-bottom:1px solid #d6e9c6
96
+ }
97
+ #overview.bg-1, tr.bg-1 th {
98
+ color:#f0ad4e;
99
+ background:#fcf8e3;
100
+ border-bottom:1px solid #fbeed5
101
+ }
102
+ #overview.bg-2, tr.bg-2 th {
103
+ color:#b94a48;
104
+ background:#f2dede;
105
+ border-bottom:1px solid #eed3d7
106
+ }
107
+ td {
108
+ border-bottom:1px solid #ddd
109
+ }
110
+ td.clr-1 {
111
+ color:#f0ad4e
112
+ }
113
+ td.clr-2 {
114
+ color:#b94a48
115
+ }
116
+ td a {
117
+ color:#3a33d1;
118
+ text-decoration:none
119
+ }
120
+ td a:hover {
121
+ color:#272296;
122
+ text-decoration:underline
123
+ }
124
+ </style>
125
+ </head>
126
+ <body>
127
+ <div id="overview" class="bg-${reportColor}">
128
+ <h1>ESLint Report</h1>
129
+ <div>
130
+ <span>${reportSummary}</span> - Generated on ${date}
131
+ </div>
132
+ </div>
133
+ <table>
134
+ <tbody>
135
+ ${results}
136
+ </tbody>
137
+ </table>
138
+ <script type="text/javascript">
139
+ var groups = document.querySelectorAll("tr[data-group]");
140
+ for (i = 0; i < groups.length; i++) {
141
+ groups[i].addEventListener("click", function() {
142
+ var inGroup = document.getElementsByClassName(this.getAttribute("data-group"));
143
+ this.innerHTML = (this.innerHTML.indexOf("+") > -1) ? this.innerHTML.replace("+", "-") : this.innerHTML.replace("-", "+");
144
+ for (var j = 0; j < inGroup.length; j++) {
145
+ inGroup[j].style.display = (inGroup[j].style.display !== "none") ? "none" : "table-row";
146
+ }
147
+ });
148
+ }
149
+ </script>
150
+ </body>
151
+ </html>
152
+ `.trimLeft();
153
+ }
18
154
 
19
155
  /**
20
156
  * Given a word and a count, append an s if count is not one.
@@ -58,6 +194,35 @@ function renderColor(totalErrors, totalWarnings) {
58
194
  return 0;
59
195
  }
60
196
 
197
+ /**
198
+ * Get HTML (table row) describing a single message.
199
+ * @param {Object} it data for the message.
200
+ * @returns {string} HTML (table row) describing the message.
201
+ */
202
+ function messageTemplate(it) {
203
+ const {
204
+ parentIndex,
205
+ lineNumber,
206
+ columnNumber,
207
+ severityNumber,
208
+ severityName,
209
+ message,
210
+ ruleUrl,
211
+ ruleId
212
+ } = it;
213
+
214
+ return `
215
+ <tr style="display:none" class="f-${parentIndex}">
216
+ <td>${lineNumber}:${columnNumber}</td>
217
+ <td class="clr-${severityNumber}">${severityName}</td>
218
+ <td>${encodeHTML(message)}</td>
219
+ <td>
220
+ <a href="${ruleUrl ? ruleUrl : ""}" target="_blank" rel="noopener noreferrer">${ruleId ? ruleId : ""}</a>
221
+ </td>
222
+ </tr>
223
+ `.trimLeft();
224
+ }
225
+
61
226
  /**
62
227
  * Get HTML (table rows) describing the messages.
63
228
  * @param {Array} messages Messages.
@@ -80,7 +245,9 @@ function renderMessages(messages, parentIndex, rulesMeta) {
80
245
  if (rulesMeta) {
81
246
  const meta = rulesMeta[message.ruleId];
82
247
 
83
- ruleUrl = lodash.get(meta, "docs.url", null);
248
+ if (meta && meta.docs && meta.docs.url) {
249
+ ruleUrl = meta.docs.url;
250
+ }
84
251
  }
85
252
 
86
253
  return messageTemplate({
@@ -96,6 +263,24 @@ function renderMessages(messages, parentIndex, rulesMeta) {
96
263
  }).join("\n");
97
264
  }
98
265
 
266
+ /**
267
+ * Get HTML (table row) describing the result for a single file.
268
+ * @param {Object} it data for the file.
269
+ * @returns {string} HTML (table row) describing the result for the file.
270
+ */
271
+ function resultTemplate(it) {
272
+ const { color, index, filePath, summary } = it;
273
+
274
+ return `
275
+ <tr class="bg-${color}" data-group="f-${index}">
276
+ <th colspan="4">
277
+ [+] ${encodeHTML(filePath)}
278
+ <span>${encodeHTML(summary)}</span>
279
+ </th>
280
+ </tr>
281
+ `.trimLeft();
282
+ }
283
+
99
284
  // eslint-disable-next-line jsdoc/require-description
100
285
  /**
101
286
  * @param {Array} results Test results.
@@ -108,7 +293,6 @@ function renderResults(results, rulesMeta) {
108
293
  color: renderColor(result.errorCount, result.warningCount),
109
294
  filePath: result.filePath,
110
295
  summary: renderSummary(result.errorCount, result.warningCount)
111
-
112
296
  }) + renderMessages(result.messages, index, rulesMeta)).join("\n");
113
297
  }
114
298
 
@@ -9,7 +9,7 @@
9
9
  // Requirements
10
10
  //------------------------------------------------------------------------------
11
11
 
12
- const lodash = require("lodash"),
12
+ const equal = require("fast-deep-equal"),
13
13
  recConfig = require("../../conf/eslint-recommended"),
14
14
  ConfigOps = require("@eslint/eslintrc/lib/shared/config-ops"),
15
15
  { Linter } = require("../linter"),
@@ -329,7 +329,7 @@ function extendFromRecommended(config) {
329
329
  const recRules = Object.keys(recConfig.rules).filter(ruleId => ConfigOps.isErrorSeverity(recConfig.rules[ruleId]));
330
330
 
331
331
  recRules.forEach(ruleId => {
332
- if (lodash.isEqual(recConfig.rules[ruleId], newConfig.rules[ruleId])) {
332
+ if (equal(recConfig.rules[ruleId], newConfig.rules[ruleId])) {
333
333
  delete newConfig.rules[ruleId];
334
334
  }
335
335
  });
@@ -117,6 +117,7 @@ function writeJSConfigFile(config, filePath) {
117
117
  function write(config, filePath) {
118
118
  switch (path.extname(filePath)) {
119
119
  case ".js":
120
+ case ".cjs":
120
121
  writeJSConfigFile(config, filePath);
121
122
  break;
122
123
 
@@ -12,6 +12,7 @@
12
12
 
13
13
  const util = require("util"),
14
14
  path = require("path"),
15
+ fs = require("fs"),
15
16
  enquirer = require("enquirer"),
16
17
  ProgressBar = require("progress"),
17
18
  semver = require("semver"),
@@ -48,6 +49,16 @@ function writeFile(config, format) {
48
49
  extname = ".yml";
49
50
  } else if (format === "JSON") {
50
51
  extname = ".json";
52
+ } else if (format === "JavaScript") {
53
+ const pkgJSONPath = npmUtils.findPackageJson();
54
+
55
+ if (pkgJSONPath) {
56
+ const pkgJSONContents = JSON.parse(fs.readFileSync(pkgJSONPath, "utf8"));
57
+
58
+ if (pkgJSONContents.type === "module") {
59
+ extname = ".cjs";
60
+ }
61
+ }
51
62
  }
52
63
 
53
64
  const installedESLint = config.installedESLint;
@@ -531,7 +542,8 @@ function promptUser() {
531
542
  choices: [
532
543
  { message: "Airbnb: https://github.com/airbnb/javascript", name: "airbnb" },
533
544
  { message: "Standard: https://github.com/standard/standard", name: "standard" },
534
- { message: "Google: https://github.com/google/eslint-config-google", name: "google" }
545
+ { message: "Google: https://github.com/google/eslint-config-google", name: "google" },
546
+ { message: "XO: https://github.com/xojs/eslint-config-xo", name: "xo" }
535
547
  ],
536
548
  skip() {
537
549
  this.state.answers.packageJsonExists = npmUtils.checkPackageJson();
@@ -683,6 +695,7 @@ const init = {
683
695
  hasESLintVersionConflict,
684
696
  installModules,
685
697
  processAnswers,
698
+ writeFile,
686
699
  /* istanbul ignore next */initializeConfig() {
687
700
  return promptUser();
688
701
  }
@@ -172,6 +172,7 @@ function checkPackageJson(startDir) {
172
172
  module.exports = {
173
173
  installSyncSaveDev,
174
174
  fetchPeerDependencies,
175
+ findPackageJson,
175
176
  checkDeps,
176
177
  checkDevDeps,
177
178
  checkPackageJson
@@ -5,8 +5,6 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const lodash = require("lodash");
9
-
10
8
  /**
11
9
  * Compares the locations of two objects in a source file
12
10
  * @param {{line: number, column: number}} itemA The first object
@@ -124,7 +122,21 @@ module.exports = ({ directives, problems, reportUnusedDisableDirectives = "off"
124
122
  .map(directive => Object.assign({}, directive, { unprocessedDirective: directive }))
125
123
  .sort(compareLocations);
126
124
 
127
- const lineDirectives = lodash.flatMap(directives, directive => {
125
+ /**
126
+ * Returns a new array formed by applying a given callback function to each element of the array, and then flattening the result by one level.
127
+ * TODO(stephenwade): Replace this with array.flatMap when we drop support for Node v10
128
+ * @param {any[]} array The array to process
129
+ * @param {Function} fn The function to use
130
+ * @returns {any[]} The result array
131
+ */
132
+ function flatMap(array, fn) {
133
+ const mapped = array.map(fn);
134
+ const flattened = [].concat(...mapped);
135
+
136
+ return flattened;
137
+ }
138
+
139
+ const lineDirectives = flatMap(directives, directive => {
128
140
  switch (directive.type) {
129
141
  case "disable":
130
142
  case "enable":
@@ -15,7 +15,7 @@ const
15
15
  eslintScope = require("eslint-scope"),
16
16
  evk = require("eslint-visitor-keys"),
17
17
  espree = require("espree"),
18
- lodash = require("lodash"),
18
+ merge = require("lodash.merge"),
19
19
  BuiltInEnvironments = require("@eslint/eslintrc/conf/environments"),
20
20
  pkg = require("../../package.json"),
21
21
  astUtils = require("../shared/ast-utils"),
@@ -529,8 +529,8 @@ function normalizeVerifyOptions(providedOptions, config) {
529
529
  function resolveParserOptions(parserName, providedOptions, enabledEnvironments) {
530
530
  const parserOptionsFromEnv = enabledEnvironments
531
531
  .filter(env => env.parserOptions)
532
- .reduce((parserOptions, env) => lodash.merge(parserOptions, env.parserOptions), {});
533
- const mergedParserOptions = lodash.merge(parserOptionsFromEnv, providedOptions || {});
532
+ .reduce((parserOptions, env) => merge(parserOptions, env.parserOptions), {});
533
+ const mergedParserOptions = merge(parserOptionsFromEnv, providedOptions || {});
534
534
  const isModule = mergedParserOptions.sourceType === "module";
535
535
 
536
536
  if (isModule) {
@@ -1286,7 +1286,9 @@ class Linter {
1286
1286
  const filenameToExpose = normalizeFilename(filename);
1287
1287
  const text = ensureText(textOrSourceCode);
1288
1288
  const preprocess = options.preprocess || (rawText => [rawText]);
1289
- const postprocess = options.postprocess || lodash.flatten;
1289
+
1290
+ // TODO(stephenwade): Replace this with array.flat() when we drop support for Node v10
1291
+ const postprocess = options.postprocess || (array => [].concat(...array));
1290
1292
  const filterCodeBlock =
1291
1293
  options.filterCodeBlock ||
1292
1294
  (blockFilename => blockFilename.endsWith(".js"));
@@ -1308,9 +1310,9 @@ class Linter {
1308
1310
  return [];
1309
1311
  }
1310
1312
 
1311
- // Resolve configuration again if the file extension was changed.
1312
- if (configForRecursive && path.extname(blockName) !== originalExtname) {
1313
- debug("Resolving configuration again because the file extension was changed.");
1313
+ // Resolve configuration again if the file content or extension was changed.
1314
+ if (configForRecursive && (text !== blockText || path.extname(blockName) !== originalExtname)) {
1315
+ debug("Resolving configuration again because the file content or extension was changed.");
1314
1316
  return this._verifyWithConfigArray(
1315
1317
  blockText,
1316
1318
  configForRecursive,
@@ -10,7 +10,6 @@
10
10
  //------------------------------------------------------------------------------
11
11
 
12
12
  const esquery = require("esquery");
13
- const lodash = require("lodash");
14
13
 
15
14
  //------------------------------------------------------------------------------
16
15
  // Typedefs
@@ -32,6 +31,35 @@ const lodash = require("lodash");
32
31
  // Helpers
33
32
  //------------------------------------------------------------------------------
34
33
 
34
+ /**
35
+ * Computes the union of one or more arrays
36
+ * @param {...any[]} arrays One or more arrays to union
37
+ * @returns {any[]} The union of the input arrays
38
+ */
39
+ function union(...arrays) {
40
+
41
+ // TODO(stephenwade): Replace this with arrays.flat() when we drop support for Node v10
42
+ return [...new Set([].concat(...arrays))];
43
+ }
44
+
45
+ /**
46
+ * Computes the intersection of one or more arrays
47
+ * @param {...any[]} arrays One or more arrays to intersect
48
+ * @returns {any[]} The intersection of the input arrays
49
+ */
50
+ function intersection(...arrays) {
51
+ if (arrays.length === 0) {
52
+ return [];
53
+ }
54
+
55
+ let result = [...new Set(arrays[0])];
56
+
57
+ for (const array of arrays.slice(1)) {
58
+ result = result.filter(x => array.includes(x));
59
+ }
60
+ return result;
61
+ }
62
+
35
63
  /**
36
64
  * Gets the possible types of a selector
37
65
  * @param {Object} parsedSelector An object (from esquery) describing the matching behavior of the selector
@@ -46,7 +74,7 @@ function getPossibleTypes(parsedSelector) {
46
74
  const typesForComponents = parsedSelector.selectors.map(getPossibleTypes);
47
75
 
48
76
  if (typesForComponents.every(Boolean)) {
49
- return lodash.union(...typesForComponents);
77
+ return union(...typesForComponents);
50
78
  }
51
79
  return null;
52
80
  }
@@ -63,7 +91,7 @@ function getPossibleTypes(parsedSelector) {
63
91
  * If at least one of the components could only match a particular type, the compound could only match
64
92
  * the intersection of those types.
65
93
  */
66
- return lodash.intersection(...typesForComponents);
94
+ return intersection(...typesForComponents);
67
95
  }
68
96
 
69
97
  case "child":
@@ -166,15 +194,21 @@ function tryParseSelector(rawSelector) {
166
194
  }
167
195
  }
168
196
 
197
+ const selectorCache = new Map();
198
+
169
199
  /**
170
200
  * Parses a raw selector string, and returns the parsed selector along with specificity and type information.
171
201
  * @param {string} rawSelector A raw AST selector
172
202
  * @returns {ASTSelector} A selector descriptor
173
203
  */
174
- const parseSelector = lodash.memoize(rawSelector => {
204
+ function parseSelector(rawSelector) {
205
+ if (selectorCache.has(rawSelector)) {
206
+ return selectorCache.get(rawSelector);
207
+ }
208
+
175
209
  const parsedSelector = tryParseSelector(rawSelector);
176
210
 
177
- return {
211
+ const result = {
178
212
  rawSelector,
179
213
  isExit: rawSelector.endsWith(":exit"),
180
214
  parsedSelector,
@@ -182,7 +216,10 @@ const parseSelector = lodash.memoize(rawSelector => {
182
216
  attributeCount: countClassAttributes(parsedSelector),
183
217
  identifierCount: countIdentifiers(parsedSelector)
184
218
  };
185
- });
219
+
220
+ selectorCache.set(rawSelector, result);
221
+ return result;
222
+ }
186
223
 
187
224
  //------------------------------------------------------------------------------
188
225
  // Public Interface