eslint 7.22.0 → 7.26.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 CHANGED
@@ -1,3 +1,59 @@
1
+ v7.26.0 - May 7, 2021
2
+
3
+ * [`aaf65e6`](https://github.com/eslint/eslint/commit/aaf65e629adb74401092c3ccc9cb4e4bd1c8609b) Upgrade: eslintrc for ModuleResolver fix (#14577) (Brandon Mills)
4
+ * [`ae6dbd1`](https://github.com/eslint/eslint/commit/ae6dbd148aaca83e4bd04b9351b54029c50fac8a) Fix: track variables, not names in require-atomic-updates (fixes #14208) (#14282) (Patrick Ahmetovic)
5
+ * [`6a86e50`](https://github.com/eslint/eslint/commit/6a86e5018a3733049c09261bcabae422fbea893d) Chore: remove loose-parser tests (fixes #14315) (#14569) (Milos Djermanovic)
6
+ * [`ee3a3ea`](https://github.com/eslint/eslint/commit/ee3a3ead893d185cc4b1ae9041940cb0968767e1) Fix: create `.eslintrc.cjs` for `module` type (#14304) (Nitin Kumar)
7
+ * [`6791dec`](https://github.com/eslint/eslint/commit/6791decfc58b7b09cfd0aabd15a3d14148aae073) Docs: fix example for require-atomic-updates (#14562) (Milos Djermanovic)
8
+ * [`388eb7e`](https://github.com/eslint/eslint/commit/388eb7e14039b8951462b311d6121002ca5232cb) Sponsors: Sync README with website (ESLint Jenkins)
9
+ * [`f071d1e`](https://github.com/eslint/eslint/commit/f071d1ef91286bf2e3fb63d9b679ff7702819a1e) Update: Add automated suggestion to `radix` rule for parsing decimals (#14291) (Bryan Mishkin)
10
+ * [`0b6a3f3`](https://github.com/eslint/eslint/commit/0b6a3f31e6e78825114f82d4e0aed9cd72f784ac) New: Include XO style guide in `eslint --init` (#14193) (Federico Brigante)
11
+
12
+ v7.25.0 - April 23, 2021
13
+
14
+ * [`5df5e4a`](https://github.com/eslint/eslint/commit/5df5e4a9976964fcf4dc67e241d4e22ec1370fe0) Update: highlight last write reference for no-unused-vars (fixes #14324) (#14335) (Nitin Kumar)
15
+ * [`0023872`](https://github.com/eslint/eslint/commit/00238729329b86b4f8af89ebfe278da3095a6075) Docs: Add deprecated note to `working-with-rules-deprecated` page (#14344) (Michael Novotny)
16
+ * [`36fca70`](https://github.com/eslint/eslint/commit/36fca70fa29ab65080076810de98e09133254b8a) Chore: Upgrade eslump to 3.0.0 (#14350) (Stephen Wade)
17
+ * [`59b689a`](https://github.com/eslint/eslint/commit/59b689a0b3fa658b8380431007cc1facb4617a3b) Chore: add node v16 (#14355) (薛定谔的猫)
18
+ * [`35a1f5e`](https://github.com/eslint/eslint/commit/35a1f5e967e4e87360d3e70d3fca0f7adeeaa1d7) Sponsors: Sync README with website (ESLint Jenkins)
19
+ * [`fb0a92b`](https://github.com/eslint/eslint/commit/fb0a92b3d2fed4a17bc39b7f02c540cd1175ec7d) Chore: rename misspelled identifier in test (#14346) (Tobias Nießen)
20
+ * [`f2babb1`](https://github.com/eslint/eslint/commit/f2babb1069194166e0ac1afd1269bbd06ac299b6) Docs: update pull request template (#14336) (Nitin Kumar)
21
+ * [`02dde29`](https://github.com/eslint/eslint/commit/02dde29eeb523ca24bc4ae7797d38627c3ba9fe9) Docs: Fix anchor in 'docs/developer-guide/working-with-rules.md' (#14332) (Nate-Wilkins)
22
+ * [`07d14c3`](https://github.com/eslint/eslint/commit/07d14c304c358fbc9c3d318e1377d2b2bda9179f) Chore: remove extraneous command from lint-staged config (#14314) (James George)
23
+ * [`41b3570`](https://github.com/eslint/eslint/commit/41b3570b6c014c534bb3208ed00050fd99842101) Update: lint code block with same extension but different content (#14227) (JounQin)
24
+ * [`eb29996`](https://github.com/eslint/eslint/commit/eb299966bdc3920dd2c6f9774d95103d242fc409) Docs: add more examples with arrow functions for no-sequences rule (#14313) (Nitin Kumar)
25
+
26
+ v7.24.0 - April 9, 2021
27
+
28
+ * [`0c346c8`](https://github.com/eslint/eslint/commit/0c346c87fa83c6d1184fdafb9c0748c2e15a423d) Chore: ignore `pnpm-lock.yaml` (#14303) (Nitin Kumar)
29
+ * [`f06ecdf`](https://github.com/eslint/eslint/commit/f06ecdf78b6d6f366434d73a6acfe7041d575223) Update: Add disallowTemplateShorthand option in no-implicit-coercion (#13579) (Remco Haszing)
30
+ * [`71a80e3`](https://github.com/eslint/eslint/commit/71a80e38aab2dada01b808ed43d9b0e806d863c4) Docs: fix broken links in Node.js API docs toc (#14296) (u-sho (Shouhei Uechi))
31
+ * [`bd46dc4`](https://github.com/eslint/eslint/commit/bd46dc4647faa4c3bbb5f60d4c00616a64081398) Docs: Fix incorrect reference to "braces" in arrow-parens (#14300) (emclain)
32
+ * [`0d6235e`](https://github.com/eslint/eslint/commit/0d6235ea201b8b90761ee69bb4d46ae18899c28d) Docs: update header in max-lines (#14273) (Shinigami)
33
+ * [`70c9216`](https://github.com/eslint/eslint/commit/70c92164017238e329e3a2d1654a0227b8f953f7) Docs: Update issue triage to include blocked column (#14275) (Nicholas C. Zakas)
34
+ * [`abca186`](https://github.com/eslint/eslint/commit/abca186a845200fd7728c4e5f220973e640054f9) Docs: Fix typo in suggestions section (#14293) (Kevin Partington)
35
+ * [`c4d8b0d`](https://github.com/eslint/eslint/commit/c4d8b0db62b859e721105d4bc0f4044ce346995e) Fix: no-unused-vars ignoreRestSiblings check assignments (fixes #14163) (#14264) (YeonJuan)
36
+ * [`b51d077`](https://github.com/eslint/eslint/commit/b51d0778d76c2aa27578caca3ea82c867dced3e4) Update: add ignoreNonDeclaration to no-multi-assign rule (fixes #12545) (#14185) (t-mangoe)
37
+ * [`c981fb1`](https://github.com/eslint/eslint/commit/c981fb1994cd04914042ced1980aa86b68ba7be9) Chore: Upgrade mocha to 8.3.2 (#14278) (Stephen Wade)
38
+ * [`147fc04`](https://github.com/eslint/eslint/commit/147fc045e699811fab33dddf77498324ddf7e9d6) Docs: Fix `repro:needed` label in bug report template (#14285) (Milos Djermanovic)
39
+ * [`e1cfde9`](https://github.com/eslint/eslint/commit/e1cfde93eec71a15c2df1ad660a7a6171204ba80) Docs: Update bug report template (#14276) (Nicholas C. Zakas)
40
+ * [`c85c2f1`](https://github.com/eslint/eslint/commit/c85c2f1138a9e952655f19ee780ab0c8e35431a8) Docs: Add fatal to Node.js API LintMessage type (#14251) (Brandon Mills)
41
+
42
+ v7.23.0 - March 26, 2021
43
+
44
+ * [`687ccae`](https://github.com/eslint/eslint/commit/687ccae517b8b815cf21e948f80d22e2bf118a99) Update: add option "allowInParentheses" to no-sequences (fixes #14197) (#14199) (Daniel Rentz)
45
+ * [`dbf2529`](https://github.com/eslint/eslint/commit/dbf252964d9a2b8957cfe0aed5c87a6d4a5cce24) Sponsors: Sync README with website (ESLint Jenkins)
46
+ * [`4bdf2c1`](https://github.com/eslint/eslint/commit/4bdf2c1dade27625b601080687ce95b8c229e491) Sponsors: Sync README with website (ESLint Jenkins)
47
+ * [`49d1697`](https://github.com/eslint/eslint/commit/49d16977d969070e5240074e76036f56631a90d3) Chore: Upgrade eslint-plugin-jsdoc to v25 and remove --legacy-peer-deps (#14244) (Brandon Mills)
48
+ * [`43f1685`](https://github.com/eslint/eslint/commit/43f1685356b9840e09631843ad9ccf0440a498b0) Update: `--quiet` should not supress `--max-warnings` (fixes #14202) (#14242) (Milos Djermanovic)
49
+ * [`909c727`](https://github.com/eslint/eslint/commit/909c7271b8d294bd884827ad5df02615b6ec5e82) Docs: Add valid example that shows vars in a block scope (#14230) (Ed S)
50
+ * [`28583eb`](https://github.com/eslint/eslint/commit/28583eb8ada20f32579841bec3fbd60a018d5931) Fix: no-mixed-operators false positives with `? :` (fixes #14223) (#14226) (Milos Djermanovic)
51
+ * [`a99eb2d`](https://github.com/eslint/eslint/commit/a99eb2dc2a297d16e40a9feef3956668716c4eb5) Fix: Clarify line breaks in object-curly-newline (fixes #14024) (#14063) (armin yahya)
52
+ * [`8984c91`](https://github.com/eslint/eslint/commit/8984c91372e64d1e8dd2ce21b87b80977d57bff9) Update: eslint --env-info output os info (#14059) (薛定谔的猫)
53
+ * [`2a79306`](https://github.com/eslint/eslint/commit/2a79306f71c4c80f1e3e73be2a140d07cf55c63d) Sponsors: Sync README with website (ESLint Jenkins)
54
+ * [`ebd7026`](https://github.com/eslint/eslint/commit/ebd70263f6e6fe597613d90f4b8de84710c2f3d6) Docs: Fix typo (#14225) (Greg Finley)
55
+ * [`a2013fc`](https://github.com/eslint/eslint/commit/a2013fcf996c8651bc760df21d900442828a6884) Sponsors: Sync README with website (ESLint Jenkins)
56
+
1
57
  v7.22.0 - March 12, 2021
2
58
 
3
59
  * [`3a432d8`](https://github.com/eslint/eslint/commit/3a432d82b3a5710aff7da20302fe0b94fedc46c2) Docs: Improve documentation for indent rule (#14168) (Serkan Özel)
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://substack.com/"><img src="https://avatars.githubusercontent.com/u/53023767?v=4" alt="Substack" height="96"></a> <a href="https://aka.ms/microsoftfossfund"><img src="https://avatars.githubusercontent.com/u/67931232?u=7fddc652a464d7151b97e8f108392af7d54fa3e8&v=4" alt="Microsoft FOSS Fund Sponsorships" height="96"></a></p><h3>Silver 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>
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://buy.fineproxy.org/eng/"><img src="https://images.opencollective.com/buy-fineproxy-org/b282e39/logo.png" alt="Buy.Fineproxy.Org" height="32"></a> <a href="https://www.crosswordsolver.org/anagram-solver/"><img src="https://images.opencollective.com/anagram-solver/2666271/logo.png" alt="Anagram Solver" height="32"></a> <a href="null"><img src="https://images.opencollective.com/bugsnag-stability-monitoring/c2cef36/logo.png" alt="Bugsnag Stability Monitoring" height="32"></a> <a href="https://mixpanel.com"><img src="https://images.opencollective.com/mixpanel/cd682f7/logo.png" alt="Mixpanel" height="32"></a> <a href="https://www.vpsserver.com"><img src="https://images.opencollective.com/vpsservercom/logo.png" alt="VPS Server" height="32"></a> <a href="https://icons8.com"><img src="https://images.opencollective.com/icons8/7fa1641/logo.png" alt="Icons8: free icons, photos, illustrations, and music" height="32"></a> <a href="https://discordapp.com"><img src="https://images.opencollective.com/discordapp/7e3d9a9/logo.png" alt="Discord" height="32"></a> <a href="https://themeisle.com"><img src="https://images.opencollective.com/themeisle/d5592fe/logo.png" alt="ThemeIsle" height="32"></a> <a href="https://www.firesticktricks.com"><img src="https://images.opencollective.com/fire-stick-tricks/b8fbe2c/logo.png" alt="Fire Stick Tricks" height="32"></a></p>
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
@@ -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");
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 {Object} cliOptions The CLI options to translate.
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
- results = ESLint.getErrorResults(results);
311
+ resultsToPrint = ESLint.getErrorResults(resultsToPrint);
307
312
  }
308
313
 
309
- if (await printResults(engine, results, options.format, options.outputFile)) {
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;
@@ -117,6 +117,7 @@ function writeJSConfigFile(config, filePath) {
117
117
  function write(config, filePath) {
118
118
  switch (path.extname(filePath)) {
119
119
  case ".js":
120
+ case ".cjs":
120
121
  writeJSConfigFile(config, filePath);
121
122
  break;
122
123
 
@@ -12,6 +12,7 @@
12
12
 
13
13
  const util = require("util"),
14
14
  path = require("path"),
15
+ fs = require("fs"),
15
16
  enquirer = require("enquirer"),
16
17
  ProgressBar = require("progress"),
17
18
  semver = require("semver"),
@@ -48,6 +49,16 @@ function writeFile(config, format) {
48
49
  extname = ".yml";
49
50
  } else if (format === "JSON") {
50
51
  extname = ".json";
52
+ } else if (format === "JavaScript") {
53
+ const pkgJSONPath = npmUtils.findPackageJson();
54
+
55
+ if (pkgJSONPath) {
56
+ const pkgJSONContents = JSON.parse(fs.readFileSync(pkgJSONPath, "utf8"));
57
+
58
+ if (pkgJSONContents.type === "module") {
59
+ extname = ".cjs";
60
+ }
61
+ }
51
62
  }
52
63
 
53
64
  const installedESLint = config.installedESLint;
@@ -531,7 +542,8 @@ function promptUser() {
531
542
  choices: [
532
543
  { message: "Airbnb: https://github.com/airbnb/javascript", name: "airbnb" },
533
544
  { message: "Standard: https://github.com/standard/standard", name: "standard" },
534
- { message: "Google: https://github.com/google/eslint-config-google", name: "google" }
545
+ { message: "Google: https://github.com/google/eslint-config-google", name: "google" },
546
+ { message: "XO: https://github.com/xojs/eslint-config-xo", name: "xo" }
535
547
  ],
536
548
  skip() {
537
549
  this.state.answers.packageJsonExists = npmUtils.checkPackageJson();
@@ -683,6 +695,7 @@ const init = {
683
695
  hasESLintVersionConflict,
684
696
  installModules,
685
697
  processAnswers,
698
+ writeFile,
686
699
  /* istanbul ignore next */initializeConfig() {
687
700
  return promptUser();
688
701
  }
@@ -172,6 +172,7 @@ function checkPackageJson(startDir) {
172
172
  module.exports = {
173
173
  installSyncSaveDev,
174
174
  fetchPeerDependencies,
175
+ findPackageJson,
175
176
  checkDeps,
176
177
  checkDevDeps,
177
178
  checkPackageJson
@@ -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,
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
  //------------------------------------------------------------------------------
@@ -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 (TARGET_NODE_TYPE.test(node.parent.type)) {
224
- if (node.parent.type === "ConditionalExpression" && !shouldIgnore(node) && isMixedWithConditionalParent(node.parent)) {
225
- reportBothOperators(node);
226
- } else {
227
- if (TARGET_NODE_TYPE.test(node.parent.type) &&
228
- isMixedWithParent(node) &&
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 (["AssignmentExpression", "VariableDeclarator"].indexOf(node.parent.type) !== -1) {
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 (requiresExtraParens(node)) {
103
- if (isParenthesisedTwice(node)) {
104
- return;
105
- }
106
- } else {
107
- if (isParenthesised(node)) {
108
- return;
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
- return variable.defs.some(def => {
208
- const propertyNode = def.name.parent;
209
- const patternNode = propertyNode.parent;
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: unusedVar.references.length ? unusedVar.references[
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)
@@ -134,7 +134,7 @@ module.exports = {
134
134
  type: "layout",
135
135
 
136
136
  docs: {
137
- description: "enforce consistent line breaks inside braces",
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"
@@ -82,7 +82,8 @@ module.exports = {
82
82
  description: "enforce the consistent use of the radix argument when using `parseInt()`",
83
83
  category: "Best Practices",
84
84
  recommended: false,
85
- url: "https://eslint.org/docs/rules/radix"
85
+ url: "https://eslint.org/docs/rules/radix",
86
+ suggestion: true
86
87
  },
87
88
 
88
89
  schema: [
@@ -95,7 +96,8 @@ module.exports = {
95
96
  missingParameters: "Missing parameters.",
96
97
  redundantRadix: "Redundant radix parameter.",
97
98
  missingRadix: "Missing radix parameter.",
98
- invalidRadix: "Invalid radix parameter, must be an integer between 2 and 36."
99
+ invalidRadix: "Invalid radix parameter, must be an integer between 2 and 36.",
100
+ addRadixParameter10: "Add radix parameter `10` for parsing decimal numbers."
99
101
  }
100
102
  },
101
103
 
@@ -123,7 +125,21 @@ module.exports = {
123
125
  if (mode === MODE_ALWAYS) {
124
126
  context.report({
125
127
  node,
126
- messageId: "missingRadix"
128
+ messageId: "missingRadix",
129
+ suggest: [
130
+ {
131
+ messageId: "addRadixParameter10",
132
+ fix(fixer) {
133
+ const sourceCode = context.getSourceCode();
134
+ const tokens = sourceCode.getTokens(node);
135
+ const lastToken = tokens[tokens.length - 1]; // Parenthesis.
136
+ const secondToLastToken = tokens[tokens.length - 2]; // May or may not be a comma.
137
+ const hasTrailingComma = secondToLastToken.type === "Punctuator" && secondToLastToken.value === ",";
138
+
139
+ return fixer.insertTextBefore(lastToken, hasTrailingComma ? " 10," : ", 10");
140
+ }
141
+ }
142
+ ]
127
143
  });
128
144
  }
129
145
  break;
@@ -13,6 +13,10 @@
13
13
  */
14
14
  function createReferenceMap(scope, outReferenceMap = new Map()) {
15
15
  for (const reference of scope.references) {
16
+ if (reference.resolved === null) {
17
+ continue;
18
+ }
19
+
16
20
  outReferenceMap.set(reference.identifier, reference);
17
21
  }
18
22
  for (const childScope of scope.childScopes) {
@@ -86,42 +90,42 @@ class SegmentInfo {
86
90
  * @returns {void}
87
91
  */
88
92
  initialize(segment) {
89
- const outdatedReadVariableNames = new Set();
90
- const freshReadVariableNames = new Set();
93
+ const outdatedReadVariables = new Set();
94
+ const freshReadVariables = new Set();
91
95
 
92
96
  for (const prevSegment of segment.prevSegments) {
93
97
  const info = this.info.get(prevSegment);
94
98
 
95
99
  if (info) {
96
- info.outdatedReadVariableNames.forEach(Set.prototype.add, outdatedReadVariableNames);
97
- info.freshReadVariableNames.forEach(Set.prototype.add, freshReadVariableNames);
100
+ info.outdatedReadVariables.forEach(Set.prototype.add, outdatedReadVariables);
101
+ info.freshReadVariables.forEach(Set.prototype.add, freshReadVariables);
98
102
  }
99
103
  }
100
104
 
101
- this.info.set(segment, { outdatedReadVariableNames, freshReadVariableNames });
105
+ this.info.set(segment, { outdatedReadVariables, freshReadVariables });
102
106
  }
103
107
 
104
108
  /**
105
109
  * Mark a given variable as read on given segments.
106
110
  * @param {PathSegment[]} segments The segments that it read the variable on.
107
- * @param {string} variableName The variable name to be read.
111
+ * @param {Variable} variable The variable to be read.
108
112
  * @returns {void}
109
113
  */
110
- markAsRead(segments, variableName) {
114
+ markAsRead(segments, variable) {
111
115
  for (const segment of segments) {
112
116
  const info = this.info.get(segment);
113
117
 
114
118
  if (info) {
115
- info.freshReadVariableNames.add(variableName);
119
+ info.freshReadVariables.add(variable);
116
120
 
117
121
  // If a variable is freshly read again, then it's no more out-dated.
118
- info.outdatedReadVariableNames.delete(variableName);
122
+ info.outdatedReadVariables.delete(variable);
119
123
  }
120
124
  }
121
125
  }
122
126
 
123
127
  /**
124
- * Move `freshReadVariableNames` to `outdatedReadVariableNames`.
128
+ * Move `freshReadVariables` to `outdatedReadVariables`.
125
129
  * @param {PathSegment[]} segments The segments to process.
126
130
  * @returns {void}
127
131
  */
@@ -130,8 +134,8 @@ class SegmentInfo {
130
134
  const info = this.info.get(segment);
131
135
 
132
136
  if (info) {
133
- info.freshReadVariableNames.forEach(Set.prototype.add, info.outdatedReadVariableNames);
134
- info.freshReadVariableNames.clear();
137
+ info.freshReadVariables.forEach(Set.prototype.add, info.outdatedReadVariables);
138
+ info.freshReadVariables.clear();
135
139
  }
136
140
  }
137
141
  }
@@ -139,14 +143,14 @@ class SegmentInfo {
139
143
  /**
140
144
  * Check if a given variable is outdated on the current segments.
141
145
  * @param {PathSegment[]} segments The current segments.
142
- * @param {string} variableName The variable name to check.
146
+ * @param {Variable} variable The variable to check.
143
147
  * @returns {boolean} `true` if the variable is outdated on the segments.
144
148
  */
145
- isOutdated(segments, variableName) {
149
+ isOutdated(segments, variable) {
146
150
  for (const segment of segments) {
147
151
  const info = this.info.get(segment);
148
152
 
149
- if (info && info.outdatedReadVariableNames.has(variableName)) {
153
+ if (info && info.outdatedReadVariables.has(variable)) {
150
154
  return true;
151
155
  }
152
156
  }
@@ -214,14 +218,13 @@ module.exports = {
214
218
  if (!reference) {
215
219
  return;
216
220
  }
217
- const name = reference.identifier.name;
218
221
  const variable = reference.resolved;
219
222
  const writeExpr = getWriteExpr(reference);
220
223
  const isMemberAccess = reference.identifier.parent.type === "MemberExpression";
221
224
 
222
225
  // Add a fresh read variable.
223
226
  if (reference.isRead() && !(writeExpr && writeExpr.parent.operator === "=")) {
224
- segmentInfo.markAsRead(codePath.currentSegments, name);
227
+ segmentInfo.markAsRead(codePath.currentSegments, variable);
225
228
  }
226
229
 
227
230
  /*
@@ -245,7 +248,7 @@ module.exports = {
245
248
 
246
249
  /*
247
250
  * Verify assignments.
248
- * If the reference exists in `outdatedReadVariableNames` list, report it.
251
+ * If the reference exists in `outdatedReadVariables` list, report it.
249
252
  */
250
253
  ":expression:exit"(node) {
251
254
  const { codePath, referenceMap } = stack;
@@ -267,9 +270,9 @@ module.exports = {
267
270
  assignmentReferences.delete(node);
268
271
 
269
272
  for (const reference of references) {
270
- const name = reference.identifier.name;
273
+ const variable = reference.resolved;
271
274
 
272
- if (segmentInfo.isOutdated(codePath.currentSegments, name)) {
275
+ if (segmentInfo.isOutdated(codePath.currentSegments, variable)) {
273
276
  context.report({
274
277
  node: node.parent,
275
278
  messageId: "nonAtomicUpdate",
@@ -11,6 +11,7 @@
11
11
 
12
12
  const path = require("path");
13
13
  const spawn = require("cross-spawn");
14
+ const os = require("os");
14
15
  const log = require("../shared/logging");
15
16
  const packageJson = require("../../package.json");
16
17
 
@@ -140,7 +141,8 @@ function environment() {
140
141
  `Node version: ${getBinVersion("node")}`,
141
142
  `npm version: ${getBinVersion("npm")}`,
142
143
  `Local ESLint version: ${getNpmPackageVersion("eslint", { global: false })}`,
143
- `Global ESLint version: ${getNpmPackageVersion("eslint", { global: true })}`
144
+ `Global ESLint version: ${getNpmPackageVersion("eslint", { global: true })}`,
145
+ `Operating System: ${os.platform()} ${os.release()}`
144
146
  ].join("\n");
145
147
  }
146
148
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint",
3
- "version": "7.22.0",
3
+ "version": "7.26.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": [
@@ -47,7 +44,7 @@
47
44
  "bugs": "https://github.com/eslint/eslint/issues/",
48
45
  "dependencies": {
49
46
  "@babel/code-frame": "7.12.11",
50
- "@eslint/eslintrc": "^0.4.0",
47
+ "@eslint/eslintrc": "^0.4.1",
51
48
  "ajv": "^6.10.0",
52
49
  "chalk": "^4.0.0",
53
50
  "cross-spawn": "^7.0.2",
@@ -87,7 +84,6 @@
87
84
  "devDependencies": {
88
85
  "@babel/core": "^7.4.3",
89
86
  "@babel/preset-env": "^7.4.3",
90
- "acorn": "^7.2.0",
91
87
  "babel-loader": "^8.0.5",
92
88
  "chai": "^4.0.1",
93
89
  "cheerio": "^0.22.0",
@@ -100,10 +96,10 @@
100
96
  "eslint-config-eslint": "file:packages/eslint-config-eslint",
101
97
  "eslint-plugin-eslint-plugin": "^2.2.1",
102
98
  "eslint-plugin-internal-rules": "file:tools/internal-rules",
103
- "eslint-plugin-jsdoc": "^22.1.0",
99
+ "eslint-plugin-jsdoc": "^25.4.3",
104
100
  "eslint-plugin-node": "^11.1.0",
105
101
  "eslint-release": "^2.0.0",
106
- "eslump": "^2.0.0",
102
+ "eslump": "^3.0.0",
107
103
  "esprima": "^4.0.1",
108
104
  "fs-teardown": "^0.1.0",
109
105
  "glob": "^7.1.6",
@@ -118,8 +114,8 @@
118
114
  "markdownlint": "^0.19.0",
119
115
  "markdownlint-cli": "^0.22.0",
120
116
  "memfs": "^3.0.1",
121
- "mocha": "^7.1.1",
122
- "mocha-junit-reporter": "^1.23.0",
117
+ "mocha": "^8.3.2",
118
+ "mocha-junit-reporter": "^2.0.0",
123
119
  "node-polyfill-webpack-plugin": "^1.0.3",
124
120
  "npm-license": "^0.3.3",
125
121
  "nyc": "^15.0.1",