eslint 7.25.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,14 @@
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
+
1
12
  v7.25.0 - April 23, 2021
2
13
 
3
14
  * [`5df5e4a`](https://github.com/eslint/eslint/commit/5df5e4a9976964fcf4dc67e241d4e22ec1370fe0) Update: highlight last write reference for no-unused-vars (fixes #14324) (#14335) (Nitin Kumar)
package/README.md CHANGED
@@ -281,7 +281,7 @@ 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://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>
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
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-->
@@ -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");
@@ -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
@@ -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",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint",
3
- "version": "7.25.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": {
@@ -44,7 +44,7 @@
44
44
  "bugs": "https://github.com/eslint/eslint/issues/",
45
45
  "dependencies": {
46
46
  "@babel/code-frame": "7.12.11",
47
- "@eslint/eslintrc": "^0.4.0",
47
+ "@eslint/eslintrc": "^0.4.1",
48
48
  "ajv": "^6.10.0",
49
49
  "chalk": "^4.0.0",
50
50
  "cross-spawn": "^7.0.2",
@@ -84,7 +84,6 @@
84
84
  "devDependencies": {
85
85
  "@babel/core": "^7.4.3",
86
86
  "@babel/preset-env": "^7.4.3",
87
- "acorn": "^7.2.0",
88
87
  "babel-loader": "^8.0.5",
89
88
  "chai": "^4.0.1",
90
89
  "cheerio": "^0.22.0",