eslint 7.21.0 → 7.25.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 +62 -0
- package/README.md +3 -3
- package/lib/cli-engine/formatters/html.js +2 -2
- package/lib/cli-engine/lint-result-cache.js +0 -1
- package/lib/cli.js +10 -3
- package/lib/linter/linter.js +3 -3
- package/lib/linter/report-translator.js +17 -0
- package/lib/options.js +47 -0
- package/lib/rule-tester/rule-tester.js +2 -2
- package/lib/rules/eol-last.js +1 -1
- package/lib/rules/lines-around-comment.js +3 -4
- package/lib/rules/max-lines.js +1 -1
- package/lib/rules/no-implicit-coercion.js +37 -0
- package/lib/rules/no-mixed-operators.js +6 -23
- package/lib/rules/no-multi-assign.js +15 -2
- package/lib/rules/no-sequences.js +27 -8
- package/lib/rules/no-unused-vars.js +26 -13
- package/lib/rules/object-curly-newline.js +2 -2
- package/lib/shared/runtime-info.js +4 -3
- package/package.json +15 -17
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,65 @@
|
|
1
|
+
v7.25.0 - April 23, 2021
|
2
|
+
|
3
|
+
* [`5df5e4a`](https://github.com/eslint/eslint/commit/5df5e4a9976964fcf4dc67e241d4e22ec1370fe0) Update: highlight last write reference for no-unused-vars (fixes #14324) (#14335) (Nitin Kumar)
|
4
|
+
* [`0023872`](https://github.com/eslint/eslint/commit/00238729329b86b4f8af89ebfe278da3095a6075) Docs: Add deprecated note to `working-with-rules-deprecated` page (#14344) (Michael Novotny)
|
5
|
+
* [`36fca70`](https://github.com/eslint/eslint/commit/36fca70fa29ab65080076810de98e09133254b8a) Chore: Upgrade eslump to 3.0.0 (#14350) (Stephen Wade)
|
6
|
+
* [`59b689a`](https://github.com/eslint/eslint/commit/59b689a0b3fa658b8380431007cc1facb4617a3b) Chore: add node v16 (#14355) (薛定谔的猫)
|
7
|
+
* [`35a1f5e`](https://github.com/eslint/eslint/commit/35a1f5e967e4e87360d3e70d3fca0f7adeeaa1d7) Sponsors: Sync README with website (ESLint Jenkins)
|
8
|
+
* [`fb0a92b`](https://github.com/eslint/eslint/commit/fb0a92b3d2fed4a17bc39b7f02c540cd1175ec7d) Chore: rename misspelled identifier in test (#14346) (Tobias Nießen)
|
9
|
+
* [`f2babb1`](https://github.com/eslint/eslint/commit/f2babb1069194166e0ac1afd1269bbd06ac299b6) Docs: update pull request template (#14336) (Nitin Kumar)
|
10
|
+
* [`02dde29`](https://github.com/eslint/eslint/commit/02dde29eeb523ca24bc4ae7797d38627c3ba9fe9) Docs: Fix anchor in 'docs/developer-guide/working-with-rules.md' (#14332) (Nate-Wilkins)
|
11
|
+
* [`07d14c3`](https://github.com/eslint/eslint/commit/07d14c304c358fbc9c3d318e1377d2b2bda9179f) Chore: remove extraneous command from lint-staged config (#14314) (James George)
|
12
|
+
* [`41b3570`](https://github.com/eslint/eslint/commit/41b3570b6c014c534bb3208ed00050fd99842101) Update: lint code block with same extension but different content (#14227) (JounQin)
|
13
|
+
* [`eb29996`](https://github.com/eslint/eslint/commit/eb299966bdc3920dd2c6f9774d95103d242fc409) Docs: add more examples with arrow functions for no-sequences rule (#14313) (Nitin Kumar)
|
14
|
+
|
15
|
+
v7.24.0 - April 9, 2021
|
16
|
+
|
17
|
+
* [`0c346c8`](https://github.com/eslint/eslint/commit/0c346c87fa83c6d1184fdafb9c0748c2e15a423d) Chore: ignore `pnpm-lock.yaml` (#14303) (Nitin Kumar)
|
18
|
+
* [`f06ecdf`](https://github.com/eslint/eslint/commit/f06ecdf78b6d6f366434d73a6acfe7041d575223) Update: Add disallowTemplateShorthand option in no-implicit-coercion (#13579) (Remco Haszing)
|
19
|
+
* [`71a80e3`](https://github.com/eslint/eslint/commit/71a80e38aab2dada01b808ed43d9b0e806d863c4) Docs: fix broken links in Node.js API docs toc (#14296) (u-sho (Shouhei Uechi))
|
20
|
+
* [`bd46dc4`](https://github.com/eslint/eslint/commit/bd46dc4647faa4c3bbb5f60d4c00616a64081398) Docs: Fix incorrect reference to "braces" in arrow-parens (#14300) (emclain)
|
21
|
+
* [`0d6235e`](https://github.com/eslint/eslint/commit/0d6235ea201b8b90761ee69bb4d46ae18899c28d) Docs: update header in max-lines (#14273) (Shinigami)
|
22
|
+
* [`70c9216`](https://github.com/eslint/eslint/commit/70c92164017238e329e3a2d1654a0227b8f953f7) Docs: Update issue triage to include blocked column (#14275) (Nicholas C. Zakas)
|
23
|
+
* [`abca186`](https://github.com/eslint/eslint/commit/abca186a845200fd7728c4e5f220973e640054f9) Docs: Fix typo in suggestions section (#14293) (Kevin Partington)
|
24
|
+
* [`c4d8b0d`](https://github.com/eslint/eslint/commit/c4d8b0db62b859e721105d4bc0f4044ce346995e) Fix: no-unused-vars ignoreRestSiblings check assignments (fixes #14163) (#14264) (YeonJuan)
|
25
|
+
* [`b51d077`](https://github.com/eslint/eslint/commit/b51d0778d76c2aa27578caca3ea82c867dced3e4) Update: add ignoreNonDeclaration to no-multi-assign rule (fixes #12545) (#14185) (t-mangoe)
|
26
|
+
* [`c981fb1`](https://github.com/eslint/eslint/commit/c981fb1994cd04914042ced1980aa86b68ba7be9) Chore: Upgrade mocha to 8.3.2 (#14278) (Stephen Wade)
|
27
|
+
* [`147fc04`](https://github.com/eslint/eslint/commit/147fc045e699811fab33dddf77498324ddf7e9d6) Docs: Fix `repro:needed` label in bug report template (#14285) (Milos Djermanovic)
|
28
|
+
* [`e1cfde9`](https://github.com/eslint/eslint/commit/e1cfde93eec71a15c2df1ad660a7a6171204ba80) Docs: Update bug report template (#14276) (Nicholas C. Zakas)
|
29
|
+
* [`c85c2f1`](https://github.com/eslint/eslint/commit/c85c2f1138a9e952655f19ee780ab0c8e35431a8) Docs: Add fatal to Node.js API LintMessage type (#14251) (Brandon Mills)
|
30
|
+
|
31
|
+
v7.23.0 - March 26, 2021
|
32
|
+
|
33
|
+
* [`687ccae`](https://github.com/eslint/eslint/commit/687ccae517b8b815cf21e948f80d22e2bf118a99) Update: add option "allowInParentheses" to no-sequences (fixes #14197) (#14199) (Daniel Rentz)
|
34
|
+
* [`dbf2529`](https://github.com/eslint/eslint/commit/dbf252964d9a2b8957cfe0aed5c87a6d4a5cce24) Sponsors: Sync README with website (ESLint Jenkins)
|
35
|
+
* [`4bdf2c1`](https://github.com/eslint/eslint/commit/4bdf2c1dade27625b601080687ce95b8c229e491) Sponsors: Sync README with website (ESLint Jenkins)
|
36
|
+
* [`49d1697`](https://github.com/eslint/eslint/commit/49d16977d969070e5240074e76036f56631a90d3) Chore: Upgrade eslint-plugin-jsdoc to v25 and remove --legacy-peer-deps (#14244) (Brandon Mills)
|
37
|
+
* [`43f1685`](https://github.com/eslint/eslint/commit/43f1685356b9840e09631843ad9ccf0440a498b0) Update: `--quiet` should not supress `--max-warnings` (fixes #14202) (#14242) (Milos Djermanovic)
|
38
|
+
* [`909c727`](https://github.com/eslint/eslint/commit/909c7271b8d294bd884827ad5df02615b6ec5e82) Docs: Add valid example that shows vars in a block scope (#14230) (Ed S)
|
39
|
+
* [`28583eb`](https://github.com/eslint/eslint/commit/28583eb8ada20f32579841bec3fbd60a018d5931) Fix: no-mixed-operators false positives with `? :` (fixes #14223) (#14226) (Milos Djermanovic)
|
40
|
+
* [`a99eb2d`](https://github.com/eslint/eslint/commit/a99eb2dc2a297d16e40a9feef3956668716c4eb5) Fix: Clarify line breaks in object-curly-newline (fixes #14024) (#14063) (armin yahya)
|
41
|
+
* [`8984c91`](https://github.com/eslint/eslint/commit/8984c91372e64d1e8dd2ce21b87b80977d57bff9) Update: eslint --env-info output os info (#14059) (薛定谔的猫)
|
42
|
+
* [`2a79306`](https://github.com/eslint/eslint/commit/2a79306f71c4c80f1e3e73be2a140d07cf55c63d) Sponsors: Sync README with website (ESLint Jenkins)
|
43
|
+
* [`ebd7026`](https://github.com/eslint/eslint/commit/ebd70263f6e6fe597613d90f4b8de84710c2f3d6) Docs: Fix typo (#14225) (Greg Finley)
|
44
|
+
* [`a2013fc`](https://github.com/eslint/eslint/commit/a2013fcf996c8651bc760df21d900442828a6884) Sponsors: Sync README with website (ESLint Jenkins)
|
45
|
+
|
46
|
+
v7.22.0 - March 12, 2021
|
47
|
+
|
48
|
+
* [`3a432d8`](https://github.com/eslint/eslint/commit/3a432d82b3a5710aff7da20302fe0b94fedc46c2) Docs: Improve documentation for indent rule (#14168) (Serkan Özel)
|
49
|
+
* [`f62ec8d`](https://github.com/eslint/eslint/commit/f62ec8d30d925e70e4d0d40640857c587ac2e116) Update: throw error when fix range is invalid (#14142) (Jacob Bandes-Storch)
|
50
|
+
* [`0eecad2`](https://github.com/eslint/eslint/commit/0eecad271358f753730741fcfcb2f7cc915c1fa7) Upgrade: Update lodash in package.json to V 4.17.21 (#14159) (Basem Al-Nabulsi)
|
51
|
+
* [`5ad91aa`](https://github.com/eslint/eslint/commit/5ad91aa7df3d6bc185786e6eccd9e055fd951055) Update: report es2021 globals in no-extend-native (refs #13602) (#14177) (Milos Djermanovic)
|
52
|
+
* [`c295581`](https://github.com/eslint/eslint/commit/c295581aca4e08ec4ae8e5ee5726a6f454a3ee26) Chore: remove leftover JSDoc from lint-result-cache (#14176) (Milos Djermanovic)
|
53
|
+
* [`0d541f9`](https://github.com/eslint/eslint/commit/0d541f9d9d58966372e2055a8f69fb9483d56a4b) Chore: Reduce lodash usage (#14178) (Stephen Wade)
|
54
|
+
* [`27a67d7`](https://github.com/eslint/eslint/commit/27a67d71ffa9bbd7af02ae448844e127bcf956dc) Sponsors: Sync README with website (ESLint Jenkins)
|
55
|
+
* [`459d821`](https://github.com/eslint/eslint/commit/459d821f4a599501ceb002f9d7a5034fc45ffbb0) Chore: upgrade dependencies of browser test (#14127) (Pig Fang)
|
56
|
+
* [`ebfb63a`](https://github.com/eslint/eslint/commit/ebfb63a682004a008f2707dbad616e5ae1630b2c) Sponsors: Sync README with website (ESLint Jenkins)
|
57
|
+
* [`3ba029f`](https://github.com/eslint/eslint/commit/3ba029fbffd44068be93254890fc2aec3e92c212) Docs: Remove Extraneous Dash (#14164) (Danny Hurlburt)
|
58
|
+
* [`6f4540e`](https://github.com/eslint/eslint/commit/6f4540ea7ea39775906526506fd7abd7ea97610c) Sponsors: Sync README with website (ESLint Jenkins)
|
59
|
+
* [`ddf361c`](https://github.com/eslint/eslint/commit/ddf361ca2a2a01a9974f421e5f62270df282d0e8) Docs: Fix Formatting (#14154) (Danny Hurlburt)
|
60
|
+
* [`c0d2ac1`](https://github.com/eslint/eslint/commit/c0d2ac16f8f9c75c62c78e9fe6a24a25ba0d7828) Sponsors: Sync README with website (ESLint Jenkins)
|
61
|
+
* [`a8df03e`](https://github.com/eslint/eslint/commit/a8df03efe3bc47665d2112c2cdd5bead337d475d) Docs: Clarify triage process (#14117) (Nicholas C. Zakas)
|
62
|
+
|
1
63
|
v7.21.0 - February 27, 2021
|
2
64
|
|
3
65
|
* [`3cd5440`](https://github.com/eslint/eslint/commit/3cd5440b94d5fa4f11a09f50b685f6150f0c2d41) Upgrade: @eslint/eslintrc to 0.4.0 (#14147) (Brandon Mills)
|
package/README.md
CHANGED
@@ -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.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://
|
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
|
286
|
-
<p><a href="https://
|
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>
|
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://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>
|
287
287
|
<!--sponsorsend-->
|
288
288
|
|
289
289
|
## <a name="technology-sponsors"></a>Technology Sponsors
|
@@ -72,7 +72,7 @@ function renderMessages(messages, parentIndex, rulesMeta) {
|
|
72
72
|
* @param {Object} message Message.
|
73
73
|
* @returns {string} HTML (table row) describing a message.
|
74
74
|
*/
|
75
|
-
return
|
75
|
+
return messages.map(message => {
|
76
76
|
const lineNumber = message.line || 0;
|
77
77
|
const columnNumber = message.column || 0;
|
78
78
|
let ruleUrl;
|
@@ -103,7 +103,7 @@ function renderMessages(messages, parentIndex, rulesMeta) {
|
|
103
103
|
* @returns {string} HTML string describing the results.
|
104
104
|
*/
|
105
105
|
function renderResults(results, rulesMeta) {
|
106
|
-
return
|
106
|
+
return results.map((result, index) => resultTemplate({
|
107
107
|
index,
|
108
108
|
color: renderColor(result.errorCount, result.warningCount),
|
109
109
|
filePath: result.filePath,
|
@@ -67,7 +67,6 @@ class LintResultCache {
|
|
67
67
|
/**
|
68
68
|
* Creates a new LintResultCache instance.
|
69
69
|
* @param {string} cacheFileLocation The cache file location.
|
70
|
-
* configuration lookup by file path).
|
71
70
|
* @param {"metadata" | "content"} cacheStrategy The cache strategy to use.
|
72
71
|
*/
|
73
72
|
constructor(cacheFileLocation, cacheStrategy) {
|
package/lib/cli.js
CHANGED
@@ -32,6 +32,7 @@ const debug = require("debug")("eslint:cli");
|
|
32
32
|
/** @typedef {import("./eslint/eslint").ESLintOptions} ESLintOptions */
|
33
33
|
/** @typedef {import("./eslint/eslint").LintMessage} LintMessage */
|
34
34
|
/** @typedef {import("./eslint/eslint").LintResult} LintResult */
|
35
|
+
/** @typedef {import("./options").ParsedCLIOptions} ParsedCLIOptions */
|
35
36
|
|
36
37
|
//------------------------------------------------------------------------------
|
37
38
|
// Helpers
|
@@ -54,7 +55,7 @@ function quietFixPredicate(message) {
|
|
54
55
|
|
55
56
|
/**
|
56
57
|
* Translates the CLI options into the options expected by the CLIEngine.
|
57
|
-
* @param {
|
58
|
+
* @param {ParsedCLIOptions} cliOptions The CLI options to translate.
|
58
59
|
* @returns {ESLintOptions} The options object for the CLIEngine.
|
59
60
|
* @private
|
60
61
|
*/
|
@@ -221,6 +222,8 @@ const cli = {
|
|
221
222
|
if (Array.isArray(args)) {
|
222
223
|
debug("CLI args: %o", args.slice(2));
|
223
224
|
}
|
225
|
+
|
226
|
+
/** @type {ParsedCLIOptions} */
|
224
227
|
let options;
|
225
228
|
|
226
229
|
try {
|
@@ -301,12 +304,16 @@ const cli = {
|
|
301
304
|
await ESLint.outputFixes(results);
|
302
305
|
}
|
303
306
|
|
307
|
+
let resultsToPrint = results;
|
308
|
+
|
304
309
|
if (options.quiet) {
|
305
310
|
debug("Quiet mode enabled - filtering out warnings");
|
306
|
-
|
311
|
+
resultsToPrint = ESLint.getErrorResults(resultsToPrint);
|
307
312
|
}
|
308
313
|
|
309
|
-
if (await printResults(engine,
|
314
|
+
if (await printResults(engine, resultsToPrint, options.format, options.outputFile)) {
|
315
|
+
|
316
|
+
// Errors and warnings from the original unfiltered results should determine the exit code
|
310
317
|
const { errorCount, warningCount } = countErrors(results);
|
311
318
|
const tooManyWarnings =
|
312
319
|
options.maxWarnings >= 0 && warningCount > options.maxWarnings;
|
package/lib/linter/linter.js
CHANGED
@@ -1308,9 +1308,9 @@ class Linter {
|
|
1308
1308
|
return [];
|
1309
1309
|
}
|
1310
1310
|
|
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.");
|
1311
|
+
// Resolve configuration again if the file content or extension was changed.
|
1312
|
+
if (configForRecursive && (text !== blockText || path.extname(blockName) !== originalExtname)) {
|
1313
|
+
debug("Resolving configuration again because the file content or extension was changed.");
|
1314
1314
|
return this._verifyWithConfigArray(
|
1315
1315
|
blockText,
|
1316
1316
|
configForRecursive,
|
@@ -115,6 +115,17 @@ function normalizeReportLoc(descriptor) {
|
|
115
115
|
return descriptor.node.loc;
|
116
116
|
}
|
117
117
|
|
118
|
+
/**
|
119
|
+
* Check that a fix has a valid range.
|
120
|
+
* @param {Fix|null} fix The fix to validate.
|
121
|
+
* @returns {void}
|
122
|
+
*/
|
123
|
+
function assertValidFix(fix) {
|
124
|
+
if (fix) {
|
125
|
+
assert(fix.range && typeof fix.range[0] === "number" && typeof fix.range[1] === "number", `Fix has invalid range: ${JSON.stringify(fix, null, 2)}`);
|
126
|
+
}
|
127
|
+
}
|
128
|
+
|
118
129
|
/**
|
119
130
|
* Compares items in a fixes array by range.
|
120
131
|
* @param {Fix} a The first message.
|
@@ -133,6 +144,10 @@ function compareFixesByRange(a, b) {
|
|
133
144
|
* @returns {{text: string, range: number[]}} The merged fixes
|
134
145
|
*/
|
135
146
|
function mergeFixes(fixes, sourceCode) {
|
147
|
+
for (const fix of fixes) {
|
148
|
+
assertValidFix(fix);
|
149
|
+
}
|
150
|
+
|
136
151
|
if (fixes.length === 0) {
|
137
152
|
return null;
|
138
153
|
}
|
@@ -181,6 +196,8 @@ function normalizeFixes(descriptor, sourceCode) {
|
|
181
196
|
if (fix && Symbol.iterator in fix) {
|
182
197
|
return mergeFixes(Array.from(fix), sourceCode);
|
183
198
|
}
|
199
|
+
|
200
|
+
assertValidFix(fix);
|
184
201
|
return fix;
|
185
202
|
}
|
186
203
|
|
package/lib/options.js
CHANGED
@@ -11,6 +11,53 @@
|
|
11
11
|
|
12
12
|
const optionator = require("optionator");
|
13
13
|
|
14
|
+
//------------------------------------------------------------------------------
|
15
|
+
// Typedefs
|
16
|
+
//------------------------------------------------------------------------------
|
17
|
+
|
18
|
+
/**
|
19
|
+
* The options object parsed by Optionator.
|
20
|
+
* @typedef {Object} ParsedCLIOptions
|
21
|
+
* @property {boolean} cache Only check changed files
|
22
|
+
* @property {string} cacheFile Path to the cache file. Deprecated: use --cache-location
|
23
|
+
* @property {string} [cacheLocation] Path to the cache file or directory
|
24
|
+
* @property {"metadata" | "content"} cacheStrategy Strategy to use for detecting changed files in the cache
|
25
|
+
* @property {boolean} [color] Force enabling/disabling of color
|
26
|
+
* @property {string} [config] Use this configuration, overriding .eslintrc.* config options if present
|
27
|
+
* @property {boolean} debug Output debugging information
|
28
|
+
* @property {string[]} [env] Specify environments
|
29
|
+
* @property {boolean} envInfo Output execution environment information
|
30
|
+
* @property {boolean} errorOnUnmatchedPattern Prevent errors when pattern is unmatched
|
31
|
+
* @property {boolean} eslintrc Disable use of configuration from .eslintrc.*
|
32
|
+
* @property {string[]} [ext] Specify JavaScript file extensions
|
33
|
+
* @property {boolean} fix Automatically fix problems
|
34
|
+
* @property {boolean} fixDryRun Automatically fix problems without saving the changes to the file system
|
35
|
+
* @property {("problem" | "suggestion" | "layout")[]} [fixType] Specify the types of fixes to apply (problem, suggestion, layout)
|
36
|
+
* @property {string} format Use a specific output format
|
37
|
+
* @property {string[]} [global] Define global variables
|
38
|
+
* @property {boolean} [help] Show help
|
39
|
+
* @property {boolean} ignore Disable use of ignore files and patterns
|
40
|
+
* @property {string} [ignorePath] Specify path of ignore file
|
41
|
+
* @property {string[]} [ignorePattern] Pattern of files to ignore (in addition to those in .eslintignore)
|
42
|
+
* @property {boolean} init Run config initialization wizard
|
43
|
+
* @property {boolean} inlineConfig Prevent comments from changing config or rules
|
44
|
+
* @property {number} maxWarnings Number of warnings to trigger nonzero exit code
|
45
|
+
* @property {string} [outputFile] Specify file to write report to
|
46
|
+
* @property {string} [parser] Specify the parser to be used
|
47
|
+
* @property {Object} [parserOptions] Specify parser options
|
48
|
+
* @property {string[]} [plugin] Specify plugins
|
49
|
+
* @property {string} [printConfig] Print the configuration for the given file
|
50
|
+
* @property {boolean | undefined} reportUnusedDisableDirectives Adds reported errors for unused eslint-disable directives
|
51
|
+
* @property {string} [resolvePluginsRelativeTo] A folder where plugins should be resolved from, CWD by default
|
52
|
+
* @property {Object} [rule] Specify rules
|
53
|
+
* @property {string[]} [rulesdir] Use additional rules from this directory
|
54
|
+
* @property {boolean} stdin Lint code provided on <STDIN>
|
55
|
+
* @property {string} [stdinFilename] Specify filename to process STDIN as
|
56
|
+
* @property {boolean} quiet Report errors only
|
57
|
+
* @property {boolean} [version] Output the version number
|
58
|
+
* @property {string[]} _ Positional filenames or patterns
|
59
|
+
*/
|
60
|
+
|
14
61
|
//------------------------------------------------------------------------------
|
15
62
|
// Initialization and Public Interface
|
16
63
|
//------------------------------------------------------------------------------
|
@@ -427,12 +427,12 @@ class RuleTester {
|
|
427
427
|
scenarioErrors = [],
|
428
428
|
linter = this.linter;
|
429
429
|
|
430
|
-
if (
|
430
|
+
if (!test || typeof test !== "object") {
|
431
431
|
throw new TypeError(`Test Scenarios for rule ${ruleName} : Could not find test scenario object`);
|
432
432
|
}
|
433
433
|
|
434
434
|
requiredScenarios.forEach(scenarioType => {
|
435
|
-
if (
|
435
|
+
if (!test[scenarioType]) {
|
436
436
|
scenarioErrors.push(`Could not find any ${scenarioType} test scenarios`);
|
437
437
|
}
|
438
438
|
});
|
package/lib/rules/eol-last.js
CHANGED
@@ -8,8 +8,7 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const
|
12
|
-
astUtils = require("./utils/ast-utils");
|
11
|
+
const astUtils = require("./utils/ast-utils");
|
13
12
|
|
14
13
|
//------------------------------------------------------------------------------
|
15
14
|
// Helpers
|
@@ -347,7 +346,7 @@ module.exports = {
|
|
347
346
|
const nextTokenOrComment = sourceCode.getTokenAfter(token, { includeComments: true });
|
348
347
|
|
349
348
|
// check for newline before
|
350
|
-
if (!exceptionStartAllowed && before && !
|
349
|
+
if (!exceptionStartAllowed && before && !commentAndEmptyLines.includes(prevLineNum) &&
|
351
350
|
!(astUtils.isCommentToken(previousTokenOrComment) && astUtils.isTokenOnSameLine(previousTokenOrComment, token))) {
|
352
351
|
const lineStart = token.range[0] - token.loc.start.column;
|
353
352
|
const range = [lineStart, lineStart];
|
@@ -362,7 +361,7 @@ module.exports = {
|
|
362
361
|
}
|
363
362
|
|
364
363
|
// check for newline after
|
365
|
-
if (!exceptionEndAllowed && after && !
|
364
|
+
if (!exceptionEndAllowed && after && !commentAndEmptyLines.includes(nextLineNum) &&
|
366
365
|
!(astUtils.isCommentToken(nextTokenOrComment) && astUtils.isTokenOnSameLine(token, nextTokenOrComment))) {
|
367
366
|
context.report({
|
368
367
|
node: token,
|
package/lib/rules/max-lines.js
CHANGED
@@ -24,6 +24,7 @@ function parseOptions(options) {
|
|
24
24
|
boolean: "boolean" in options ? options.boolean : true,
|
25
25
|
number: "number" in options ? options.number : true,
|
26
26
|
string: "string" in options ? options.string : true,
|
27
|
+
disallowTemplateShorthand: "disallowTemplateShorthand" in options ? options.disallowTemplateShorthand : false,
|
27
28
|
allow: options.allow || []
|
28
29
|
};
|
29
30
|
}
|
@@ -180,6 +181,10 @@ module.exports = {
|
|
180
181
|
type: "boolean",
|
181
182
|
default: true
|
182
183
|
},
|
184
|
+
disallowTemplateShorthand: {
|
185
|
+
type: "boolean",
|
186
|
+
default: false
|
187
|
+
},
|
183
188
|
allow: {
|
184
189
|
type: "array",
|
185
190
|
items: {
|
@@ -299,6 +304,38 @@ module.exports = {
|
|
299
304
|
|
300
305
|
report(node, recommendation, true);
|
301
306
|
}
|
307
|
+
},
|
308
|
+
|
309
|
+
TemplateLiteral(node) {
|
310
|
+
if (!options.disallowTemplateShorthand) {
|
311
|
+
return;
|
312
|
+
}
|
313
|
+
|
314
|
+
// tag`${foo}`
|
315
|
+
if (node.parent.type === "TaggedTemplateExpression") {
|
316
|
+
return;
|
317
|
+
}
|
318
|
+
|
319
|
+
// `` or `${foo}${bar}`
|
320
|
+
if (node.expressions.length !== 1) {
|
321
|
+
return;
|
322
|
+
}
|
323
|
+
|
324
|
+
|
325
|
+
// `prefix${foo}`
|
326
|
+
if (node.quasis[0].value.cooked !== "") {
|
327
|
+
return;
|
328
|
+
}
|
329
|
+
|
330
|
+
// `${foo}postfix`
|
331
|
+
if (node.quasis[1].value.cooked !== "") {
|
332
|
+
return;
|
333
|
+
}
|
334
|
+
|
335
|
+
const code = sourceCode.getText(node.expressions[0]);
|
336
|
+
const recommendation = `String(${code})`;
|
337
|
+
|
338
|
+
report(node, recommendation, true);
|
302
339
|
}
|
303
340
|
};
|
304
341
|
}
|
@@ -161,17 +161,6 @@ module.exports = {
|
|
161
161
|
);
|
162
162
|
}
|
163
163
|
|
164
|
-
/**
|
165
|
-
* Checks whether the operator of a given node is mixed with a
|
166
|
-
* conditional expression.
|
167
|
-
* @param {ASTNode} node A node to check. This is a conditional
|
168
|
-
* expression node
|
169
|
-
* @returns {boolean} `true` if the node was mixed.
|
170
|
-
*/
|
171
|
-
function isMixedWithConditionalParent(node) {
|
172
|
-
return !astUtils.isParenthesised(sourceCode, node) && !astUtils.isParenthesised(sourceCode, node.test);
|
173
|
-
}
|
174
|
-
|
175
164
|
/**
|
176
165
|
* Gets the operator token of a given node.
|
177
166
|
* @param {ASTNode} node A node to check. This is a BinaryExpression
|
@@ -220,19 +209,13 @@ module.exports = {
|
|
220
209
|
* @returns {void}
|
221
210
|
*/
|
222
211
|
function check(node) {
|
223
|
-
if (
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
!shouldIgnore(node)
|
230
|
-
) {
|
231
|
-
reportBothOperators(node);
|
232
|
-
}
|
233
|
-
}
|
212
|
+
if (
|
213
|
+
TARGET_NODE_TYPE.test(node.parent.type) &&
|
214
|
+
isMixedWithParent(node) &&
|
215
|
+
!shouldIgnore(node)
|
216
|
+
) {
|
217
|
+
reportBothOperators(node);
|
234
218
|
}
|
235
|
-
|
236
219
|
}
|
237
220
|
|
238
221
|
return {
|
@@ -21,7 +21,16 @@ module.exports = {
|
|
21
21
|
url: "https://eslint.org/docs/rules/no-multi-assign"
|
22
22
|
},
|
23
23
|
|
24
|
-
schema: [
|
24
|
+
schema: [{
|
25
|
+
type: "object",
|
26
|
+
properties: {
|
27
|
+
ignoreNonDeclaration: {
|
28
|
+
type: "boolean",
|
29
|
+
default: false
|
30
|
+
}
|
31
|
+
},
|
32
|
+
additionalProperties: false
|
33
|
+
}],
|
25
34
|
|
26
35
|
messages: {
|
27
36
|
unexpectedChain: "Unexpected chained assignment."
|
@@ -33,10 +42,14 @@ module.exports = {
|
|
33
42
|
//--------------------------------------------------------------------------
|
34
43
|
// Public
|
35
44
|
//--------------------------------------------------------------------------
|
45
|
+
const options = context.options[0] || {
|
46
|
+
ignoreNonDeclaration: false
|
47
|
+
};
|
48
|
+
const targetParent = options.ignoreNonDeclaration ? ["VariableDeclarator"] : ["AssignmentExpression", "VariableDeclarator"];
|
36
49
|
|
37
50
|
return {
|
38
51
|
AssignmentExpression(node) {
|
39
|
-
if (
|
52
|
+
if (targetParent.indexOf(node.parent.type) !== -1) {
|
40
53
|
context.report({
|
41
54
|
node,
|
42
55
|
messageId: "unexpectedChain"
|
@@ -11,6 +11,14 @@
|
|
11
11
|
|
12
12
|
const astUtils = require("./utils/ast-utils");
|
13
13
|
|
14
|
+
//------------------------------------------------------------------------------
|
15
|
+
// Helpers
|
16
|
+
//------------------------------------------------------------------------------
|
17
|
+
|
18
|
+
const DEFAULT_OPTIONS = {
|
19
|
+
allowInParentheses: true
|
20
|
+
};
|
21
|
+
|
14
22
|
//------------------------------------------------------------------------------
|
15
23
|
// Rule Definition
|
16
24
|
//------------------------------------------------------------------------------
|
@@ -26,7 +34,15 @@ module.exports = {
|
|
26
34
|
url: "https://eslint.org/docs/rules/no-sequences"
|
27
35
|
},
|
28
36
|
|
29
|
-
schema: [
|
37
|
+
schema: [{
|
38
|
+
properties: {
|
39
|
+
allowInParentheses: {
|
40
|
+
type: "boolean",
|
41
|
+
default: true
|
42
|
+
}
|
43
|
+
},
|
44
|
+
additionalProperties: false
|
45
|
+
}],
|
30
46
|
|
31
47
|
messages: {
|
32
48
|
unexpectedCommaExpression: "Unexpected use of comma operator."
|
@@ -34,6 +50,7 @@ module.exports = {
|
|
34
50
|
},
|
35
51
|
|
36
52
|
create(context) {
|
53
|
+
const options = Object.assign({}, DEFAULT_OPTIONS, context.options[0]);
|
37
54
|
const sourceCode = context.getSourceCode();
|
38
55
|
|
39
56
|
/**
|
@@ -99,13 +116,15 @@ module.exports = {
|
|
99
116
|
}
|
100
117
|
|
101
118
|
// Wrapping a sequence in extra parens indicates intent
|
102
|
-
if (
|
103
|
-
if (
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
119
|
+
if (options.allowInParentheses) {
|
120
|
+
if (requiresExtraParens(node)) {
|
121
|
+
if (isParenthesisedTwice(node)) {
|
122
|
+
return;
|
123
|
+
}
|
124
|
+
} else {
|
125
|
+
if (isParenthesised(node)) {
|
126
|
+
return;
|
127
|
+
}
|
109
128
|
}
|
110
129
|
}
|
111
130
|
|
@@ -196,6 +196,17 @@ module.exports = {
|
|
196
196
|
|
197
197
|
}
|
198
198
|
|
199
|
+
/**
|
200
|
+
* Checks whether a node is a sibling of the rest property or not.
|
201
|
+
* @param {ASTNode} node a node to check
|
202
|
+
* @returns {boolean} True if the node is a sibling of the rest property, otherwise false.
|
203
|
+
*/
|
204
|
+
function hasRestSibling(node) {
|
205
|
+
return node.type === "Property" &&
|
206
|
+
node.parent.type === "ObjectPattern" &&
|
207
|
+
REST_PROPERTY_TYPE.test(node.parent.properties[node.parent.properties.length - 1].type);
|
208
|
+
}
|
209
|
+
|
199
210
|
/**
|
200
211
|
* Determines if a variable has a sibling rest property
|
201
212
|
* @param {Variable} variable eslint-scope variable object.
|
@@ -204,16 +215,10 @@ module.exports = {
|
|
204
215
|
*/
|
205
216
|
function hasRestSpreadSibling(variable) {
|
206
217
|
if (config.ignoreRestSiblings) {
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
return (
|
212
|
-
propertyNode.type === "Property" &&
|
213
|
-
patternNode.type === "ObjectPattern" &&
|
214
|
-
REST_PROPERTY_TYPE.test(patternNode.properties[patternNode.properties.length - 1].type)
|
215
|
-
);
|
216
|
-
});
|
218
|
+
const hasRestSiblingDefinition = variable.defs.some(def => hasRestSibling(def.name.parent));
|
219
|
+
const hasRestSiblingReference = variable.references.some(ref => hasRestSibling(ref.identifier.parent));
|
220
|
+
|
221
|
+
return hasRestSiblingDefinition || hasRestSiblingReference;
|
217
222
|
}
|
218
223
|
|
219
224
|
return false;
|
@@ -619,10 +624,18 @@ module.exports = {
|
|
619
624
|
|
620
625
|
// Report the first declaration.
|
621
626
|
if (unusedVar.defs.length > 0) {
|
627
|
+
|
628
|
+
// report last write reference, https://github.com/eslint/eslint/issues/14324
|
629
|
+
const writeReferences = unusedVar.references.filter(ref => ref.isWrite() && ref.from.variableScope === unusedVar.scope.variableScope);
|
630
|
+
|
631
|
+
let referenceToReport;
|
632
|
+
|
633
|
+
if (writeReferences.length > 0) {
|
634
|
+
referenceToReport = writeReferences[writeReferences.length - 1];
|
635
|
+
}
|
636
|
+
|
622
637
|
context.report({
|
623
|
-
node:
|
624
|
-
unusedVar.references.length - 1
|
625
|
-
].identifier : unusedVar.identifiers[0],
|
638
|
+
node: referenceToReport ? referenceToReport.identifier : unusedVar.identifiers[0],
|
626
639
|
messageId: "unusedVar",
|
627
640
|
data: unusedVar.references.some(ref => ref.isWrite())
|
628
641
|
? getAssignedMessageData(unusedVar)
|
@@ -82,7 +82,7 @@ function normalizeOptionValue(value) {
|
|
82
82
|
function normalizeOptions(options) {
|
83
83
|
const isNodeSpecificOption = lodash.overSome([lodash.isPlainObject, lodash.isString]);
|
84
84
|
|
85
|
-
if (lodash.isPlainObject(options) &&
|
85
|
+
if (lodash.isPlainObject(options) && Object.values(options).some(isNodeSpecificOption)) {
|
86
86
|
return {
|
87
87
|
ObjectExpression: normalizeOptionValue(options.ObjectExpression),
|
88
88
|
ObjectPattern: normalizeOptionValue(options.ObjectPattern),
|
@@ -134,7 +134,7 @@ module.exports = {
|
|
134
134
|
type: "layout",
|
135
135
|
|
136
136
|
docs: {
|
137
|
-
description: "enforce consistent line breaks
|
137
|
+
description: "enforce consistent line breaks after opening and before closing braces",
|
138
138
|
category: "Stylistic Issues",
|
139
139
|
recommended: false,
|
140
140
|
url: "https://eslint.org/docs/rules/object-curly-newline"
|
@@ -11,7 +11,7 @@
|
|
11
11
|
|
12
12
|
const path = require("path");
|
13
13
|
const spawn = require("cross-spawn");
|
14
|
-
const
|
14
|
+
const os = require("os");
|
15
15
|
const log = require("../shared/logging");
|
16
16
|
const packageJson = require("../../package.json");
|
17
17
|
|
@@ -107,7 +107,7 @@ function environment() {
|
|
107
107
|
* Checking globally returns an empty JSON object, while local checks
|
108
108
|
* include the name and version of the local project.
|
109
109
|
*/
|
110
|
-
if (
|
110
|
+
if (Object.keys(parsedStdout).length === 0 || !(parsedStdout.dependencies && parsedStdout.dependencies.eslint)) {
|
111
111
|
return "Not found";
|
112
112
|
}
|
113
113
|
|
@@ -141,7 +141,8 @@ function environment() {
|
|
141
141
|
`Node version: ${getBinVersion("node")}`,
|
142
142
|
`npm version: ${getBinVersion("npm")}`,
|
143
143
|
`Local ESLint version: ${getNpmPackageVersion("eslint", { global: false })}`,
|
144
|
-
`Global ESLint version: ${getNpmPackageVersion("eslint", { global: true })}
|
144
|
+
`Global ESLint version: ${getNpmPackageVersion("eslint", { global: true })}`,
|
145
|
+
`Operating System: ${os.platform()} ${os.release()}`
|
145
146
|
].join("\n");
|
146
147
|
}
|
147
148
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "eslint",
|
3
|
-
"version": "7.
|
3
|
+
"version": "7.25.0",
|
4
4
|
"author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
|
5
5
|
"description": "An AST-based pattern checker for JavaScript.",
|
6
6
|
"bin": {
|
@@ -27,10 +27,7 @@
|
|
27
27
|
"pre-commit": "lint-staged"
|
28
28
|
},
|
29
29
|
"lint-staged": {
|
30
|
-
"*.js":
|
31
|
-
"eslint --fix",
|
32
|
-
"git add"
|
33
|
-
],
|
30
|
+
"*.js": "eslint --fix",
|
34
31
|
"*.md": "markdownlint"
|
35
32
|
},
|
36
33
|
"files": [
|
@@ -63,7 +60,7 @@
|
|
63
60
|
"file-entry-cache": "^6.0.1",
|
64
61
|
"functional-red-black-tree": "^1.0.1",
|
65
62
|
"glob-parent": "^5.0.0",
|
66
|
-
"globals": "^
|
63
|
+
"globals": "^13.6.0",
|
67
64
|
"ignore": "^4.0.6",
|
68
65
|
"import-fresh": "^3.0.0",
|
69
66
|
"imurmurhash": "^0.1.4",
|
@@ -71,7 +68,7 @@
|
|
71
68
|
"js-yaml": "^3.13.1",
|
72
69
|
"json-stable-stringify-without-jsonify": "^1.0.1",
|
73
70
|
"levn": "^0.4.1",
|
74
|
-
"lodash": "^4.17.
|
71
|
+
"lodash": "^4.17.21",
|
75
72
|
"minimatch": "^3.0.4",
|
76
73
|
"natural-compare": "^1.4.0",
|
77
74
|
"optionator": "^0.9.1",
|
@@ -100,26 +97,27 @@
|
|
100
97
|
"eslint-config-eslint": "file:packages/eslint-config-eslint",
|
101
98
|
"eslint-plugin-eslint-plugin": "^2.2.1",
|
102
99
|
"eslint-plugin-internal-rules": "file:tools/internal-rules",
|
103
|
-
"eslint-plugin-jsdoc": "^
|
100
|
+
"eslint-plugin-jsdoc": "^25.4.3",
|
104
101
|
"eslint-plugin-node": "^11.1.0",
|
105
102
|
"eslint-release": "^2.0.0",
|
106
|
-
"eslump": "^
|
103
|
+
"eslump": "^3.0.0",
|
107
104
|
"esprima": "^4.0.1",
|
108
105
|
"fs-teardown": "^0.1.0",
|
109
106
|
"glob": "^7.1.6",
|
110
107
|
"jsdoc": "^3.5.5",
|
111
|
-
"karma": "^
|
108
|
+
"karma": "^6.1.1",
|
112
109
|
"karma-chrome-launcher": "^3.1.0",
|
113
|
-
"karma-mocha": "^
|
114
|
-
"karma-mocha-reporter": "^2.2.
|
115
|
-
"karma-webpack": "^
|
110
|
+
"karma-mocha": "^2.0.1",
|
111
|
+
"karma-mocha-reporter": "^2.2.5",
|
112
|
+
"karma-webpack": "^5.0.0",
|
116
113
|
"lint-staged": "^10.1.2",
|
117
114
|
"load-perf": "^0.2.0",
|
118
115
|
"markdownlint": "^0.19.0",
|
119
116
|
"markdownlint-cli": "^0.22.0",
|
120
117
|
"memfs": "^3.0.1",
|
121
|
-
"mocha": "^
|
122
|
-
"mocha-junit-reporter": "^
|
118
|
+
"mocha": "^8.3.2",
|
119
|
+
"mocha-junit-reporter": "^2.0.0",
|
120
|
+
"node-polyfill-webpack-plugin": "^1.0.3",
|
123
121
|
"npm-license": "^0.3.3",
|
124
122
|
"nyc": "^15.0.1",
|
125
123
|
"proxyquire": "^2.0.1",
|
@@ -129,8 +127,8 @@
|
|
129
127
|
"shelljs": "^0.8.2",
|
130
128
|
"sinon": "^9.0.1",
|
131
129
|
"temp": "^0.9.0",
|
132
|
-
"webpack": "^
|
133
|
-
"webpack-cli": "^
|
130
|
+
"webpack": "^5.23.0",
|
131
|
+
"webpack-cli": "^4.5.0",
|
134
132
|
"yorkie": "^2.0.0"
|
135
133
|
},
|
136
134
|
"keywords": [
|