eslint 8.16.0 → 8.17.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
@@ -299,7 +299,7 @@ The following companies, organizations, and individuals support ESLint's ongoing
299
299
  <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>
300
300
  <p><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>
301
301
  <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>
302
- <p><a href="https://launchdarkly.com"><img src="https://images.opencollective.com/launchdarkly/574bb9e/logo.png" alt="launchdarkly" height="32"></a> <a href="https://nx.dev"><img src="https://images.opencollective.com/nx/0efbe42/logo.png" alt="Nx (by Nrwl)" 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>
302
+ <p><a href="https://launchdarkly.com"><img src="https://images.opencollective.com/launchdarkly/574bb9e/logo.png" alt="launchdarkly" height="32"></a> <a href="https://nx.dev"><img src="https://images.opencollective.com/nx/0efbe42/logo.png" alt="Nx (by Nrwl)" 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> <a href="https://herocoders.com"><img src="https://avatars.githubusercontent.com/u/37549774?v=4" alt="HeroCoders" height="32"></a></p>
303
303
  <!--sponsorsend-->
304
304
 
305
305
  ## <a name="technology-sponsors"></a>Technology Sponsors
package/bin/eslint.js CHANGED
@@ -69,7 +69,7 @@ function getErrorMessage(error) {
69
69
  // Lazy loading because this is used only if an error happened.
70
70
  const util = require("util");
71
71
 
72
- // Foolproof -- thirdparty module might throw non-object.
72
+ // Foolproof -- third-party module might throw non-object.
73
73
  if (typeof error !== "object" || error === null) {
74
74
  return String(error);
75
75
  }
@@ -104,9 +104,9 @@ function isNonEmptyString(x) {
104
104
  }
105
105
 
106
106
  /**
107
- * Check if a given value is an array of non-empty stringss or not.
107
+ * Check if a given value is an array of non-empty strings or not.
108
108
  * @param {any} x The value to check.
109
- * @returns {boolean} `true` if `x` is an array of non-empty stringss.
109
+ * @returns {boolean} `true` if `x` is an array of non-empty strings.
110
110
  */
111
111
  function isArrayOfNonEmptyString(x) {
112
112
  return Array.isArray(x) && x.every(isNonEmptyString);
@@ -599,7 +599,7 @@ class ESLint {
599
599
  * The following values are allowed:
600
600
  * - `undefined` ... Load `stylish` builtin formatter.
601
601
  * - A builtin formatter name ... Load the builtin formatter.
602
- * - A thirdparty formatter name:
602
+ * - A third-party formatter name:
603
603
  * - `foo` → `eslint-formatter-foo`
604
604
  * - `@foo` → `@foo/eslint-formatter`
605
605
  * - `@foo/bar` → `@foo/eslint-formatter-bar`
@@ -183,7 +183,7 @@ module.exports = {
183
183
  /**
184
184
  * Gets the left paren and right paren tokens of a node.
185
185
  * @param {ASTNode} node The node with parens
186
- * @throws {TypeError} Unexecpted node type.
186
+ * @throws {TypeError} Unexpected node type.
187
187
  * @returns {Object} An object with keys `leftParen` for the left paren token, and `rightParen` for the right paren token.
188
188
  * Can also return `null` if an expression has no parens (e.g. a NewExpression with no arguments, or an ArrowFunctionExpression
189
189
  * with a single parameter)
@@ -916,18 +916,6 @@ module.exports = {
916
916
  }
917
917
 
918
918
  offsets.setDesiredOffsets([firstBodyToken.range[0], lastBodyToken.range[1]], lastParentToken, 1);
919
-
920
- /*
921
- * For blockless nodes with semicolon-first style, don't indent the semicolon.
922
- * e.g.
923
- * if (foo) bar()
924
- * ; [1, 2, 3].map(foo)
925
- */
926
- const lastToken = sourceCode.getLastToken(node);
927
-
928
- if (node.type !== "EmptyStatement" && astUtils.isSemicolonToken(lastToken)) {
929
- offsets.setDesiredOffset(lastToken, lastParentToken, 0);
930
- }
931
919
  }
932
920
  }
933
921
 
@@ -1271,6 +1259,50 @@ module.exports = {
1271
1259
  }
1272
1260
  },
1273
1261
 
1262
+ /*
1263
+ * For blockless nodes with semicolon-first style, don't indent the semicolon.
1264
+ * e.g.
1265
+ * if (foo)
1266
+ * bar()
1267
+ * ; [1, 2, 3].map(foo)
1268
+ *
1269
+ * Traversal into the node sets indentation of the semicolon, so we need to override it on exit.
1270
+ */
1271
+ ":matches(DoWhileStatement, ForStatement, ForInStatement, ForOfStatement, IfStatement, WhileStatement):exit"(node) {
1272
+ let nodesToCheck;
1273
+
1274
+ if (node.type === "IfStatement") {
1275
+ nodesToCheck = [node.consequent];
1276
+ if (node.alternate) {
1277
+ nodesToCheck.push(node.alternate);
1278
+ }
1279
+ } else {
1280
+ nodesToCheck = [node.body];
1281
+ }
1282
+
1283
+ for (const nodeToCheck of nodesToCheck) {
1284
+ const lastToken = sourceCode.getLastToken(nodeToCheck);
1285
+
1286
+ if (astUtils.isSemicolonToken(lastToken)) {
1287
+ const tokenBeforeLast = sourceCode.getTokenBefore(lastToken);
1288
+ const tokenAfterLast = sourceCode.getTokenAfter(lastToken);
1289
+
1290
+ // override indentation of `;` only if its line looks like a semicolon-first style line
1291
+ if (
1292
+ !astUtils.isTokenOnSameLine(tokenBeforeLast, lastToken) &&
1293
+ tokenAfterLast &&
1294
+ astUtils.isTokenOnSameLine(lastToken, tokenAfterLast)
1295
+ ) {
1296
+ offsets.setDesiredOffset(
1297
+ lastToken,
1298
+ sourceCode.getFirstToken(node),
1299
+ 0
1300
+ );
1301
+ }
1302
+ }
1303
+ }
1304
+ },
1305
+
1274
1306
  ImportDeclaration(node) {
1275
1307
  if (node.specifiers.some(specifier => specifier.type === "ImportSpecifier")) {
1276
1308
  const openingCurly = sourceCode.getFirstToken(node, astUtils.isOpeningBraceToken);
@@ -126,7 +126,7 @@ module.exports = {
126
126
 
127
127
  /*
128
128
  * This rule does not apply to class static blocks, but we have to track them so
129
- * that stataments in them do not count as statements in the enclosing function.
129
+ * that statements in them do not count as statements in the enclosing function.
130
130
  */
131
131
  if (node.type === "StaticBlock") {
132
132
  return;
@@ -120,7 +120,7 @@ function isStaticBoolean(scope, node) {
120
120
 
121
121
  /**
122
122
  * Test if an AST node will always give the same result when compared to a
123
- * bolean value. Note that comparison to boolean values is different than
123
+ * boolean value. Note that comparison to boolean values is different than
124
124
  * truthiness.
125
125
  * https://262.ecma-international.org/5.1/#sec-11.9.3
126
126
  *
@@ -238,7 +238,7 @@ function hasConstantLooseBooleanComparison(scope, node) {
238
238
 
239
239
  /**
240
240
  * Test if an AST node will always give the same result when _strictly_ compared
241
- * to a bolean value. This can happen if the expression can never be boolean, or
241
+ * to a boolean value. This can happen if the expression can never be boolean, or
242
242
  * if it is always the same boolean value.
243
243
  * @param {Scope} scope The scope in which the node was found.
244
244
  * @param {ASTNode} node The node to test
@@ -488,7 +488,7 @@ module.exports = {
488
488
  }
489
489
 
490
490
  /*
491
- * In theory we could handle short circuting assignment operators,
491
+ * In theory we could handle short-circuiting assignment operators,
492
492
  * for some constant values, but that would require walking the
493
493
  * scope to find the value of the variable being assigned. This is
494
494
  * dependant on https://github.com/eslint/eslint/issues/13776
@@ -30,9 +30,9 @@ function parseOptions(options) {
30
30
  }
31
31
 
32
32
  /**
33
- * Checks whether or not a node is a double logical nigating.
33
+ * Checks whether or not a node is a double logical negating.
34
34
  * @param {ASTNode} node An UnaryExpression node to check.
35
- * @returns {boolean} Whether or not the node is a double logical nigating.
35
+ * @returns {boolean} Whether or not the node is a double logical negating.
36
36
  */
37
37
  function isDoubleLogicalNegating(node) {
38
38
  return (
@@ -125,7 +125,7 @@ function isSafe(loopNode, reference) {
125
125
  * The reference is every reference of the upper scope's variable we are
126
126
  * looking now.
127
127
  *
128
- * It's safeafe if the reference matches one of the following condition.
128
+ * It's safe if the reference matches one of the following condition.
129
129
  * - is readonly.
130
130
  * - doesn't exist inside a local function and after the border.
131
131
  * @param {eslint-scope.Reference} upperRef A reference to check.
@@ -29,7 +29,7 @@ module.exports = {
29
29
  schema: [],
30
30
 
31
31
  messages: {
32
- preferLiteral: "The object literal notation {} is preferrable."
32
+ preferLiteral: "The object literal notation {} is preferable."
33
33
  }
34
34
  },
35
35
 
@@ -23,7 +23,7 @@ module.exports = {
23
23
  schema: [],
24
24
 
25
25
  messages: {
26
- noOcatal: "Octal literals should not be used."
26
+ noOctal: "Octal literals should not be used."
27
27
  }
28
28
  },
29
29
 
@@ -35,7 +35,7 @@ module.exports = {
35
35
  if (typeof node.value === "number" && /^0[0-9]/u.test(node.raw)) {
36
36
  context.report({
37
37
  node,
38
- messageId: "noOcatal"
38
+ messageId: "noOctal"
39
39
  });
40
40
  }
41
41
  }
@@ -21,6 +21,7 @@ function parseOptions(options) {
21
21
  let functions = true;
22
22
  let classes = true;
23
23
  let variables = true;
24
+ let allowNamedExports = false;
24
25
 
25
26
  if (typeof options === "string") {
26
27
  functions = (options !== "nofunc");
@@ -28,9 +29,10 @@ function parseOptions(options) {
28
29
  functions = options.functions !== false;
29
30
  classes = options.classes !== false;
30
31
  variables = options.variables !== false;
32
+ allowNamedExports = !!options.allowNamedExports;
31
33
  }
32
34
 
33
- return { functions, classes, variables };
35
+ return { functions, classes, variables, allowNamedExports };
34
36
  }
35
37
 
36
38
  /**
@@ -240,7 +242,8 @@ module.exports = {
240
242
  properties: {
241
243
  functions: { type: "boolean" },
242
244
  classes: { type: "boolean" },
243
- variables: { type: "boolean" }
245
+ variables: { type: "boolean" },
246
+ allowNamedExports: { type: "boolean" }
244
247
  },
245
248
  additionalProperties: false
246
249
  }
@@ -273,6 +276,16 @@ module.exports = {
273
276
  return false;
274
277
  }
275
278
 
279
+ const { identifier } = reference;
280
+
281
+ if (
282
+ options.allowNamedExports &&
283
+ identifier.parent.type === "ExportSpecifier" &&
284
+ identifier.parent.local === identifier
285
+ ) {
286
+ return false;
287
+ }
288
+
276
289
  const variable = reference.resolved;
277
290
 
278
291
  if (!variable || variable.defs.length === 0) {
@@ -136,7 +136,6 @@ module.exports = {};
136
136
 
137
137
  /**
138
138
  * @typedef {Object} RuleMetaDocs
139
- * @property {string} category The category of the rule.
140
139
  * @property {string} description The description of the rule.
141
140
  * @property {boolean} recommended If `true` then the rule is included in `eslint:recommended` preset.
142
141
  * @property {string} url The URL of the rule documentation.
@@ -147,6 +146,7 @@ module.exports = {};
147
146
  * @property {boolean} [deprecated] If `true` then the rule has been deprecated.
148
147
  * @property {RuleMetaDocs} docs The document information of the rule.
149
148
  * @property {"code"|"whitespace"} [fixable] The autofix type.
149
+ * @property {boolean} [hasSuggestions] If `true` then the rule provides suggestions.
150
150
  * @property {Record<string,string>} [messages] The messages the rule reports.
151
151
  * @property {string[]} [replacedBy] The IDs of the alternative rules.
152
152
  * @property {Array|Object} schema The option schema of the rule.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint",
3
- "version": "8.16.0",
3
+ "version": "8.17.0",
4
4
  "author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
5
5
  "description": "An AST-based pattern checker for JavaScript.",
6
6
  "bin": {
@@ -16,7 +16,9 @@
16
16
  "test": "node Makefile.js test",
17
17
  "test:cli": "mocha",
18
18
  "lint": "node Makefile.js lint",
19
+ "lint:docsjs": "node Makefile.js lintDocsJS",
19
20
  "fix": "node Makefile.js lint -- fix",
21
+ "fix:docsjs": "node Makefile.js lintDocsJS -- fix",
20
22
  "fuzz": "node Makefile.js fuzz",
21
23
  "generate-release": "node Makefile.js generateRelease",
22
24
  "generate-alpharelease": "node Makefile.js generatePrerelease -- alpha",