eslint 8.10.0 → 8.11.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/README.md CHANGED
@@ -292,9 +292,9 @@ The following companies, organizations, and individuals support ESLint's ongoing
292
292
  <!--sponsorsstart-->
293
293
  <h3>Platinum Sponsors</h3>
294
294
  <p><a href="https://automattic.com"><img src="https://images.opencollective.com/automattic/d0ef3e1/logo.png" alt="Automattic" height="undefined"></a></p><h3>Gold Sponsors</h3>
295
- <p><a href="https://contra.com"><img src="https://images.opencollective.com/contra1/c70f93f/logo.png" alt="Contra" height="96"></a> <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://americanexpress.io"><img src="https://avatars.githubusercontent.com/u/3853301?v=4" alt="American Express" 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>
295
+ <p><a href="https://contra.com"><img src="https://images.opencollective.com/contra1/c70f93f/logo.png" alt="Contra" height="96"></a> <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://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://americanexpress.io"><img src="https://avatars.githubusercontent.com/u/3853301?v=4" alt="American Express" 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>
296
296
  <p><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>
297
- <p><a href="https://launchdarkly.com"><img src="https://images.opencollective.com/launchdarkly/574bb9e/logo.png" alt="launchdarkly" 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="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/f9645d9/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.ignitionapp.com"><img src="https://avatars.githubusercontent.com/u/5753491?v=4" alt="Practice Ignition" height="32"></a></p>
297
+ <p><a href="https://launchdarkly.com"><img src="https://images.opencollective.com/launchdarkly/574bb9e/logo.png" alt="launchdarkly" 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="https://www.vpsserver.com"><img src="https://images.opencollective.com/vpsservercom/logo.png" alt="VPS" 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/f9645d9/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.ignitionapp.com"><img src="https://avatars.githubusercontent.com/u/5753491?v=4" alt="Ignition" height="32"></a></p>
298
298
  <!--sponsorsend-->
299
299
 
300
300
  ## <a name="technology-sponsors"></a>Technology Sponsors
@@ -39,6 +39,8 @@ function pageTemplate(it) {
39
39
  <head>
40
40
  <meta charset="UTF-8">
41
41
  <title>ESLint Report</title>
42
+ <link rel="icon" type="image/png" sizes="any" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAAHaAAAB2gGFomX7AAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAABD1JREFUWMPFl11sk2UUx3/nbYtjxS1MF7MLMTECMgSTtSSyrQkLhAj7UBPnDSEGoxegGzMwojhXVpmTAA5iYpSoMQa8GBhFOrMFk03buei6yRAlcmOM0SEmU9d90b19jxcM1o5+sGnsc/e+z/l6ztf/HFFVMnns6QieeOCHBePGsHM+wrOtvLG2C4WRVDSSygNV7sCjlspxwDnPB44aols/DXk+mbMBmx/6OseITF1CuOtfevkPh2Uu+/jbdX8lujSScRlT5r7/QDlAfsRmfzmpnkQ/H3H13gf6bBrBn1uqK8WylgEnU8eZmk1repbfchJG1TyKyIKEwuBHFd3lD3naY3O1siiwXsVoBV2VgM1ht/QQUJk2ByqKghsQziYQ8ifKgexIXmuyzC4r67Y7R+xPAfuB/Nn3Cpva+0s7khpQVtZtd4bt51BWxtBYAiciprG7c7D4SixzU9PYalDL6110Ifb/w8W9eY7JqFeFHbO8fPGyLHwwFHJNJTSgwtVTB9oaw9BlQ+tO93vOxypoaQnfEYlI43SeCHDC4TDq9+51/h5fxr33q0ZfV9g04wat9Q943rjJgCp3952W2i8Bi6eDvdsfKj0cK/DYMRyXL4/sUJUmIHd2zYMezsvLaamp4WpcWN3BXSiHpuMwbGbZlnZ8tXY4rgosy+G7oRwQ0cAsd28YGgqfU5UjCZQDLALxDg+Hv/P5Rqvj4hwrS8izXzWb4spwc1GgENF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44
  <style>
43
45
  body {
44
46
  font-family:Arial, "Helvetica Neue", Helvetica, sans-serif;
@@ -243,8 +243,18 @@ module.exports = {
243
243
  node: lastItem,
244
244
  loc: trailingToken.loc,
245
245
  messageId: "unexpected",
246
- fix(fixer) {
247
- return fixer.remove(trailingToken);
246
+ *fix(fixer) {
247
+ yield fixer.remove(trailingToken);
248
+
249
+ /*
250
+ * Extend the range of the fix to include surrounding tokens to ensure
251
+ * that the element after which the comma is removed stays _last_.
252
+ * This intentionally makes conflicts in fix ranges with rules that may be
253
+ * adding or removing elements in the same autofix pass.
254
+ * https://github.com/eslint/eslint/issues/15660
255
+ */
256
+ yield fixer.insertTextBefore(sourceCode.getTokenBefore(trailingToken), "");
257
+ yield fixer.insertTextAfter(sourceCode.getTokenAfter(trailingToken), "");
248
258
  }
249
259
  });
250
260
  }
@@ -282,8 +292,18 @@ module.exports = {
282
292
  end: astUtils.getNextLocation(sourceCode, trailingToken.loc.end)
283
293
  },
284
294
  messageId: "missing",
285
- fix(fixer) {
286
- return fixer.insertTextAfter(trailingToken, ",");
295
+ *fix(fixer) {
296
+ yield fixer.insertTextAfter(trailingToken, ",");
297
+
298
+ /*
299
+ * Extend the range of the fix to include surrounding tokens to ensure
300
+ * that the element after which the comma is inserted stays _last_.
301
+ * This intentionally makes conflicts in fix ranges with rules that may be
302
+ * adding or removing elements in the same autofix pass.
303
+ * https://github.com/eslint/eslint/issues/15660
304
+ */
305
+ yield fixer.insertTextBefore(trailingToken, "");
306
+ yield fixer.insertTextAfter(sourceCode.getTokenAfter(trailingToken), "");
287
307
  }
288
308
  });
289
309
  }
@@ -120,12 +120,30 @@ module.exports = {
120
120
  return false;
121
121
  }
122
122
 
123
+ /**
124
+ * Checks if an identifier is a reference to a global variable.
125
+ * @param {ASTNode} node An identifier node to check.
126
+ * @returns {boolean} `true` if the identifier is a reference to a global variable.
127
+ */
128
+ function isReferenceToGlobalVariable(node) {
129
+ const scope = context.getScope();
130
+ const reference = scope.references.find(ref => ref.identifier === node);
131
+
132
+ return Boolean(
133
+ reference &&
134
+ reference.resolved &&
135
+ reference.resolved.scope.type === "global" &&
136
+ reference.resolved.defs.length === 0
137
+ );
138
+ }
139
+
123
140
  /**
124
141
  * Checks if a node has a constant truthiness value.
125
142
  * @param {ASTNode} node The AST node to check.
126
- * @param {boolean} inBooleanPosition `false` if checking branch of a condition.
127
- * `true` in all other cases. When `false`, checks if -- for both string and
128
- * number -- if coerced to that type, the value will be constant.
143
+ * @param {boolean} inBooleanPosition `true` if checking the test of a
144
+ * condition. `false` in all other cases. When `false`, checks if -- for
145
+ * both string and number -- if coerced to that type, the value will
146
+ * be constant.
129
147
  * @returns {Bool} true when node's truthiness is constant
130
148
  * @private
131
149
  */
@@ -215,6 +233,15 @@ module.exports = {
215
233
  return isConstant(node.expressions[node.expressions.length - 1], inBooleanPosition);
216
234
  case "SpreadElement":
217
235
  return isConstant(node.argument, inBooleanPosition);
236
+ case "CallExpression":
237
+ if (node.callee.type === "Identifier" && node.callee.name === "Boolean") {
238
+ if (node.arguments.length === 0 || isConstant(node.arguments[0], true)) {
239
+ return isReferenceToGlobalVariable(node.callee);
240
+ }
241
+ }
242
+ return false;
243
+ case "Identifier":
244
+ return node.name === "undefined" && isReferenceToGlobalVariable(node);
218
245
 
219
246
  // no default
220
247
  }
@@ -67,6 +67,9 @@ module.exports = {
67
67
  },
68
68
  caughtErrorsIgnorePattern: {
69
69
  type: "string"
70
+ },
71
+ destructuredArrayIgnorePattern: {
72
+ type: "string"
70
73
  }
71
74
  },
72
75
  additionalProperties: false
@@ -114,6 +117,10 @@ module.exports = {
114
117
  if (firstOption.caughtErrorsIgnorePattern) {
115
118
  config.caughtErrorsIgnorePattern = new RegExp(firstOption.caughtErrorsIgnorePattern, "u");
116
119
  }
120
+
121
+ if (firstOption.destructuredArrayIgnorePattern) {
122
+ config.destructuredArrayIgnorePattern = new RegExp(firstOption.destructuredArrayIgnorePattern, "u");
123
+ }
117
124
  }
118
125
  }
119
126
 
@@ -155,7 +162,14 @@ module.exports = {
155
162
  * @returns {UnusedVarMessageData} The message data to be used with this unused variable.
156
163
  */
157
164
  function getAssignedMessageData(unusedVar) {
158
- const additional = config.varsIgnorePattern ? `. Allowed unused vars must match ${config.varsIgnorePattern.toString()}` : "";
165
+ const def = unusedVar.defs[0];
166
+ let additional = "";
167
+
168
+ if (config.destructuredArrayIgnorePattern && def && def.name.parent.type === "ArrayPattern") {
169
+ additional = `. Allowed unused elements of array destructuring patterns must match ${config.destructuredArrayIgnorePattern.toString()}`;
170
+ } else if (config.varsIgnorePattern) {
171
+ additional = `. Allowed unused vars must match ${config.varsIgnorePattern.toString()}`;
172
+ }
159
173
 
160
174
  return {
161
175
  varName: unusedVar.name,
@@ -584,6 +598,19 @@ module.exports = {
584
598
 
585
599
  if (def) {
586
600
  const type = def.type;
601
+ const refUsedInArrayPatterns = variable.references.some(ref => ref.identifier.parent.type === "ArrayPattern");
602
+
603
+ // skip elements of array destructuring patterns
604
+ if (
605
+ (
606
+ def.name.parent.type === "ArrayPattern" ||
607
+ refUsedInArrayPatterns
608
+ ) &&
609
+ config.destructuredArrayIgnorePattern &&
610
+ config.destructuredArrayIgnorePattern.test(def.name.name)
611
+ ) {
612
+ continue;
613
+ }
587
614
 
588
615
  // skip catch variables
589
616
  if (type === "CatchClause") {
@@ -19,6 +19,8 @@ module.exports = {
19
19
  url: "https://eslint.org/docs/rules/valid-typeof"
20
20
  },
21
21
 
22
+ hasSuggestions: true,
23
+
22
24
  schema: [
23
25
  {
24
26
  type: "object",
@@ -33,7 +35,8 @@ module.exports = {
33
35
  ],
34
36
  messages: {
35
37
  invalidValue: "Invalid typeof comparison value.",
36
- notString: "Typeof comparisons should be to string literals."
38
+ notString: "Typeof comparisons should be to string literals.",
39
+ suggestString: 'Use `"{{type}}"` instead of `{{type}}`.'
37
40
  }
38
41
  },
39
42
 
@@ -44,6 +47,21 @@ module.exports = {
44
47
 
45
48
  const requireStringLiterals = context.options[0] && context.options[0].requireStringLiterals;
46
49
 
50
+ let globalScope;
51
+
52
+ /**
53
+ * Checks whether the given node represents a reference to a global variable that is not declared in the source code.
54
+ * These identifiers will be allowed, as it is assumed that user has no control over the names of external global variables.
55
+ * @param {ASTNode} node `Identifier` node to check.
56
+ * @returns {boolean} `true` if the node is a reference to a global variable.
57
+ */
58
+ function isReferenceToGlobalVariable(node) {
59
+ const variable = globalScope.set.get(node.name);
60
+
61
+ return variable && variable.defs.length === 0 &&
62
+ variable.references.some(ref => ref.identifier === node);
63
+ }
64
+
47
65
  /**
48
66
  * Determines whether a node is a typeof expression.
49
67
  * @param {ASTNode} node The node
@@ -59,6 +77,10 @@ module.exports = {
59
77
 
60
78
  return {
61
79
 
80
+ Program() {
81
+ globalScope = context.getScope();
82
+ },
83
+
62
84
  UnaryExpression(node) {
63
85
  if (isTypeofExpression(node)) {
64
86
  const parent = context.getAncestors().pop();
@@ -72,6 +94,20 @@ module.exports = {
72
94
  if (VALID_TYPES.indexOf(value) === -1) {
73
95
  context.report({ node: sibling, messageId: "invalidValue" });
74
96
  }
97
+ } else if (sibling.type === "Identifier" && sibling.name === "undefined" && isReferenceToGlobalVariable(sibling)) {
98
+ context.report({
99
+ node: sibling,
100
+ messageId: requireStringLiterals ? "notString" : "invalidValue",
101
+ suggest: [
102
+ {
103
+ messageId: "suggestString",
104
+ data: { type: "undefined" },
105
+ fix(fixer) {
106
+ return fixer.replaceText(sibling, '"undefined"');
107
+ }
108
+ }
109
+ ]
110
+ });
75
111
  } else if (requireStringLiterals && !isTypeofExpression(sibling)) {
76
112
  context.report({ node: sibling, messageId: "notString" });
77
113
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint",
3
- "version": "8.10.0",
3
+ "version": "8.11.0",
4
4
  "author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
5
5
  "description": "An AST-based pattern checker for JavaScript.",
6
6
  "bin": {
@@ -47,7 +47,7 @@
47
47
  "homepage": "https://eslint.org",
48
48
  "bugs": "https://github.com/eslint/eslint/issues/",
49
49
  "dependencies": {
50
- "@eslint/eslintrc": "^1.2.0",
50
+ "@eslint/eslintrc": "^1.2.1",
51
51
  "@humanwhocodes/config-array": "^0.9.2",
52
52
  "ajv": "^6.10.0",
53
53
  "chalk": "^4.0.0",