eslint 7.26.0 → 7.30.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 (67) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/README.md +12 -7
  3. package/bin/eslint.js +2 -12
  4. package/lib/cli-engine/file-enumerator.js +1 -1
  5. package/lib/cli-engine/formatters/html.js +193 -9
  6. package/lib/config/default-config.js +52 -0
  7. package/lib/config/flat-config-array.js +125 -0
  8. package/lib/config/flat-config-schema.js +452 -0
  9. package/lib/config/rule-validator.js +169 -0
  10. package/lib/eslint/eslint.js +38 -2
  11. package/lib/init/autoconfig.js +2 -2
  12. package/lib/init/npm-utils.js +1 -2
  13. package/lib/linter/apply-disable-directives.js +15 -3
  14. package/lib/linter/linter.js +31 -21
  15. package/lib/linter/node-event-generator.js +43 -6
  16. package/lib/rule-tester/rule-tester.js +89 -23
  17. package/lib/rules/arrow-body-style.js +21 -11
  18. package/lib/rules/comma-dangle.js +16 -7
  19. package/lib/rules/comma-spacing.js +1 -1
  20. package/lib/rules/comma-style.js +1 -2
  21. package/lib/rules/complexity.js +2 -3
  22. package/lib/rules/consistent-return.js +2 -2
  23. package/lib/rules/dot-notation.js +3 -3
  24. package/lib/rules/eol-last.js +2 -7
  25. package/lib/rules/indent.js +10 -13
  26. package/lib/rules/max-lines-per-function.js +2 -3
  27. package/lib/rules/max-lines.js +32 -7
  28. package/lib/rules/max-params.js +2 -3
  29. package/lib/rules/max-statements.js +2 -3
  30. package/lib/rules/no-duplicate-imports.js +214 -66
  31. package/lib/rules/no-fallthrough.js +18 -13
  32. package/lib/rules/no-implicit-coercion.js +21 -2
  33. package/lib/rules/no-restricted-imports.js +61 -24
  34. package/lib/rules/no-unused-vars.js +40 -10
  35. package/lib/rules/no-useless-backreference.js +1 -2
  36. package/lib/rules/no-useless-computed-key.js +8 -2
  37. package/lib/rules/no-warning-comments.js +1 -1
  38. package/lib/rules/object-curly-newline.js +19 -4
  39. package/lib/rules/prefer-arrow-callback.js +4 -4
  40. package/lib/rules/spaced-comment.js +2 -2
  41. package/lib/rules/use-isnan.js +4 -1
  42. package/lib/rules/utils/ast-utils.js +2 -2
  43. package/lib/shared/deprecation-warnings.js +12 -3
  44. package/lib/shared/string-utils.js +22 -0
  45. package/lib/source-code/source-code.js +8 -7
  46. package/lib/source-code/token-store/utils.js +4 -12
  47. package/messages/{all-files-ignored.txt → all-files-ignored.js} +10 -2
  48. package/messages/extend-config-missing.js +13 -0
  49. package/messages/failed-to-read-json.js +11 -0
  50. package/messages/file-not-found.js +10 -0
  51. package/messages/{no-config-found.txt → no-config-found.js} +9 -1
  52. package/messages/plugin-conflict.js +22 -0
  53. package/messages/plugin-invalid.js +16 -0
  54. package/messages/plugin-missing.js +19 -0
  55. package/messages/{print-config-with-directory-path.txt → print-config-with-directory-path.js} +6 -0
  56. package/messages/whitespace-found.js +11 -0
  57. package/package.json +9 -7
  58. package/lib/cli-engine/formatters/html-template-message.html +0 -8
  59. package/lib/cli-engine/formatters/html-template-page.html +0 -115
  60. package/lib/cli-engine/formatters/html-template-result.html +0 -6
  61. package/messages/extend-config-missing.txt +0 -5
  62. package/messages/failed-to-read-json.txt +0 -3
  63. package/messages/file-not-found.txt +0 -2
  64. package/messages/plugin-conflict.txt +0 -7
  65. package/messages/plugin-invalid.txt +0 -8
  66. package/messages/plugin-missing.txt +0 -11
  67. package/messages/whitespace-found.txt +0 -3
package/CHANGELOG.md CHANGED
@@ -1,3 +1,61 @@
1
+ v7.30.0 - July 2, 2021
2
+
3
+ * [`5f74642`](https://github.com/eslint/eslint/commit/5f746420700d457b92dd86659de588d272937b79) Chore: don't check Program.start in SourceCode#getComments (refs #14744) (#14748) (Milos Djermanovic)
4
+ * [`19a871a`](https://github.com/eslint/eslint/commit/19a871a35ae9997ce352624b1081c96c54b73a9f) Docs: Suggest linting plugins for ESLint plugin developers (#14754) (Bryan Mishkin)
5
+ * [`aa87329`](https://github.com/eslint/eslint/commit/aa87329d919f569404ca573b439934552006572f) Docs: fix broken links (#14756) (Sam Chen)
6
+ * [`278813a`](https://github.com/eslint/eslint/commit/278813a6e759f6b5512ac64c7530c9c51732e692) Docs: fix and add more examples for new-cap rule (fixes #12874) (#14725) (Nitin Kumar)
7
+ * [`ed1da5d`](https://github.com/eslint/eslint/commit/ed1da5d96af2587b7211854e45cf8657ef808710) Update: ecmaVersion allows "latest" (#14720) (薛定谔的猫)
8
+ * [`104c0b5`](https://github.com/eslint/eslint/commit/104c0b592f203d315a108d311c58375357e40b24) Update: improve use-isnan rule to detect `Number.NaN` (fixes #14715) (#14718) (Nitin Kumar)
9
+ * [`b08170b`](https://github.com/eslint/eslint/commit/b08170b92beb22db6ec612ebdfff930f9e0582ab) Update: Implement FlatConfigArray (refs #13481) (#14321) (Nicholas C. Zakas)
10
+ * [`f113cdd`](https://github.com/eslint/eslint/commit/f113cdd872257d72bbd66d95e4eaf13623323b24) Chore: upgrade eslint-plugin-eslint-plugin (#14738) (薛定谔的猫)
11
+ * [`1b8997a`](https://github.com/eslint/eslint/commit/1b8997ab63781f4ebf87e3269400b2ef4c7d2973) Docs: Fix getRulesMetaForResults link syntax (#14723) (Brandon Mills)
12
+ * [`aada733`](https://github.com/eslint/eslint/commit/aada733d2aee830aa32cccb9828cd72db4ccd6bd) Docs: fix two broken links (#14726) (Sam Chen)
13
+ * [`8972529`](https://github.com/eslint/eslint/commit/8972529f82d13bd04059ee8852b4ebb9b5350962) Docs: Update README team and sponsors (ESLint Jenkins)
14
+
15
+ v7.29.0 - June 18, 2021
16
+
17
+ * [`bfbfe5c`](https://github.com/eslint/eslint/commit/bfbfe5c1fd4c39a06d5e159dbe48479ca4305fc0) New: Add only to RuleTester (refs eslint/rfcs#73) (#14677) (Brandon Mills)
18
+ * [`c2cd7b4`](https://github.com/eslint/eslint/commit/c2cd7b4a18057ca6067bdfc16de771dc5d90c0ea) New: Add ESLint#getRulesMetaForResults() (refs #13654) (#14716) (Nicholas C. Zakas)
19
+ * [`eea7e0d`](https://github.com/eslint/eslint/commit/eea7e0d09d6ef43d6663cbe424e7974764a5f7fe) Chore: remove duplicate code (#14719) (Nitin Kumar)
20
+ * [`6a1c7a0`](https://github.com/eslint/eslint/commit/6a1c7a0dac050ea5876972c50563a7eb867b38d3) Fix: allow fallthrough comment inside block (fixes #14701) (#14702) (Kevin Gibbons)
21
+ * [`a47e5e3`](https://github.com/eslint/eslint/commit/a47e5e30b0da364593b6881f6826c595da8696f5) Docs: Add Mega-Linter to the list of integrations (#14707) (Nicolas Vuillamy)
22
+ * [`353ddf9`](https://github.com/eslint/eslint/commit/353ddf965078030794419b089994373e27ffc86e) Chore: enable reportUnusedDisableDirectives in eslint-config-eslint (#14699) (薛定谔的猫)
23
+ * [`757c495`](https://github.com/eslint/eslint/commit/757c49584a5852c468c1b4a0b74ad3aa39d954e5) Chore: add some rules to eslint-config-eslint (#14692) (薛定谔的猫)
24
+ * [`c93a222`](https://github.com/eslint/eslint/commit/c93a222563177a9b5bc7a59aa106bc0a6d31e063) Docs: fix a broken link (#14697) (Sam Chen)
25
+ * [`655c118`](https://github.com/eslint/eslint/commit/655c1187fc845bac61ae8d06c556f1a59ee2071b) Sponsors: Sync README with website (ESLint Jenkins)
26
+ * [`e2bed2e`](https://github.com/eslint/eslint/commit/e2bed2ead22b575d55ccaeed94eecd3a979dd871) Sponsors: Sync README with website (ESLint Jenkins)
27
+ * [`8490fb4`](https://github.com/eslint/eslint/commit/8490fb42e559ef0b3c34ac60be4e05e0d879a9cb) Sponsors: Sync README with website (ESLint Jenkins)
28
+ * [`ddbe877`](https://github.com/eslint/eslint/commit/ddbe877c95224e127215d35562a175c6f2b7ba22) Sponsors: Sync README with website (ESLint Jenkins)
29
+
30
+ v7.28.0 - June 4, 2021
31
+
32
+ * [`1237705`](https://github.com/eslint/eslint/commit/1237705dd08c209c5e3136045ec51a4ba87a3abe) Upgrade: @eslint/eslintrc to 0.4.2 (#14672) (Milos Djermanovic)
33
+ * [`123fb86`](https://github.com/eslint/eslint/commit/123fb8648731c2c23313c544ffa1872d3024fe68) Docs: Add Feedback Needed triage description (#14670) (Nicholas C. Zakas)
34
+ * [`c545163`](https://github.com/eslint/eslint/commit/c5451635b4e89827cfc8d8d77083647c74506e42) Update: support multiline /*eslint-env*/ directives (fixes #14652) (#14660) (薛定谔的猫)
35
+ * [`8d1e75a`](https://github.com/eslint/eslint/commit/8d1e75a31b3e3d67130709a219bdd07ce6f3cf74) Upgrade: glob-parent version in package.json (#14658) (Hamza Najeeb)
36
+ * [`1f048cb`](https://github.com/eslint/eslint/commit/1f048cb0eec660d2052f1758f4b2ad7b1cb424e1) Fix: no-implicit-coercion false positive with `String()` (fixes #14623) (#14641) (Milos Djermanovic)
37
+ * [`d709abf`](https://github.com/eslint/eslint/commit/d709abfdde087325d4578b6709dc61040b8ca9d8) Chore: fix comment location in no-unused-vars (#14648) (Milos Djermanovic)
38
+ * [`e44ce0a`](https://github.com/eslint/eslint/commit/e44ce0a8acfaad513c385150c25e76e82a1b8f12) Fix: no-duplicate-imports allow unmergeable (fixes #12758, fixes #12760) (#14238) (Soufiane Boutahlil)
39
+ * [`bb66a3d`](https://github.com/eslint/eslint/commit/bb66a3d91af426dac9a7ffdbe47bdbbc0ffd4dd7) New: add `getPhysicalFilename()` method to rule context (fixes #11989) (#14616) (Nitin Kumar)
40
+ * [`2e43dac`](https://github.com/eslint/eslint/commit/2e43dacd24337a82d4184fac9b44d497675f46ef) Docs: fix `no-sequences` example (#14643) (Nitin Kumar)
41
+ * [`958ff4e`](https://github.com/eslint/eslint/commit/958ff4e8a5102f204f1484d09985e28a79790996) Docs: add note for arrow functions in no-seq rule (#14578) (Nitin Kumar)
42
+ * [`e4f111b`](https://github.com/eslint/eslint/commit/e4f111b67d114adbf76a9c9dbb18fa4f49bc91b6) Fix: arrow-body-style crash with object pattern (fixes #14633) (#14635) (Milos Djermanovic)
43
+ * [`ec28b5a`](https://github.com/eslint/eslint/commit/ec28b5a2bdc69f34ce29d670f5e84d2446774a00) Chore: upgrade eslint-plugin-eslint-plugin (#14590) (薛定谔的猫)
44
+ * [`85a2725`](https://github.com/eslint/eslint/commit/85a2725b1fade5538e727102d9701ccb503e54d4) Docs: Update README team and sponsors (ESLint Jenkins)
45
+
46
+ v7.27.0 - May 21, 2021
47
+
48
+ * [`2c0868c`](https://github.com/eslint/eslint/commit/2c0868cbeadc9f42716fa1178ebdc6b4cee6d31e) Chore: merge all html formatter files into `html.js` (#14612) (Milos Djermanovic)
49
+ * [`9e9b5e0`](https://github.com/eslint/eslint/commit/9e9b5e07475564813b62cd1d7562a93c5fb4bc74) Update: no-unused-vars false negative with comma operator (fixes #14325) (#14354) (Nitin Kumar)
50
+ * [`afe9569`](https://github.com/eslint/eslint/commit/afe95693e1e4316a1c6f01d39345061d4c5921c7) Chore: use includes instead of indexOf (#14607) (Mikhail Bodrov)
51
+ * [`c0f418e`](https://github.com/eslint/eslint/commit/c0f418e2476df98519bc156b81d20431984e8704) Chore: Remove lodash (#14287) (Stephen Wade)
52
+ * [`52655dd`](https://github.com/eslint/eslint/commit/52655dd54925ee02af2ba3a0ebc09de959ae3101) Update: no-restricted-imports custom message for patterns (fixes #11843) (#14580) (Alex Holden)
53
+ * [`967b1c4`](https://github.com/eslint/eslint/commit/967b1c4ceca8f5248378477da94ff118dafaa647) Chore: Fix typo in large.js (#14589) (Ikko Ashimine)
54
+ * [`2466a05`](https://github.com/eslint/eslint/commit/2466a05160de60958457d984b79fd445c12ebc98) Sponsors: Sync README with website (ESLint Jenkins)
55
+ * [`fe29f18`](https://github.com/eslint/eslint/commit/fe29f18227fd02fd7c3da033417d621275b00d0a) Sponsors: Sync README with website (ESLint Jenkins)
56
+ * [`086c1d6`](https://github.com/eslint/eslint/commit/086c1d6e8593cf8e7851daa8f2a890c213cf6999) Chore: add more test cases for `no-sequences` (#14579) (Nitin Kumar)
57
+ * [`6a2ced8`](https://github.com/eslint/eslint/commit/6a2ced892c0dc43fa4942293b9f1c4b9151c3741) Docs: Update README team and sponsors (ESLint Jenkins)
58
+
1
59
  v7.26.0 - May 7, 2021
2
60
 
3
61
  * [`aaf65e6`](https://github.com/eslint/eslint/commit/aaf65e629adb74401092c3ccc9cb4e4bd1c8609b) Upgrade: eslintrc for ModuleResolver fix (#14577) (Brandon Mills)
package/README.md CHANGED
@@ -223,11 +223,6 @@ Nicholas C. Zakas
223
223
  Brandon Mills
224
224
  </a>
225
225
  </td><td align="center" valign="top" width="11%">
226
- <a href="https://github.com/mysticatea">
227
- <img src="https://github.com/mysticatea.png?s=75" width="75" height="75"><br />
228
- Toru Nagashima
229
- </a>
230
- </td><td align="center" valign="top" width="11%">
231
226
  <a href="https://github.com/mdjermanovic">
232
227
  <img src="https://github.com/mdjermanovic.png?s=75" width="75" height="75"><br />
233
228
  Milos Djermanovic
@@ -240,6 +235,11 @@ Milos Djermanovic
240
235
  The people who review and implement new features.
241
236
 
242
237
  <table><tbody><tr><td align="center" valign="top" width="11%">
238
+ <a href="https://github.com/mysticatea">
239
+ <img src="https://github.com/mysticatea.png?s=75" width="75" height="75"><br />
240
+ Toru Nagashima
241
+ </a>
242
+ </td><td align="center" valign="top" width="11%">
243
243
  <a href="https://github.com/aladdin-add">
244
244
  <img src="https://github.com/aladdin-add.png?s=75" width="75" height="75"><br />
245
245
  薛定谔的猫
@@ -268,6 +268,11 @@ Anix
268
268
  <img src="https://github.com/yeonjuan.png?s=75" width="75" height="75"><br />
269
269
  YeonJuan
270
270
  </a>
271
+ </td><td align="center" valign="top" width="11%">
272
+ <a href="https://github.com/snitin315">
273
+ <img src="https://github.com/snitin315.png?s=75" width="75" height="75"><br />
274
+ Nitin Kumar
275
+ </a>
271
276
  </td></tr></tbody></table>
272
277
 
273
278
 
@@ -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.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://coinbase.com"><img src="https://avatars.githubusercontent.com/u/1885080?v=4" alt="Coinbase" 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://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>
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> <a href="https://www.practiceignition.com"><img src="https://avatars.githubusercontent.com/u/5753491?v=4" alt="Practice Ignition" 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 {
@@ -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
 
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @fileoverview Default configuration
3
+ * @author Nicholas C. Zakas
4
+ */
5
+
6
+ "use strict";
7
+
8
+ //-----------------------------------------------------------------------------
9
+ // Requirements
10
+ //-----------------------------------------------------------------------------
11
+
12
+ const Rules = require("../rules");
13
+
14
+ //-----------------------------------------------------------------------------
15
+ // Helpers
16
+ //-----------------------------------------------------------------------------
17
+
18
+
19
+ exports.defaultConfig = [
20
+ {
21
+ plugins: {
22
+ "@": {
23
+ parsers: {
24
+ espree: require("espree")
25
+ },
26
+
27
+ /*
28
+ * Because we try to delay loading rules until absolutely
29
+ * necessary, a proxy allows us to hook into the lazy-loading
30
+ * aspect of the rules map while still keeping all of the
31
+ * relevant configuration inside of the config array.
32
+ */
33
+ rules: new Proxy({}, {
34
+ get(target, property) {
35
+ return Rules.get(property);
36
+ },
37
+
38
+ has(target, property) {
39
+ return Rules.has(property);
40
+ }
41
+ })
42
+ }
43
+ },
44
+ ignores: [
45
+ "**/node_modules/**",
46
+ ".git/**"
47
+ ],
48
+ languageOptions: {
49
+ parser: "@/espree"
50
+ }
51
+ }
52
+ ];
@@ -0,0 +1,125 @@
1
+ /**
2
+ * @fileoverview Flat Config Array
3
+ * @author Nicholas C. Zakas
4
+ */
5
+
6
+ "use strict";
7
+
8
+ //-----------------------------------------------------------------------------
9
+ // Requirements
10
+ //-----------------------------------------------------------------------------
11
+
12
+ const { ConfigArray, ConfigArraySymbol } = require("@humanwhocodes/config-array");
13
+ const { flatConfigSchema } = require("./flat-config-schema");
14
+ const { RuleValidator } = require("./rule-validator");
15
+ const { defaultConfig } = require("./default-config");
16
+ const recommendedConfig = require("../../conf/eslint-recommended");
17
+ const allConfig = require("../../conf/eslint-all");
18
+
19
+ //-----------------------------------------------------------------------------
20
+ // Helpers
21
+ //-----------------------------------------------------------------------------
22
+
23
+ const ruleValidator = new RuleValidator();
24
+
25
+ /**
26
+ * Splits a plugin identifier in the form a/b/c into two parts: a/b and c.
27
+ * @param {string} identifier The identifier to parse.
28
+ * @returns {{objectName: string, pluginName: string}} The parts of the plugin
29
+ * name.
30
+ */
31
+ function splitPluginIdentifier(identifier) {
32
+ const parts = identifier.split("/");
33
+
34
+ return {
35
+ objectName: parts.pop(),
36
+ pluginName: parts.join("/")
37
+ };
38
+ }
39
+
40
+ //-----------------------------------------------------------------------------
41
+ // Exports
42
+ //-----------------------------------------------------------------------------
43
+
44
+ /**
45
+ * Represents an array containing configuration information for ESLint.
46
+ */
47
+ class FlatConfigArray extends ConfigArray {
48
+
49
+ /**
50
+ * Creates a new instance.
51
+ * @param {*[]} configs An array of configuration information.
52
+ * @param {{basePath: string, baseConfig: FlatConfig}} options The options
53
+ * to use for the config array instance.
54
+ */
55
+ constructor(configs, { basePath, baseConfig = defaultConfig }) {
56
+ super(configs, {
57
+ basePath,
58
+ schema: flatConfigSchema
59
+ });
60
+
61
+ this.unshift(baseConfig);
62
+ }
63
+
64
+ /* eslint-disable class-methods-use-this */
65
+ /**
66
+ * Replaces a config with another config to allow us to put strings
67
+ * in the config array that will be replaced by objects before
68
+ * normalization.
69
+ * @param {Object} config The config to preprocess.
70
+ * @returns {Object} The preprocessed config.
71
+ */
72
+ [ConfigArraySymbol.preprocessConfig](config) {
73
+ if (config === "eslint:recommended") {
74
+ return recommendedConfig;
75
+ }
76
+
77
+ if (config === "eslint:all") {
78
+ return allConfig;
79
+ }
80
+
81
+ return config;
82
+ }
83
+
84
+ /**
85
+ * Finalizes the config by replacing plugin references with their objects
86
+ * and validating rule option schemas.
87
+ * @param {Object} config The config to finalize.
88
+ * @returns {Object} The finalized config.
89
+ * @throws {TypeError} If the config is invalid.
90
+ */
91
+ [ConfigArraySymbol.finalizeConfig](config) {
92
+
93
+ const { plugins, languageOptions, processor } = config;
94
+
95
+ // Check parser value
96
+ if (languageOptions && languageOptions.parser && typeof languageOptions.parser === "string") {
97
+ const { pluginName, objectName: parserName } = splitPluginIdentifier(languageOptions.parser);
98
+
99
+ if (!plugins || !plugins[pluginName] || !plugins[pluginName].parsers || !plugins[pluginName].parsers[parserName]) {
100
+ throw new TypeError(`Key "parser": Could not find "${parserName}" in plugin "${pluginName}".`);
101
+ }
102
+
103
+ languageOptions.parser = plugins[pluginName].parsers[parserName];
104
+ }
105
+
106
+ // Check processor value
107
+ if (processor && typeof processor === "string") {
108
+ const { pluginName, objectName: processorName } = splitPluginIdentifier(processor);
109
+
110
+ if (!plugins || !plugins[pluginName] || !plugins[pluginName].processors || !plugins[pluginName].processors[processorName]) {
111
+ throw new TypeError(`Key "processor": Could not find "${processorName}" in plugin "${pluginName}".`);
112
+ }
113
+
114
+ config.processor = plugins[pluginName].processors[processorName];
115
+ }
116
+
117
+ ruleValidator.validate(config);
118
+
119
+ return config;
120
+ }
121
+ /* eslint-enable class-methods-use-this */
122
+
123
+ }
124
+
125
+ exports.FlatConfigArray = FlatConfigArray;