eslint 7.24.0 → 7.28.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.
- package/CHANGELOG.md +54 -0
- package/README.md +7 -7
- package/bin/eslint.js +2 -12
- package/lib/cli-engine/cli-engine.js +2 -7
- package/lib/cli-engine/file-enumerator.js +1 -1
- package/lib/cli-engine/formatters/html.js +193 -9
- package/lib/init/autoconfig.js +2 -2
- package/lib/init/config-file.js +1 -0
- package/lib/init/config-initializer.js +14 -1
- package/lib/init/npm-utils.js +1 -0
- package/lib/linter/apply-disable-directives.js +15 -3
- package/lib/linter/linter.js +18 -12
- package/lib/linter/node-event-generator.js +43 -6
- package/lib/rule-tester/rule-tester.js +14 -10
- package/lib/rules/arrow-body-style.js +21 -11
- package/lib/rules/comma-dangle.js +16 -7
- package/lib/rules/comma-spacing.js +1 -1
- package/lib/rules/complexity.js +2 -3
- package/lib/rules/consistent-return.js +2 -2
- package/lib/rules/eol-last.js +2 -7
- package/lib/rules/indent.js +8 -9
- package/lib/rules/max-lines-per-function.js +2 -3
- package/lib/rules/max-lines.js +32 -7
- package/lib/rules/max-params.js +2 -3
- package/lib/rules/max-statements.js +2 -3
- package/lib/rules/no-duplicate-imports.js +214 -66
- package/lib/rules/no-fallthrough.js +2 -8
- package/lib/rules/no-implicit-coercion.js +21 -2
- package/lib/rules/no-restricted-imports.js +61 -24
- package/lib/rules/no-unused-vars.js +51 -13
- package/lib/rules/no-useless-backreference.js +1 -2
- package/lib/rules/no-useless-computed-key.js +8 -2
- package/lib/rules/no-warning-comments.js +1 -1
- package/lib/rules/object-curly-newline.js +19 -4
- package/lib/rules/radix.js +19 -3
- package/lib/rules/require-atomic-updates.js +23 -20
- package/lib/rules/spaced-comment.js +2 -2
- package/lib/rules/utils/ast-utils.js +2 -2
- package/lib/shared/deprecation-warnings.js +12 -3
- package/lib/shared/string-utils.js +22 -0
- package/lib/source-code/source-code.js +6 -5
- package/lib/source-code/token-store/utils.js +4 -12
- package/messages/{all-files-ignored.txt → all-files-ignored.js} +10 -2
- package/messages/extend-config-missing.js +13 -0
- package/messages/failed-to-read-json.js +11 -0
- package/messages/file-not-found.js +10 -0
- package/messages/{no-config-found.txt → no-config-found.js} +9 -1
- package/messages/plugin-conflict.js +22 -0
- package/messages/plugin-invalid.js +16 -0
- package/messages/plugin-missing.js +19 -0
- package/messages/{print-config-with-directory-path.txt → print-config-with-directory-path.js} +6 -0
- package/messages/whitespace-found.js +11 -0
- package/package.json +10 -13
- package/lib/cli-engine/formatters/html-template-message.html +0 -8
- package/lib/cli-engine/formatters/html-template-page.html +0 -115
- package/lib/cli-engine/formatters/html-template-result.html +0 -6
- package/messages/extend-config-missing.txt +0 -5
- package/messages/failed-to-read-json.txt +0 -3
- package/messages/file-not-found.txt +0 -2
- package/messages/plugin-conflict.txt +0 -7
- package/messages/plugin-invalid.txt +0 -8
- package/messages/plugin-missing.txt +0 -11
- package/messages/whitespace-found.txt +0 -3
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,57 @@
|
|
1
|
+
v7.28.0 - June 4, 2021
|
2
|
+
|
3
|
+
* [`1237705`](https://github.com/eslint/eslint/commit/1237705dd08c209c5e3136045ec51a4ba87a3abe) Upgrade: @eslint/eslintrc to 0.4.2 (#14672) (Milos Djermanovic)
|
4
|
+
* [`123fb86`](https://github.com/eslint/eslint/commit/123fb8648731c2c23313c544ffa1872d3024fe68) Docs: Add Feedback Needed triage description (#14670) (Nicholas C. Zakas)
|
5
|
+
* [`c545163`](https://github.com/eslint/eslint/commit/c5451635b4e89827cfc8d8d77083647c74506e42) Update: support multiline /*eslint-env*/ directives (fixes #14652) (#14660) (薛定谔的猫)
|
6
|
+
* [`8d1e75a`](https://github.com/eslint/eslint/commit/8d1e75a31b3e3d67130709a219bdd07ce6f3cf74) Upgrade: glob-parent version in package.json (#14658) (Hamza Najeeb)
|
7
|
+
* [`1f048cb`](https://github.com/eslint/eslint/commit/1f048cb0eec660d2052f1758f4b2ad7b1cb424e1) Fix: no-implicit-coercion false positive with `String()` (fixes #14623) (#14641) (Milos Djermanovic)
|
8
|
+
* [`d709abf`](https://github.com/eslint/eslint/commit/d709abfdde087325d4578b6709dc61040b8ca9d8) Chore: fix comment location in no-unused-vars (#14648) (Milos Djermanovic)
|
9
|
+
* [`e44ce0a`](https://github.com/eslint/eslint/commit/e44ce0a8acfaad513c385150c25e76e82a1b8f12) Fix: no-duplicate-imports allow unmergeable (fixes #12758, fixes #12760) (#14238) (Soufiane Boutahlil)
|
10
|
+
* [`bb66a3d`](https://github.com/eslint/eslint/commit/bb66a3d91af426dac9a7ffdbe47bdbbc0ffd4dd7) New: add `getPhysicalFilename()` method to rule context (fixes #11989) (#14616) (Nitin Kumar)
|
11
|
+
* [`2e43dac`](https://github.com/eslint/eslint/commit/2e43dacd24337a82d4184fac9b44d497675f46ef) Docs: fix `no-sequences` example (#14643) (Nitin Kumar)
|
12
|
+
* [`958ff4e`](https://github.com/eslint/eslint/commit/958ff4e8a5102f204f1484d09985e28a79790996) Docs: add note for arrow functions in no-seq rule (#14578) (Nitin Kumar)
|
13
|
+
* [`e4f111b`](https://github.com/eslint/eslint/commit/e4f111b67d114adbf76a9c9dbb18fa4f49bc91b6) Fix: arrow-body-style crash with object pattern (fixes #14633) (#14635) (Milos Djermanovic)
|
14
|
+
* [`ec28b5a`](https://github.com/eslint/eslint/commit/ec28b5a2bdc69f34ce29d670f5e84d2446774a00) Chore: upgrade eslint-plugin-eslint-plugin (#14590) (薛定谔的猫)
|
15
|
+
* [`85a2725`](https://github.com/eslint/eslint/commit/85a2725b1fade5538e727102d9701ccb503e54d4) Docs: Update README team and sponsors (ESLint Jenkins)
|
16
|
+
|
17
|
+
v7.27.0 - May 21, 2021
|
18
|
+
|
19
|
+
* [`2c0868c`](https://github.com/eslint/eslint/commit/2c0868cbeadc9f42716fa1178ebdc6b4cee6d31e) Chore: merge all html formatter files into `html.js` (#14612) (Milos Djermanovic)
|
20
|
+
* [`9e9b5e0`](https://github.com/eslint/eslint/commit/9e9b5e07475564813b62cd1d7562a93c5fb4bc74) Update: no-unused-vars false negative with comma operator (fixes #14325) (#14354) (Nitin Kumar)
|
21
|
+
* [`afe9569`](https://github.com/eslint/eslint/commit/afe95693e1e4316a1c6f01d39345061d4c5921c7) Chore: use includes instead of indexOf (#14607) (Mikhail Bodrov)
|
22
|
+
* [`c0f418e`](https://github.com/eslint/eslint/commit/c0f418e2476df98519bc156b81d20431984e8704) Chore: Remove lodash (#14287) (Stephen Wade)
|
23
|
+
* [`52655dd`](https://github.com/eslint/eslint/commit/52655dd54925ee02af2ba3a0ebc09de959ae3101) Update: no-restricted-imports custom message for patterns (fixes #11843) (#14580) (Alex Holden)
|
24
|
+
* [`967b1c4`](https://github.com/eslint/eslint/commit/967b1c4ceca8f5248378477da94ff118dafaa647) Chore: Fix typo in large.js (#14589) (Ikko Ashimine)
|
25
|
+
* [`2466a05`](https://github.com/eslint/eslint/commit/2466a05160de60958457d984b79fd445c12ebc98) Sponsors: Sync README with website (ESLint Jenkins)
|
26
|
+
* [`fe29f18`](https://github.com/eslint/eslint/commit/fe29f18227fd02fd7c3da033417d621275b00d0a) Sponsors: Sync README with website (ESLint Jenkins)
|
27
|
+
* [`086c1d6`](https://github.com/eslint/eslint/commit/086c1d6e8593cf8e7851daa8f2a890c213cf6999) Chore: add more test cases for `no-sequences` (#14579) (Nitin Kumar)
|
28
|
+
* [`6a2ced8`](https://github.com/eslint/eslint/commit/6a2ced892c0dc43fa4942293b9f1c4b9151c3741) Docs: Update README team and sponsors (ESLint Jenkins)
|
29
|
+
|
30
|
+
v7.26.0 - May 7, 2021
|
31
|
+
|
32
|
+
* [`aaf65e6`](https://github.com/eslint/eslint/commit/aaf65e629adb74401092c3ccc9cb4e4bd1c8609b) Upgrade: eslintrc for ModuleResolver fix (#14577) (Brandon Mills)
|
33
|
+
* [`ae6dbd1`](https://github.com/eslint/eslint/commit/ae6dbd148aaca83e4bd04b9351b54029c50fac8a) Fix: track variables, not names in require-atomic-updates (fixes #14208) (#14282) (Patrick Ahmetovic)
|
34
|
+
* [`6a86e50`](https://github.com/eslint/eslint/commit/6a86e5018a3733049c09261bcabae422fbea893d) Chore: remove loose-parser tests (fixes #14315) (#14569) (Milos Djermanovic)
|
35
|
+
* [`ee3a3ea`](https://github.com/eslint/eslint/commit/ee3a3ead893d185cc4b1ae9041940cb0968767e1) Fix: create `.eslintrc.cjs` for `module` type (#14304) (Nitin Kumar)
|
36
|
+
* [`6791dec`](https://github.com/eslint/eslint/commit/6791decfc58b7b09cfd0aabd15a3d14148aae073) Docs: fix example for require-atomic-updates (#14562) (Milos Djermanovic)
|
37
|
+
* [`388eb7e`](https://github.com/eslint/eslint/commit/388eb7e14039b8951462b311d6121002ca5232cb) Sponsors: Sync README with website (ESLint Jenkins)
|
38
|
+
* [`f071d1e`](https://github.com/eslint/eslint/commit/f071d1ef91286bf2e3fb63d9b679ff7702819a1e) Update: Add automated suggestion to `radix` rule for parsing decimals (#14291) (Bryan Mishkin)
|
39
|
+
* [`0b6a3f3`](https://github.com/eslint/eslint/commit/0b6a3f31e6e78825114f82d4e0aed9cd72f784ac) New: Include XO style guide in `eslint --init` (#14193) (Federico Brigante)
|
40
|
+
|
41
|
+
v7.25.0 - April 23, 2021
|
42
|
+
|
43
|
+
* [`5df5e4a`](https://github.com/eslint/eslint/commit/5df5e4a9976964fcf4dc67e241d4e22ec1370fe0) Update: highlight last write reference for no-unused-vars (fixes #14324) (#14335) (Nitin Kumar)
|
44
|
+
* [`0023872`](https://github.com/eslint/eslint/commit/00238729329b86b4f8af89ebfe278da3095a6075) Docs: Add deprecated note to `working-with-rules-deprecated` page (#14344) (Michael Novotny)
|
45
|
+
* [`36fca70`](https://github.com/eslint/eslint/commit/36fca70fa29ab65080076810de98e09133254b8a) Chore: Upgrade eslump to 3.0.0 (#14350) (Stephen Wade)
|
46
|
+
* [`59b689a`](https://github.com/eslint/eslint/commit/59b689a0b3fa658b8380431007cc1facb4617a3b) Chore: add node v16 (#14355) (薛定谔的猫)
|
47
|
+
* [`35a1f5e`](https://github.com/eslint/eslint/commit/35a1f5e967e4e87360d3e70d3fca0f7adeeaa1d7) Sponsors: Sync README with website (ESLint Jenkins)
|
48
|
+
* [`fb0a92b`](https://github.com/eslint/eslint/commit/fb0a92b3d2fed4a17bc39b7f02c540cd1175ec7d) Chore: rename misspelled identifier in test (#14346) (Tobias Nießen)
|
49
|
+
* [`f2babb1`](https://github.com/eslint/eslint/commit/f2babb1069194166e0ac1afd1269bbd06ac299b6) Docs: update pull request template (#14336) (Nitin Kumar)
|
50
|
+
* [`02dde29`](https://github.com/eslint/eslint/commit/02dde29eeb523ca24bc4ae7797d38627c3ba9fe9) Docs: Fix anchor in 'docs/developer-guide/working-with-rules.md' (#14332) (Nate-Wilkins)
|
51
|
+
* [`07d14c3`](https://github.com/eslint/eslint/commit/07d14c304c358fbc9c3d318e1377d2b2bda9179f) Chore: remove extraneous command from lint-staged config (#14314) (James George)
|
52
|
+
* [`41b3570`](https://github.com/eslint/eslint/commit/41b3570b6c014c534bb3208ed00050fd99842101) Update: lint code block with same extension but different content (#14227) (JounQin)
|
53
|
+
* [`eb29996`](https://github.com/eslint/eslint/commit/eb299966bdc3920dd2c6f9774d95103d242fc409) Docs: add more examples with arrow functions for no-sequences rule (#14313) (Nitin Kumar)
|
54
|
+
|
1
55
|
v7.24.0 - April 9, 2021
|
2
56
|
|
3
57
|
* [`0c346c8`](https://github.com/eslint/eslint/commit/0c346c87fa83c6d1184fdafb9c0748c2e15a423d) Chore: ignore `pnpm-lock.yaml` (#14303) (Nitin Kumar)
|
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
|
薛定谔的猫
|
@@ -281,9 +281,9 @@ The following companies, organizations, and individuals support ESLint's ongoing
|
|
281
281
|
<!--sponsorsstart-->
|
282
282
|
<h3>Platinum Sponsors</h3>
|
283
283
|
<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.
|
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://substack.com/"><img src="https://avatars.githubusercontent.com/u/53023767?v=4" alt="Substack" height="96"></a></p><h3>Silver Sponsors</h3>
|
285
285
|
<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://
|
286
|
+
<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
287
|
<!--sponsorsend-->
|
288
288
|
|
289
289
|
## <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
|
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
|
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
|
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
|
16
|
-
const
|
17
|
-
|
11
|
+
const encodeHTML = (function() {
|
12
|
+
const encodeHTMLRules = {
|
13
|
+
"&": "&",
|
14
|
+
"<": "<",
|
15
|
+
">": ">",
|
16
|
+
'"': """,
|
17
|
+
"'": "'"
|
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
|
-
|
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
|
|
package/lib/init/autoconfig.js
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const
|
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 (
|
332
|
+
if (equal(recConfig.rules[ruleId], newConfig.rules[ruleId])) {
|
333
333
|
delete newConfig.rules[ruleId];
|
334
334
|
}
|
335
335
|
});
|
package/lib/init/config-file.js
CHANGED
@@ -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
|
}
|
package/lib/init/npm-utils.js
CHANGED
@@ -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
|
-
|
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":
|
package/lib/linter/linter.js
CHANGED
@@ -15,7 +15,7 @@ const
|
|
15
15
|
eslintScope = require("eslint-scope"),
|
16
16
|
evk = require("eslint-visitor-keys"),
|
17
17
|
espree = require("espree"),
|
18
|
-
|
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"),
|
@@ -444,7 +444,7 @@ function normalizeEcmaVersion(ecmaVersion) {
|
|
444
444
|
return ecmaVersion >= 2015 ? ecmaVersion - 2009 : ecmaVersion;
|
445
445
|
}
|
446
446
|
|
447
|
-
const eslintEnvPattern = /\/\*\s*eslint-env\s(.+?)\*\//
|
447
|
+
const eslintEnvPattern = /\/\*\s*eslint-env\s(.+?)\*\//gsu;
|
448
448
|
|
449
449
|
/**
|
450
450
|
* Checks whether or not there is a comment which has "eslint-env *" in a given text.
|
@@ -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) =>
|
533
|
-
const mergedParserOptions =
|
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) {
|
@@ -828,9 +828,10 @@ const BASE_TRAVERSAL_CONTEXT = Object.freeze(
|
|
828
828
|
* @param {string} filename The reported filename of the code
|
829
829
|
* @param {boolean} disableFixes If true, it doesn't make `fix` properties.
|
830
830
|
* @param {string | undefined} cwd cwd of the cli
|
831
|
+
* @param {string} physicalFilename The full path of the file on disk without any code block information
|
831
832
|
* @returns {Problem[]} An array of reported problems
|
832
833
|
*/
|
833
|
-
function runRules(sourceCode, configuredRules, ruleMapper, parserOptions, parserName, settings, filename, disableFixes, cwd) {
|
834
|
+
function runRules(sourceCode, configuredRules, ruleMapper, parserOptions, parserName, settings, filename, disableFixes, cwd, physicalFilename) {
|
834
835
|
const emitter = createEmitter();
|
835
836
|
const nodeQueue = [];
|
836
837
|
let currentNode = sourceCode.ast;
|
@@ -859,6 +860,7 @@ function runRules(sourceCode, configuredRules, ruleMapper, parserOptions, parser
|
|
859
860
|
getDeclaredVariables: sourceCode.scopeManager.getDeclaredVariables.bind(sourceCode.scopeManager),
|
860
861
|
getCwd: () => cwd,
|
861
862
|
getFilename: () => filename,
|
863
|
+
getPhysicalFilename: () => physicalFilename || filename,
|
862
864
|
getScope: () => getScope(sourceCode.scopeManager, currentNode),
|
863
865
|
getSourceCode: () => sourceCode,
|
864
866
|
markVariableAsUsed: name => markVariableAsUsed(sourceCode.scopeManager, currentNode, parserOptions, name),
|
@@ -1181,7 +1183,8 @@ class Linter {
|
|
1181
1183
|
settings,
|
1182
1184
|
options.filename,
|
1183
1185
|
options.disableFixes,
|
1184
|
-
slots.cwd
|
1186
|
+
slots.cwd,
|
1187
|
+
providedOptions.physicalFilename
|
1185
1188
|
);
|
1186
1189
|
} catch (err) {
|
1187
1190
|
err.message += `\nOccurred while linting ${options.filename}`;
|
@@ -1284,9 +1287,12 @@ class Linter {
|
|
1284
1287
|
_verifyWithProcessor(textOrSourceCode, config, options, configForRecursive) {
|
1285
1288
|
const filename = options.filename || "<input>";
|
1286
1289
|
const filenameToExpose = normalizeFilename(filename);
|
1290
|
+
const physicalFilename = options.physicalFilename || filenameToExpose;
|
1287
1291
|
const text = ensureText(textOrSourceCode);
|
1288
1292
|
const preprocess = options.preprocess || (rawText => [rawText]);
|
1289
|
-
|
1293
|
+
|
1294
|
+
// TODO(stephenwade): Replace this with array.flat() when we drop support for Node v10
|
1295
|
+
const postprocess = options.postprocess || (array => [].concat(...array));
|
1290
1296
|
const filterCodeBlock =
|
1291
1297
|
options.filterCodeBlock ||
|
1292
1298
|
(blockFilename => blockFilename.endsWith(".js"));
|
@@ -1308,13 +1314,13 @@ class Linter {
|
|
1308
1314
|
return [];
|
1309
1315
|
}
|
1310
1316
|
|
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.");
|
1317
|
+
// Resolve configuration again if the file content or extension was changed.
|
1318
|
+
if (configForRecursive && (text !== blockText || path.extname(blockName) !== originalExtname)) {
|
1319
|
+
debug("Resolving configuration again because the file content or extension was changed.");
|
1314
1320
|
return this._verifyWithConfigArray(
|
1315
1321
|
blockText,
|
1316
1322
|
configForRecursive,
|
1317
|
-
{ ...options, filename: blockName }
|
1323
|
+
{ ...options, filename: blockName, physicalFilename }
|
1318
1324
|
);
|
1319
1325
|
}
|
1320
1326
|
|
@@ -1322,7 +1328,7 @@ class Linter {
|
|
1322
1328
|
return this._verifyWithoutProcessors(
|
1323
1329
|
blockText,
|
1324
1330
|
config,
|
1325
|
-
{ ...options, filename: blockName }
|
1331
|
+
{ ...options, filename: blockName, physicalFilename }
|
1326
1332
|
);
|
1327
1333
|
});
|
1328
1334
|
|