eslint 10.2.1 → 10.4.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.
Files changed (52) hide show
  1. package/README.md +3 -3
  2. package/lib/config/config-loader.js +1 -1
  3. package/lib/config-api.js +7 -1
  4. package/lib/eslint/eslint.js +29 -6
  5. package/lib/linter/code-path-analysis/code-path-analyzer.js +7 -7
  6. package/lib/linter/code-path-analysis/debug-helpers.js +12 -1
  7. package/lib/linter/code-path-analysis/id-generator.js +1 -2
  8. package/lib/rules/capitalized-comments.js +3 -1
  9. package/lib/rules/class-methods-use-this.js +1 -2
  10. package/lib/rules/default-param-last.js +1 -2
  11. package/lib/rules/eqeqeq.js +3 -1
  12. package/lib/rules/for-direction.js +55 -11
  13. package/lib/rules/func-name-matching.js +2 -0
  14. package/lib/rules/func-style.js +1 -2
  15. package/lib/rules/init-declarations.js +7 -8
  16. package/lib/rules/logical-assignment-operators.js +4 -1
  17. package/lib/rules/max-classes-per-file.js +4 -2
  18. package/lib/rules/max-depth.js +3 -0
  19. package/lib/rules/max-lines-per-function.js +3 -0
  20. package/lib/rules/max-lines.js +3 -0
  21. package/lib/rules/max-nested-callbacks.js +3 -0
  22. package/lib/rules/max-params.js +4 -2
  23. package/lib/rules/max-statements.js +3 -0
  24. package/lib/rules/no-array-constructor.js +1 -2
  25. package/lib/rules/no-dupe-class-members.js +1 -2
  26. package/lib/rules/no-duplicate-imports.js +1 -2
  27. package/lib/rules/no-empty-function.js +1 -2
  28. package/lib/rules/no-invalid-this.js +1 -2
  29. package/lib/rules/no-loop-func.js +1 -2
  30. package/lib/rules/no-loss-of-precision.js +1 -2
  31. package/lib/rules/no-magic-numbers.js +29 -24
  32. package/lib/rules/no-restricted-exports.js +8 -8
  33. package/lib/rules/no-restricted-globals.js +1 -2
  34. package/lib/rules/no-restricted-imports.js +1 -2
  35. package/lib/rules/no-restricted-properties.js +2 -0
  36. package/lib/rules/no-restricted-syntax.js +2 -0
  37. package/lib/rules/no-shadow.js +1 -2
  38. package/lib/rules/no-unassigned-vars.js +1 -2
  39. package/lib/rules/no-unused-expressions.js +1 -2
  40. package/lib/rules/no-unused-private-class-members.js +201 -1
  41. package/lib/rules/no-unused-vars.js +50 -53
  42. package/lib/rules/no-use-before-define.js +1 -2
  43. package/lib/rules/no-useless-concat.js +2 -2
  44. package/lib/rules/no-useless-constructor.js +4 -4
  45. package/lib/rules/no-var.js +1 -2
  46. package/lib/rules/object-shorthand.js +3 -1
  47. package/lib/rules/one-var.js +3 -1
  48. package/lib/rules/prefer-arrow-callback.js +1 -2
  49. package/lib/rules/require-await.js +6 -4
  50. package/lib/rules/utils/ast-utils.js +36 -4
  51. package/lib/types/config-api.d.ts +2 -1
  52. package/package.json +8 -7
@@ -229,11 +229,10 @@ function hasReferenceBeforeDeclaration(variable) {
229
229
  module.exports = {
230
230
  meta: {
231
231
  type: "suggestion",
232
- dialects: ["typescript", "javascript"],
233
- language: "javascript",
234
232
 
235
233
  docs: {
236
234
  description: "Require `let` or `const` instead of `var`",
235
+ dialects: ["JavaScript", "TypeScript"],
237
236
  recommended: false,
238
237
  url: "https://eslint.org/docs/latest/rules/no-var",
239
238
  },
@@ -186,6 +186,8 @@ module.exports = {
186
186
  ],
187
187
  },
188
188
 
189
+ defaultOptions: ["always"],
190
+
189
191
  messages: {
190
192
  expectedAllPropertiesShorthanded:
191
193
  "Expected shorthand for all properties.",
@@ -201,7 +203,7 @@ module.exports = {
201
203
  },
202
204
 
203
205
  create(context) {
204
- const APPLY = context.options[0] || OPTIONS.always;
206
+ const APPLY = context.options[0];
205
207
  const APPLY_TO_METHODS =
206
208
  APPLY === OPTIONS.methods || APPLY === OPTIONS.always;
207
209
  const APPLY_TO_PROPS =
@@ -89,6 +89,8 @@ module.exports = {
89
89
  },
90
90
  ],
91
91
 
92
+ defaultOptions: ["always"],
93
+
92
94
  messages: {
93
95
  combineUninitialized:
94
96
  "Combine this with the previous '{{type}}' statement with uninitialized variables.",
@@ -109,7 +111,7 @@ module.exports = {
109
111
  const MODE_ALWAYS = "always";
110
112
  const MODE_NEVER = "never";
111
113
  const MODE_CONSECUTIVE = "consecutive";
112
- const mode = context.options[0] || MODE_ALWAYS;
114
+ const mode = context.options[0];
113
115
 
114
116
  const options = {};
115
117
 
@@ -158,8 +158,6 @@ function hasDuplicateParams(paramsList) {
158
158
  module.exports = {
159
159
  meta: {
160
160
  type: "suggestion",
161
- dialects: ["javascript", "typescript"],
162
- language: "javascript",
163
161
 
164
162
  defaultOptions: [
165
163
  { allowNamedFunctions: false, allowUnboundThis: true },
@@ -167,6 +165,7 @@ module.exports = {
167
165
 
168
166
  docs: {
169
167
  description: "Require using arrow functions for callbacks",
168
+ dialects: ["JavaScript", "TypeScript"],
170
169
  recommended: false,
171
170
  frozen: true,
172
171
  url: "https://eslint.org/docs/latest/rules/prefer-arrow-callback",
@@ -110,12 +110,14 @@ module.exports = {
110
110
  */
111
111
  const nextToken = sourceCode.getTokenAfter(asyncToken);
112
112
  const addSemiColon =
113
- nextToken.type === "Punctuator" &&
114
- (nextToken.value === "[" || nextToken.value === "(") &&
115
- (nodeWithAsyncKeyword.type === "MethodDefinition" ||
113
+ ((astUtils.isOpeningParenToken(nextToken) &&
116
114
  astUtils.isStartOfExpressionStatement(
117
115
  nodeWithAsyncKeyword,
118
- )) &&
116
+ )) ||
117
+ (nodeWithAsyncKeyword.type === "MethodDefinition" &&
118
+ astUtils.canContinueExpressionInClassBody(
119
+ nextToken,
120
+ ))) &&
119
121
  astUtils.needsPrecedingSemicolon(
120
122
  sourceCode,
121
123
  nodeWithAsyncKeyword,
@@ -1258,12 +1258,31 @@ function isStartOfExpressionStatement(node) {
1258
1258
  }
1259
1259
 
1260
1260
  /**
1261
- * Determines whether an opening parenthesis `(`, bracket `[` or backtick ``` ` ``` needs to be preceded by a semicolon.
1262
- * This opening parenthesis or bracket should be at the start of an `ExpressionStatement`, a `MethodDefinition` or at
1263
- * the start of the body of an `ArrowFunctionExpression`.
1261
+ * Checks whether a token can cause continuation of a preceding expression
1262
+ * (for example, of a class field initializer expression) in a class body.
1263
+ * This function checks specifically for tokens that can appear at the start
1264
+ * of a class member: `[` (computed key), `*` (generator method), `in` or `instanceof` (valid keys)
1265
+ * Without a preceding semicolon, these tokens would be parsed as index access or operators.
1266
+ * @param {Token} token The token to check.
1267
+ * @returns {boolean} Whether the token can cause continuation of a preceding expression.
1268
+ */
1269
+ function canContinueExpressionInClassBody(token) {
1270
+ return (
1271
+ (token.type === "Punctuator" &&
1272
+ (token.value === "[" || token.value === "*")) ||
1273
+ // Different parsers may return these tokens as either "Identifier" or "Keyword"
1274
+ ((token.type === "Identifier" || token.type === "Keyword") &&
1275
+ (token.value === "in" || token.value === "instanceof"))
1276
+ );
1277
+ }
1278
+
1279
+ /**
1280
+ * Determines whether an opening parenthesis `(`, bracket `[`, asterisk `*`, or backtick ``` ` ``` needs to be preceded by a semicolon.
1281
+ * This opening parenthesis or bracket should be at the start of an `ExpressionStatement`, a `MethodDefinition`, a `PropertyDefinition`,
1282
+ * or at the start of the body of an `ArrowFunctionExpression`.
1264
1283
  * @type {(sourceCode: SourceCode, node: ASTNode) => boolean}
1265
1284
  * @param {SourceCode} sourceCode The source code object.
1266
- * @param {ASTNode} node A node at the position where an opening parenthesis or bracket will be inserted.
1285
+ * @param {ASTNode} node A node at the position where an opening parenthesis, bracket, or asterisk will be inserted.
1267
1286
  * @returns {boolean} Whether a semicolon is required before the opening parenthesis or bracket.
1268
1287
  */
1269
1288
  let needsPrecedingSemicolon;
@@ -1354,6 +1373,18 @@ let needsPrecedingSemicolon;
1354
1373
 
1355
1374
  const prevNode = sourceCode.getNodeByRangeIndex(prevToken.range[0]);
1356
1375
 
1376
+ // Uninitialized class fields don't need a semicolon
1377
+ if (
1378
+ // Key
1379
+ (prevNode.parent.type === "PropertyDefinition" &&
1380
+ prevNode.parent.key === prevNode) ||
1381
+ // Closing bracket of a computed key
1382
+ (prevNode.type === "PropertyDefinition" &&
1383
+ isClosingBracketToken(prevToken))
1384
+ ) {
1385
+ return false;
1386
+ }
1387
+
1357
1388
  if (
1358
1389
  prevNode.type === "TSDeclareFunction" ||
1359
1390
  prevNode.parent.type === "TSImportEqualsDeclaration" ||
@@ -2842,6 +2873,7 @@ module.exports = {
2842
2873
  isTopLevelExpressionStatement,
2843
2874
  isDirective,
2844
2875
  isStartOfExpressionStatement,
2876
+ canContinueExpressionInClassBody,
2845
2877
  needsPrecedingSemicolon,
2846
2878
  isImportAttributeKey,
2847
2879
  getOpeningParenOfParams,
@@ -7,6 +7,7 @@ import {
7
7
  type Config,
8
8
  defineConfig,
9
9
  globalIgnores,
10
+ includeIgnoreFile,
10
11
  } from "@eslint/config-helpers";
11
12
 
12
- export { type Config, defineConfig, globalIgnores };
13
+ export { type Config, defineConfig, globalIgnores, includeIgnoreFile };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint",
3
- "version": "10.2.1",
3
+ "version": "10.4.0",
4
4
  "author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
5
5
  "description": "An AST-based pattern checker for JavaScript.",
6
6
  "type": "commonjs",
@@ -72,6 +72,8 @@
72
72
  "test": "node Makefile.js test",
73
73
  "test:browser": "node Makefile.js cypress",
74
74
  "test:cli": "mocha",
75
+ "test:ecosystem": "node tools/test-ecosystem/index.mjs",
76
+ "test:ecosystem:update": "node tools/test-ecosystem/update.mjs",
75
77
  "test:emfile": "node tools/check-emfile-handling.js",
76
78
  "test:fuzz": "node Makefile.js fuzz",
77
79
  "test:performance": "node Makefile.js perf",
@@ -120,7 +122,7 @@
120
122
  "@eslint-community/eslint-utils": "^4.8.0",
121
123
  "@eslint-community/regexpp": "^4.12.2",
122
124
  "@eslint/config-array": "^0.23.5",
123
- "@eslint/config-helpers": "^0.5.5",
125
+ "@eslint/config-helpers": "^0.6.0",
124
126
  "@eslint/core": "^1.2.1",
125
127
  "@eslint/plugin-kit": "^0.7.1",
126
128
  "@humanfs/node": "^0.16.6",
@@ -157,7 +159,7 @@
157
159
  "@eslint/json": "^1.2.0",
158
160
  "@types/esquery": "^1.5.4",
159
161
  "@types/node": "^22.13.14",
160
- "@typescript-eslint/parser": "^8.56.0",
162
+ "@typescript-eslint/parser": "^8.58.2",
161
163
  "babel-loader": "^8.0.5",
162
164
  "c8": "^11.0.0",
163
165
  "chai": "^4.0.1",
@@ -181,7 +183,7 @@
181
183
  "got": "^11.8.3",
182
184
  "gray-matter": "^4.0.3",
183
185
  "jiti": "^2.6.1",
184
- "knip": "^5.60.2",
186
+ "knip": "^6.13.1",
185
187
  "lint-staged": "^11.0.0",
186
188
  "markdown-it": "^12.2.0",
187
189
  "markdown-it-container": "^3.0.0",
@@ -196,15 +198,14 @@
196
198
  "mocha": "^11.7.1",
197
199
  "node-polyfill-webpack-plugin": "^1.0.3",
198
200
  "npm-license": "^0.3.3",
199
- "prettier": "3.8.2",
201
+ "prettier": "3.8.3",
200
202
  "progress": "^2.0.3",
201
203
  "proxyquire": "^2.0.1",
202
- "recast": "^0.23.0",
203
204
  "regenerator-runtime": "^0.14.0",
204
205
  "semver": "^7.5.3",
205
206
  "shelljs": "^0.10.0",
206
207
  "sinon": "^11.0.0",
207
- "typescript": "^5.9.3",
208
+ "typescript": "^6.0.3",
208
209
  "webpack": "^5.23.0",
209
210
  "webpack-cli": "^4.5.0",
210
211
  "yorkie": "^2.0.0"