eslint 9.11.1 → 9.13.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.
@@ -30,6 +30,7 @@ const parserSymbol = Symbol.for("eslint.RuleTester.parser");
30
30
  const { ConfigArraySymbol } = require("@eslint/config-array");
31
31
  const { isSerializable } = require("../shared/serialization");
32
32
 
33
+ const jslang = require("../languages/js");
33
34
  const { SourceCode } = require("../languages/js/source-code");
34
35
 
35
36
  //------------------------------------------------------------------------------
@@ -47,6 +48,8 @@ const { SourceCode } = require("../languages/js/source-code");
47
48
  * @property {string} [name] Name for the test case.
48
49
  * @property {string} code Code for the test case.
49
50
  * @property {any[]} [options] Options for the test case.
51
+ * @property {Function} [before] Function to execute before testing the case.
52
+ * @property {Function} [after] Function to execute after testing the case regardless of its result.
50
53
  * @property {LanguageOptions} [languageOptions] The language options to use in the test case.
51
54
  * @property {{ [name: string]: any }} [settings] Settings for the test case.
52
55
  * @property {string} [filename] The fake filename for the test case. Useful for rules that make assertion about filenames.
@@ -61,6 +64,8 @@ const { SourceCode } = require("../languages/js/source-code");
61
64
  * @property {number | Array<TestCaseError | string | RegExp>} errors Expected errors.
62
65
  * @property {string | null} [output] The expected code after autofixes are applied. If set to `null`, the test runner will assert that no autofix is suggested.
63
66
  * @property {any[]} [options] Options for the test case.
67
+ * @property {Function} [before] Function to execute before testing the case.
68
+ * @property {Function} [after] Function to execute after testing the case regardless of its result.
64
69
  * @property {{ [name: string]: any }} [settings] Settings for the test case.
65
70
  * @property {string} [filename] The fake filename for the test case. Useful for rules that make assertion about filenames.
66
71
  * @property {LanguageOptions} [languageOptions] The language options to use in the test case.
@@ -105,6 +110,8 @@ const RuleTesterParameters = [
105
110
  "code",
106
111
  "filename",
107
112
  "options",
113
+ "before",
114
+ "after",
108
115
  "errors",
109
116
  "output",
110
117
  "only"
@@ -613,14 +620,26 @@ class RuleTester {
613
620
  }
614
621
  }
615
622
  },
616
- language: defaultConfig[0].language,
617
- languageOptions: {
618
- ...defaultConfig[0].languageOptions
619
- }
623
+ language: defaultConfig[0].language
620
624
  },
621
625
  ...defaultConfig.slice(1)
622
626
  ];
623
627
 
628
+ /**
629
+ * Runs a hook on the given item when it's assigned to the given property
630
+ * @param {string|Object} item Item to run the hook on
631
+ * @param {string} prop The property having the hook assigned to
632
+ * @throws {Error} If the property is not a function or that function throws an error
633
+ * @returns {void}
634
+ * @private
635
+ */
636
+ function runHook(item, prop) {
637
+ if (typeof item === "object" && hasOwnProperty(item, prop)) {
638
+ assert.strictEqual(typeof item[prop], "function", `Optional test case property '${prop}' must be a function`);
639
+ item[prop]();
640
+ }
641
+ }
642
+
624
643
  /**
625
644
  * Run the rule for the given item
626
645
  * @param {string|Object} item Item to run the rule against
@@ -652,7 +671,10 @@ class RuleTester {
652
671
  const calculatedConfig = proto[ConfigArraySymbol.finalizeConfig].apply(this, args);
653
672
 
654
673
  // wrap the parser to catch start/end property access
655
- calculatedConfig.languageOptions.parser = wrapParser(calculatedConfig.languageOptions.parser);
674
+ if (calculatedConfig.language === jslang) {
675
+ calculatedConfig.languageOptions.parser = wrapParser(calculatedConfig.languageOptions.parser);
676
+ }
677
+
656
678
  return calculatedConfig;
657
679
  };
658
680
 
@@ -673,17 +695,6 @@ class RuleTester {
673
695
  delete itemConfig[parameter];
674
696
  }
675
697
 
676
- // wrap any parsers
677
- if (itemConfig.languageOptions && itemConfig.languageOptions.parser) {
678
-
679
- const parser = itemConfig.languageOptions.parser;
680
-
681
- if (parser && typeof parser !== "object") {
682
- throw new Error("Parser must be an object with a parse() or parseForESLint() method.");
683
- }
684
-
685
- }
686
-
687
698
  /*
688
699
  * Create the config object from the tester config and this item
689
700
  * specific configurations.
@@ -1258,7 +1269,12 @@ class RuleTester {
1258
1269
  this.constructor[valid.only ? "itOnly" : "it"](
1259
1270
  sanitize(typeof valid === "object" ? valid.name || valid.code : valid),
1260
1271
  () => {
1261
- testValidTemplate(valid);
1272
+ try {
1273
+ runHook(valid, "before");
1274
+ testValidTemplate(valid);
1275
+ } finally {
1276
+ runHook(valid, "after");
1277
+ }
1262
1278
  }
1263
1279
  );
1264
1280
  });
@@ -1271,7 +1287,12 @@ class RuleTester {
1271
1287
  this.constructor[invalid.only ? "itOnly" : "it"](
1272
1288
  sanitize(invalid.name || invalid.code),
1273
1289
  () => {
1274
- testInvalidTemplate(invalid);
1290
+ try {
1291
+ runHook(invalid, "before");
1292
+ testInvalidTemplate(invalid);
1293
+ } finally {
1294
+ runHook(invalid, "after");
1295
+ }
1275
1296
  }
1276
1297
  );
1277
1298
  });
@@ -45,6 +45,9 @@ module.exports = {
45
45
  max: {
46
46
  type: "integer",
47
47
  minimum: 0
48
+ },
49
+ variant: {
50
+ enum: ["classic", "modified"]
48
51
  }
49
52
  },
50
53
  additionalProperties: false
@@ -61,16 +64,22 @@ module.exports = {
61
64
  create(context) {
62
65
  const option = context.options[0];
63
66
  let THRESHOLD = 20;
67
+ let VARIANT = "classic";
68
+
69
+ if (typeof option === "object") {
70
+ if (Object.hasOwn(option, "maximum") || Object.hasOwn(option, "max")) {
71
+ THRESHOLD = option.maximum || option.max;
72
+ }
64
73
 
65
- if (
66
- typeof option === "object" &&
67
- (Object.hasOwn(option, "maximum") || Object.hasOwn(option, "max"))
68
- ) {
69
- THRESHOLD = option.maximum || option.max;
74
+ if (Object.hasOwn(option, "variant")) {
75
+ VARIANT = option.variant;
76
+ }
70
77
  } else if (typeof option === "number") {
71
78
  THRESHOLD = option;
72
79
  }
73
80
 
81
+ const IS_MODIFIED_COMPLEXITY = VARIANT === "modified";
82
+
74
83
  //--------------------------------------------------------------------------
75
84
  // Helpers
76
85
  //--------------------------------------------------------------------------
@@ -112,7 +121,8 @@ module.exports = {
112
121
  AssignmentPattern: increaseComplexity,
113
122
 
114
123
  // Avoid `default`
115
- "SwitchCase[test]": increaseComplexity,
124
+ "SwitchCase[test]": () => IS_MODIFIED_COMPLEXITY || increaseComplexity(),
125
+ SwitchStatement: () => IS_MODIFIED_COMPLEXITY && increaseComplexity(),
116
126
 
117
127
  // Logical assignment operators have short-circuiting behavior
118
128
  AssignmentExpression(node) {
@@ -10,6 +10,7 @@
10
10
  */
11
11
  const activeFlags = new Map([
12
12
  ["test_only", "Used only for testing."],
13
+ ["unstable_config_lookup_from_file", "Look up eslint.config.js from the file being linted."],
13
14
  ["unstable_ts_config", "Enable TypeScript configuration files."]
14
15
  ]);
15
16
 
@@ -1179,6 +1179,9 @@ export namespace Linter {
1179
1179
  ruleId: string | null;
1180
1180
  message: string;
1181
1181
  messageId?: string | undefined;
1182
+ /**
1183
+ * @deprecated `nodeType` is deprecated and will be removed in the next major version.
1184
+ */
1182
1185
  nodeType?: string | undefined;
1183
1186
  fatal?: true | undefined;
1184
1187
  severity: Exclude<Severity, 0>;
@@ -1396,6 +1399,12 @@ export class ESLint {
1396
1399
 
1397
1400
  static readonly version: string;
1398
1401
 
1402
+ /**
1403
+ * The default configuration that ESLint uses internally. This is provided for tooling that wants to calculate configurations using the same defaults as ESLint.
1404
+ * Keep in mind that the default configuration may change from version to version, so you shouldn't rely on any particular keys or values to be present.
1405
+ */
1406
+ static readonly defaultConfig: Linter.Config[];
1407
+
1399
1408
  static outputFixes(results: ESLint.LintResult[]): Promise<void>;
1400
1409
 
1401
1410
  static getErrorResults(results: ESLint.LintResult[]): ESLint.LintResult[];
@@ -1655,6 +1664,9 @@ export namespace RuleTester {
1655
1664
  interface TestCaseError {
1656
1665
  message?: string | RegExp;
1657
1666
  messageId?: string;
1667
+ /**
1668
+ * @deprecated `type` is deprecated and will be removed in the next major version.
1669
+ */
1658
1670
  type?: string | undefined;
1659
1671
  data?: any;
1660
1672
  line?: number | undefined;
@@ -118,6 +118,11 @@ export interface BestPractices extends Linter.RulesRecord {
118
118
  * @default 20
119
119
  */
120
120
  maximum: number;
121
+ /**
122
+ * @default "classic"
123
+ * @since 9.12.0
124
+ */
125
+ variant: "classic" | "modified";
121
126
  }>
122
127
  | number,
123
128
  ]
@@ -185,6 +190,7 @@ export interface BestPractices extends Linter.RulesRecord {
185
190
  * Rule to enforce consistent newlines before and after dots.
186
191
  *
187
192
  * @since 0.21.0
193
+ * @deprecated since 8.53.0, please use the [corresponding rule](https://eslint.style/rules/js/dot-location) in `@stylistic/eslint-plugin-js`.
188
194
  * @see https://eslint.org/docs/rules/dot-location
189
195
  */
190
196
  "dot-location": Linter.RuleEntry<["object" | "property"]>;
@@ -417,6 +423,10 @@ export interface BestPractices extends Linter.RulesRecord {
417
423
  * @default false
418
424
  */
419
425
  allowEmptyCase: boolean;
426
+ /**
427
+ * @default false
428
+ */
429
+ reportUnusedFallthroughComment: boolean;
420
430
  }>,
421
431
  ]
422
432
  >;
@@ -425,6 +435,7 @@ export interface BestPractices extends Linter.RulesRecord {
425
435
  * Rule to disallow leading or trailing decimal points in numeric literals.
426
436
  *
427
437
  * @since 0.0.6
438
+ * @deprecated since 8.53.0, please use the [corresponding rule](https://eslint.style/rules/js/no-floating-decimal) in `@stylistic/eslint-plugin-js`.
428
439
  * @see https://eslint.org/docs/rules/no-floating-decimal
429
440
  */
430
441
  "no-floating-decimal": Linter.RuleEntry<[]>;
@@ -601,6 +612,7 @@ export interface BestPractices extends Linter.RulesRecord {
601
612
  * Rule to disallow multiple spaces.
602
613
  *
603
614
  * @since 0.9.0
615
+ * @deprecated since 8.53.0, please use the [corresponding rule](https://eslint.style/rules/js/no-multi-spaces) in `@stylistic/eslint-plugin-js`.
604
616
  * @see https://eslint.org/docs/rules/no-multi-spaces
605
617
  */
606
618
  "no-multi-spaces": Linter.RuleEntry<
@@ -872,6 +884,15 @@ export interface BestPractices extends Linter.RulesRecord {
872
884
  */
873
885
  "no-unused-labels": Linter.RuleEntry<[]>;
874
886
 
887
+ /**
888
+ * Disallow variable assignments when the value is not used
889
+ *
890
+ *
891
+ * @since 9.0.0-alpha.1
892
+ * @see https://eslint.org/docs/latest/rules/no-useless-assignment
893
+ */
894
+ "no-useless-assignment": Linter.RuleEntry<[]>;
895
+
875
896
  /**
876
897
  * Disallow useless backreferences in regular expressions
877
898
  *
@@ -1045,12 +1066,21 @@ export interface BestPractices extends Linter.RulesRecord {
1045
1066
  "require-await": Linter.RuleEntry<[]>;
1046
1067
 
1047
1068
  /**
1048
- * Rule to enforce the use of `u` flag on RegExp.
1069
+ * Enforce the use of `u` or `v` flag on RegExp
1049
1070
  *
1050
1071
  * @since 5.3.0
1051
1072
  * @see https://eslint.org/docs/rules/require-unicode-regexp
1052
1073
  */
1053
- "require-unicode-regexp": Linter.RuleEntry<[]>;
1074
+ "require-unicode-regexp": Linter.RuleEntry<
1075
+ [
1076
+ Partial<{
1077
+ /**
1078
+ * @default false
1079
+ */
1080
+ requireFlag: "u" | "v";
1081
+ }>,
1082
+ ]
1083
+ >;
1054
1084
 
1055
1085
  /**
1056
1086
  * Rule to require `var` declarations be placed at the top of their containing scope.
@@ -1064,6 +1094,7 @@ export interface BestPractices extends Linter.RulesRecord {
1064
1094
  * Rule to require parentheses around immediate `function` invocations.
1065
1095
  *
1066
1096
  * @since 0.0.9
1097
+ * @deprecated since 8.53.0, please use the [corresponding rule](https://eslint.style/rules/js/wrap-iife) in `@stylistic/eslint-plugin-js`.
1067
1098
  * @see https://eslint.org/docs/rules/wrap-iife
1068
1099
  */
1069
1100
  "wrap-iife": Linter.RuleEntry<
@@ -191,6 +191,24 @@ export interface Deprecated extends Linter.RulesRecord {
191
191
  */
192
192
  "no-negated-in-lhs": Linter.RuleEntry<[]>;
193
193
 
194
+ /**
195
+ * Rule to disallow `Object` constructors.
196
+ *
197
+ * @since 0.0.9
198
+ * @deprecated since 8.50.0, use [`no-object-constructor`](https://eslint.org/docs/rules/no-object-constructor) instead.
199
+ * @see https://eslint.org/docs/rules/no-object-constructor
200
+ */
201
+ "no-new-object": Linter.RuleEntry<[]>;
202
+
203
+ /**
204
+ * Rule to disallow `new` operators with the `Symbol` object.
205
+ *
206
+ * @since 2.0.0-beta.1
207
+ * @deprecated since 8.27.0, use [`no-new-native-nonconstructor`](https://eslint.org/docs/rules/no-new-native-nonconstructor) instead.
208
+ * @see https://eslint.org/docs/rules/no-new-symbol
209
+ */
210
+ "no-new-symbol": Linter.RuleEntry<[]>;
211
+
194
212
  /**
195
213
  * Rule to disallow spacing between function identifiers and their applications.
196
214
  *
@@ -214,81 +232,4 @@ export interface Deprecated extends Linter.RulesRecord {
214
232
  }>,
215
233
  ]
216
234
  >;
217
-
218
- /**
219
- * Rule to require JSDoc comments.
220
- *
221
- * @since 1.4.0
222
- * @deprecated since 5.10.0
223
- * @see https://eslint.org/docs/rules/require-jsdoc
224
- */
225
- "require-jsdoc": Linter.RuleEntry<
226
- [
227
- Partial<{
228
- require: Partial<{
229
- /**
230
- * @default true
231
- */
232
- FunctionDeclaration: boolean;
233
- /**
234
- * @default false
235
- */
236
- MethodDefinition: boolean;
237
- /**
238
- * @default false
239
- */
240
- ClassDeclaration: boolean;
241
- /**
242
- * @default false
243
- */
244
- ArrowFunctionExpression: boolean;
245
- /**
246
- * @default false
247
- */
248
- FunctionExpression: boolean;
249
- }>;
250
- }>,
251
- ]
252
- >;
253
-
254
- /**
255
- * Rule to enforce valid JSDoc comments.
256
- *
257
- * @since 0.4.0
258
- * @deprecated since 5.10.0
259
- * @see https://eslint.org/docs/rules/valid-jsdoc
260
- */
261
- "valid-jsdoc": Linter.RuleEntry<
262
- [
263
- Partial<{
264
- prefer: Record<string, string>;
265
- preferType: Record<string, string>;
266
- /**
267
- * @default true
268
- */
269
- requireReturn: boolean;
270
- /**
271
- * @default true
272
- */
273
- requireReturnType: boolean;
274
- /**
275
- * @remarks
276
- * Also accept for regular expression pattern
277
- */
278
- matchDescription: string;
279
- /**
280
- * @default true
281
- */
282
- requireParamDescription: boolean;
283
- /**
284
- * @default true
285
- */
286
- requireReturnDescription: boolean;
287
- /**
288
- * @default true
289
- */
290
- requireParamType: boolean;
291
- }>,
292
- ]
293
- >;
294
235
  }
@@ -52,6 +52,7 @@ export interface ECMAScript6 extends Linter.RulesRecord {
52
52
  * Rule to require parentheses around arrow function arguments.
53
53
  *
54
54
  * @since 1.0.0-rc-1
55
+ * @deprecated since 8.53.0, please use the [corresponding rule](https://eslint.style/rules/js/arrow-parens) in `@stylistic/eslint-plugin-js`.
55
56
  * @see https://eslint.org/docs/rules/arrow-parens
56
57
  */
57
58
  "arrow-parens":
@@ -72,6 +73,7 @@ export interface ECMAScript6 extends Linter.RulesRecord {
72
73
  * Rule to enforce consistent spacing before and after the arrow in arrow functions.
73
74
  *
74
75
  * @since 1.0.0-rc-1
76
+ * @deprecated since 8.53.0, please use the [corresponding rule](https://eslint.style/rules/js/arrow-spacing) in `@stylistic/eslint-plugin-js`.
75
77
  * @see https://eslint.org/docs/rules/arrow-spacing
76
78
  */
77
79
  "arrow-spacing": Linter.RuleEntry<[]>;
@@ -91,6 +93,7 @@ export interface ECMAScript6 extends Linter.RulesRecord {
91
93
  * Rule to enforce consistent spacing around `*` operators in generator functions.
92
94
  *
93
95
  * @since 0.17.0
96
+ * @deprecated since 8.53.0, please use the [corresponding rule](https://eslint.style/rules/js/generator-star-spacing) in `@stylistic/eslint-plugin-js`.
94
97
  * @see https://eslint.org/docs/rules/generator-star-spacing
95
98
  */
96
99
  "generator-star-spacing": Linter.RuleEntry<
@@ -168,6 +171,7 @@ export interface ECMAScript6 extends Linter.RulesRecord {
168
171
  * Rule to disallow arrow functions where they could be confused with comparisons.
169
172
  *
170
173
  * @since 2.0.0-alpha-2
174
+ * @deprecated since 8.53.0, please use the [corresponding rule](https://eslint.style/rules/js/no-confusing-arrow) in `@stylistic/eslint-plugin-js`.
171
175
  * @see https://eslint.org/docs/rules/no-confusing-arrow
172
176
  */
173
177
  "no-confusing-arrow": Linter.RuleEntry<
@@ -221,15 +225,15 @@ export interface ECMAScript6 extends Linter.RulesRecord {
221
225
  >;
222
226
 
223
227
  /**
224
- * Rule to disallow `new` operators with the `Symbol` object.
225
- *
228
+ * Rule to disallow `new` operator with global non-constructor functions
229
+ *
226
230
  * @remarks
227
231
  * Recommended by ESLint, the rule was enabled in `eslint:recommended`.
228
232
  *
229
- * @since 2.0.0-beta.1
230
- * @see https://eslint.org/docs/rules/no-new-symbol
233
+ * @since 8.27.0
234
+ * @see https://eslint.org/docs/rules/no-new-native-nonconstructor
231
235
  */
232
- "no-new-symbol": Linter.RuleEntry<[]>;
236
+ "no-new-native-nonconstructor": Linter.RuleEntry<[]>;
233
237
 
234
238
  /**
235
239
  * Rule to disallow specified names in exports.
@@ -324,7 +328,16 @@ export interface ECMAScript6 extends Linter.RulesRecord {
324
328
  * @since 2.9.0
325
329
  * @see https://eslint.org/docs/rules/no-useless-computed-key
326
330
  */
327
- "no-useless-computed-key": Linter.RuleEntry<[]>;
331
+ "no-useless-computed-key": Linter.RuleEntry<
332
+ [
333
+ Partial<{
334
+ /**
335
+ * @default true
336
+ */
337
+ enforceForClassMembers: boolean;
338
+ }>,
339
+ ]
340
+ >;
328
341
 
329
342
  /**
330
343
  * Rule to disallow unnecessary constructors.
@@ -537,6 +550,7 @@ export interface ECMAScript6 extends Linter.RulesRecord {
537
550
  * Rule to enforce spacing between rest and spread operators and their expressions.
538
551
  *
539
552
  * @since 2.12.0
553
+ * @deprecated since 8.53.0, please use the [corresponding rule](https://eslint.style/rules/js/rest-spread-spacing) in `@stylistic/eslint-plugin-js`.
540
554
  * @see https://eslint.org/docs/rules/rest-spread-spacing
541
555
  */
542
556
  "rest-spread-spacing": Linter.RuleEntry<["never" | "always"]>;
@@ -586,6 +600,7 @@ export interface ECMAScript6 extends Linter.RulesRecord {
586
600
  * Rule to require or disallow spacing around embedded expressions of template strings.
587
601
  *
588
602
  * @since 2.0.0-rc.0
603
+ * @deprecated since 8.53.0, please use the [corresponding rule](https://eslint.style/rules/js/template-curly-spacing) in `@stylistic/eslint-plugin-js`.
589
604
  * @see https://eslint.org/docs/rules/template-curly-spacing
590
605
  */
591
606
  "template-curly-spacing": Linter.RuleEntry<["never" | "always"]>;
@@ -594,6 +609,7 @@ export interface ECMAScript6 extends Linter.RulesRecord {
594
609
  * Rule to require or disallow spacing around the `*` in `yield*` expressions.
595
610
  *
596
611
  * @since 2.0.0-alpha-1
612
+ * @deprecated since 8.53.0, please use the [corresponding rule](https://eslint.style/rules/js/yield-star-spacing) in `@stylistic/eslint-plugin-js`.
597
613
  * @see https://eslint.org/docs/rules/yield-star-spacing
598
614
  */
599
615
  "yield-star-spacing": Linter.RuleEntry<
@@ -280,6 +280,7 @@ export interface PossibleErrors extends Linter.RulesRecord {
280
280
  * Rule to disallow unnecessary parentheses.
281
281
  *
282
282
  * @since 0.1.4
283
+ * @deprecated since 8.53.0, please use the [corresponding rule](https://eslint.style/rules/js/no-extra-parens) in `@stylistic/eslint-plugin-js`.
283
284
  * @see https://eslint.org/docs/rules/no-extra-parens
284
285
  */
285
286
  "no-extra-parens":
@@ -319,6 +320,7 @@ export interface PossibleErrors extends Linter.RulesRecord {
319
320
  * Recommended by ESLint, the rule was enabled in `eslint:recommended`.
320
321
  *
321
322
  * @since 0.0.9
323
+ * @deprecated since 8.53.0, please use the [corresponding rule](https://eslint.style/rules/js/no-extra-semi) in `@stylistic/eslint-plugin-js`.
322
324
  * @see https://eslint.org/docs/rules/no-extra-semi
323
325
  */
324
326
  "no-extra-semi": Linter.RuleEntry<[]>;