eslint 8.47.0 → 8.57.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 (118) hide show
  1. package/README.md +18 -13
  2. package/bin/eslint.js +38 -5
  3. package/conf/rule-type-list.json +25 -33
  4. package/lib/api.js +29 -1
  5. package/lib/cli-engine/cli-engine.js +2 -2
  6. package/lib/cli-engine/lint-result-cache.js +18 -6
  7. package/lib/cli.js +36 -6
  8. package/lib/config/flat-config-schema.js +124 -61
  9. package/lib/config/rule-validator.js +2 -1
  10. package/lib/eslint/eslint-helpers.js +9 -11
  11. package/lib/eslint/eslint.js +7 -0
  12. package/lib/eslint/flat-eslint.js +33 -18
  13. package/lib/linter/apply-disable-directives.js +127 -13
  14. package/lib/linter/code-path-analysis/code-path-analyzer.js +32 -24
  15. package/lib/linter/code-path-analysis/code-path-segment.js +52 -24
  16. package/lib/linter/code-path-analysis/code-path-state.js +1108 -243
  17. package/lib/linter/code-path-analysis/code-path.js +128 -33
  18. package/lib/linter/code-path-analysis/fork-context.js +173 -72
  19. package/lib/linter/config-comment-parser.js +36 -2
  20. package/lib/linter/linter.js +183 -82
  21. package/lib/options.js +24 -3
  22. package/lib/rule-tester/flat-rule-tester.js +113 -25
  23. package/lib/rule-tester/rule-tester.js +176 -23
  24. package/lib/rules/array-bracket-newline.js +3 -0
  25. package/lib/rules/array-bracket-spacing.js +3 -0
  26. package/lib/rules/array-callback-return.js +175 -25
  27. package/lib/rules/array-element-newline.js +3 -0
  28. package/lib/rules/arrow-parens.js +3 -0
  29. package/lib/rules/arrow-spacing.js +3 -0
  30. package/lib/rules/block-spacing.js +3 -0
  31. package/lib/rules/brace-style.js +3 -0
  32. package/lib/rules/comma-dangle.js +3 -0
  33. package/lib/rules/comma-spacing.js +3 -0
  34. package/lib/rules/comma-style.js +3 -0
  35. package/lib/rules/computed-property-spacing.js +3 -0
  36. package/lib/rules/consistent-return.js +32 -7
  37. package/lib/rules/constructor-super.js +37 -14
  38. package/lib/rules/dot-location.js +3 -0
  39. package/lib/rules/eol-last.js +3 -0
  40. package/lib/rules/for-direction.js +38 -24
  41. package/lib/rules/func-call-spacing.js +3 -0
  42. package/lib/rules/function-call-argument-newline.js +3 -0
  43. package/lib/rules/function-paren-newline.js +3 -0
  44. package/lib/rules/generator-star-spacing.js +3 -0
  45. package/lib/rules/getter-return.js +33 -8
  46. package/lib/rules/implicit-arrow-linebreak.js +3 -0
  47. package/lib/rules/indent.js +3 -0
  48. package/lib/rules/index.js +1 -0
  49. package/lib/rules/jsx-quotes.js +3 -0
  50. package/lib/rules/key-spacing.js +3 -0
  51. package/lib/rules/keyword-spacing.js +3 -0
  52. package/lib/rules/linebreak-style.js +3 -0
  53. package/lib/rules/lines-around-comment.js +3 -0
  54. package/lib/rules/lines-between-class-members.js +95 -7
  55. package/lib/rules/logical-assignment-operators.js +31 -3
  56. package/lib/rules/max-len.js +3 -0
  57. package/lib/rules/max-statements-per-line.js +3 -0
  58. package/lib/rules/multiline-ternary.js +3 -0
  59. package/lib/rules/new-parens.js +3 -0
  60. package/lib/rules/newline-per-chained-call.js +3 -0
  61. package/lib/rules/no-array-constructor.js +85 -6
  62. package/lib/rules/no-confusing-arrow.js +3 -0
  63. package/lib/rules/no-console.js +74 -2
  64. package/lib/rules/no-extra-parens.js +3 -0
  65. package/lib/rules/no-extra-semi.js +3 -0
  66. package/lib/rules/no-fallthrough.js +42 -14
  67. package/lib/rules/no-floating-decimal.js +3 -0
  68. package/lib/rules/no-invalid-this.js +1 -1
  69. package/lib/rules/no-misleading-character-class.js +65 -15
  70. package/lib/rules/no-mixed-operators.js +3 -0
  71. package/lib/rules/no-mixed-spaces-and-tabs.js +3 -0
  72. package/lib/rules/no-multi-spaces.js +3 -0
  73. package/lib/rules/no-multiple-empty-lines.js +3 -0
  74. package/lib/rules/no-new-object.js +7 -0
  75. package/lib/rules/no-object-constructor.js +117 -0
  76. package/lib/rules/no-promise-executor-return.js +157 -16
  77. package/lib/rules/no-prototype-builtins.js +90 -2
  78. package/lib/rules/no-restricted-imports.js +54 -31
  79. package/lib/rules/no-restricted-properties.js +15 -28
  80. package/lib/rules/no-tabs.js +3 -0
  81. package/lib/rules/no-this-before-super.js +38 -11
  82. package/lib/rules/no-trailing-spaces.js +3 -0
  83. package/lib/rules/no-unreachable-loop.js +47 -12
  84. package/lib/rules/no-unreachable.js +39 -10
  85. package/lib/rules/no-useless-return.js +35 -4
  86. package/lib/rules/no-whitespace-before-property.js +3 -0
  87. package/lib/rules/nonblock-statement-body-position.js +3 -0
  88. package/lib/rules/object-curly-newline.js +3 -0
  89. package/lib/rules/object-curly-spacing.js +3 -0
  90. package/lib/rules/object-property-newline.js +3 -0
  91. package/lib/rules/one-var-declaration-per-line.js +3 -0
  92. package/lib/rules/operator-linebreak.js +3 -0
  93. package/lib/rules/padded-blocks.js +3 -0
  94. package/lib/rules/padding-line-between-statements.js +3 -0
  95. package/lib/rules/quote-props.js +3 -0
  96. package/lib/rules/quotes.js +3 -0
  97. package/lib/rules/require-atomic-updates.js +21 -7
  98. package/lib/rules/rest-spread-spacing.js +3 -0
  99. package/lib/rules/semi-spacing.js +3 -0
  100. package/lib/rules/semi-style.js +3 -0
  101. package/lib/rules/semi.js +3 -0
  102. package/lib/rules/space-before-blocks.js +3 -0
  103. package/lib/rules/space-before-function-paren.js +3 -0
  104. package/lib/rules/space-in-parens.js +3 -0
  105. package/lib/rules/space-infix-ops.js +3 -0
  106. package/lib/rules/space-unary-ops.js +3 -0
  107. package/lib/rules/spaced-comment.js +3 -0
  108. package/lib/rules/switch-colon-spacing.js +3 -0
  109. package/lib/rules/template-curly-spacing.js +3 -0
  110. package/lib/rules/template-tag-spacing.js +3 -0
  111. package/lib/rules/utils/ast-utils.js +111 -1
  112. package/lib/rules/wrap-iife.js +3 -0
  113. package/lib/rules/wrap-regex.js +3 -0
  114. package/lib/rules/yield-star-spacing.js +3 -0
  115. package/lib/shared/severity.js +49 -0
  116. package/lib/source-code/source-code.js +329 -3
  117. package/messages/eslintrc-incompat.js +1 -1
  118. package/package.json +24 -17
@@ -5,6 +5,17 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ //-----------------------------------------------------------------------------
9
+ // Requirements
10
+ //-----------------------------------------------------------------------------
11
+
12
+ /*
13
+ * Note: This can be removed in ESLint v9 because structuredClone is available globally
14
+ * starting in Node.js v17.
15
+ */
16
+ const structuredClone = require("@ungap/structured-clone").default;
17
+ const { normalizeSeverityToNumber } = require("../shared/severity");
18
+
8
19
  //-----------------------------------------------------------------------------
9
20
  // Type Definitions
10
21
  //-----------------------------------------------------------------------------
@@ -42,6 +53,15 @@ function isNonNullObject(value) {
42
53
  return typeof value === "object" && value !== null;
43
54
  }
44
55
 
56
+ /**
57
+ * Check if a value is a non-null non-array object.
58
+ * @param {any} value The value to check.
59
+ * @returns {boolean} `true` if the value is a non-null non-array object.
60
+ */
61
+ function isNonArrayObject(value) {
62
+ return isNonNullObject(value) && !Array.isArray(value);
63
+ }
64
+
45
65
  /**
46
66
  * Check if a value is undefined.
47
67
  * @param {any} value The value to check.
@@ -52,19 +72,27 @@ function isUndefined(value) {
52
72
  }
53
73
 
54
74
  /**
55
- * Deeply merges two objects.
75
+ * Deeply merges two non-array objects.
56
76
  * @param {Object} first The base object.
57
77
  * @param {Object} second The overrides object.
78
+ * @param {Map<string, Map<string, Object>>} [mergeMap] Maps the combination of first and second arguments to a merged result.
58
79
  * @returns {Object} An object with properties from both first and second.
59
80
  */
60
- function deepMerge(first = {}, second = {}) {
81
+ function deepMerge(first, second, mergeMap = new Map()) {
61
82
 
62
- /*
63
- * If the second value is an array, just return it. We don't merge
64
- * arrays because order matters and we can't know the correct order.
65
- */
66
- if (Array.isArray(second)) {
67
- return second;
83
+ let secondMergeMap = mergeMap.get(first);
84
+
85
+ if (secondMergeMap) {
86
+ const result = secondMergeMap.get(second);
87
+
88
+ if (result) {
89
+
90
+ // If this combination of first and second arguments has been already visited, return the previously created result.
91
+ return result;
92
+ }
93
+ } else {
94
+ secondMergeMap = new Map();
95
+ mergeMap.set(first, secondMergeMap);
68
96
  }
69
97
 
70
98
  /*
@@ -78,27 +106,25 @@ function deepMerge(first = {}, second = {}) {
78
106
  ...second
79
107
  };
80
108
 
109
+ delete result.__proto__; // eslint-disable-line no-proto -- don't merge own property "__proto__"
110
+
111
+ // Store the pending result for this combination of first and second arguments.
112
+ secondMergeMap.set(second, result);
113
+
81
114
  for (const key of Object.keys(second)) {
82
115
 
83
116
  // avoid hairy edge case
84
- if (key === "__proto__") {
117
+ if (key === "__proto__" || !Object.prototype.propertyIsEnumerable.call(first, key)) {
85
118
  continue;
86
119
  }
87
120
 
88
121
  const firstValue = first[key];
89
122
  const secondValue = second[key];
90
123
 
91
- if (isNonNullObject(firstValue)) {
92
- result[key] = deepMerge(firstValue, secondValue);
93
- } else if (isUndefined(firstValue)) {
94
- if (isNonNullObject(secondValue)) {
95
- result[key] = deepMerge(
96
- Array.isArray(secondValue) ? [] : {},
97
- secondValue
98
- );
99
- } else if (!isUndefined(secondValue)) {
100
- result[key] = secondValue;
101
- }
124
+ if (isNonArrayObject(firstValue) && isNonArrayObject(secondValue)) {
125
+ result[key] = deepMerge(firstValue, secondValue, mergeMap);
126
+ } else if (isUndefined(secondValue)) {
127
+ result[key] = firstValue;
102
128
  }
103
129
  }
104
130
 
@@ -119,7 +145,7 @@ function normalizeRuleOptions(ruleOptions) {
119
145
  : [ruleOptions];
120
146
 
121
147
  finalOptions[0] = ruleSeverities.get(finalOptions[0]);
122
- return finalOptions;
148
+ return structuredClone(finalOptions);
123
149
  }
124
150
 
125
151
  //-----------------------------------------------------------------------------
@@ -179,9 +205,7 @@ class InvalidRuleSeverityError extends Error {
179
205
  * @throws {InvalidRuleSeverityError} If the value isn't a valid rule severity.
180
206
  */
181
207
  function assertIsRuleSeverity(ruleId, value) {
182
- const severity = typeof value === "string"
183
- ? ruleSeverities.get(value.toLowerCase())
184
- : ruleSeverities.get(value);
208
+ const severity = ruleSeverities.get(value);
185
209
 
186
210
  if (typeof severity === "undefined") {
187
211
  throw new InvalidRuleSeverityError(ruleId, value);
@@ -254,6 +278,26 @@ const booleanSchema = {
254
278
  validate: "boolean"
255
279
  };
256
280
 
281
+ const ALLOWED_SEVERITIES = new Set(["error", "warn", "off", 2, 1, 0]);
282
+
283
+ /** @type {ObjectPropertySchema} */
284
+ const disableDirectiveSeveritySchema = {
285
+ merge(first, second) {
286
+ const value = second === void 0 ? first : second;
287
+
288
+ if (typeof value === "boolean") {
289
+ return value ? "warn" : "off";
290
+ }
291
+
292
+ return normalizeSeverityToNumber(value);
293
+ },
294
+ validate(value) {
295
+ if (!(ALLOWED_SEVERITIES.has(value) || typeof value === "boolean")) {
296
+ throw new TypeError("Expected one of: \"error\", \"warn\", \"off\", 0, 1, 2, or a boolean.");
297
+ }
298
+ }
299
+ };
300
+
257
301
  /** @type {ObjectPropertySchema} */
258
302
  const deepObjectAssignSchema = {
259
303
  merge(first = {}, second = {}) {
@@ -380,48 +424,57 @@ const rulesSchema = {
380
424
  ...second
381
425
  };
382
426
 
383
- for (const ruleId of Object.keys(result)) {
384
-
385
- // avoid hairy edge case
386
- if (ruleId === "__proto__") {
387
-
388
- /* eslint-disable-next-line no-proto -- Though deprecated, may still be present */
389
- delete result.__proto__;
390
- continue;
391
- }
392
-
393
- result[ruleId] = normalizeRuleOptions(result[ruleId]);
394
427
 
395
- /*
396
- * If either rule config is missing, then the correct
397
- * config is already present and we just need to normalize
398
- * the severity.
399
- */
400
- if (!(ruleId in first) || !(ruleId in second)) {
401
- continue;
402
- }
403
-
404
- const firstRuleOptions = normalizeRuleOptions(first[ruleId]);
405
- const secondRuleOptions = normalizeRuleOptions(second[ruleId]);
428
+ for (const ruleId of Object.keys(result)) {
406
429
 
407
- /*
408
- * If the second rule config only has a severity (length of 1),
409
- * then use that severity and keep the rest of the options from
410
- * the first rule config.
411
- */
412
- if (secondRuleOptions.length === 1) {
413
- result[ruleId] = [secondRuleOptions[0], ...firstRuleOptions.slice(1)];
414
- continue;
430
+ try {
431
+
432
+ // avoid hairy edge case
433
+ if (ruleId === "__proto__") {
434
+
435
+ /* eslint-disable-next-line no-proto -- Though deprecated, may still be present */
436
+ delete result.__proto__;
437
+ continue;
438
+ }
439
+
440
+ result[ruleId] = normalizeRuleOptions(result[ruleId]);
441
+
442
+ /*
443
+ * If either rule config is missing, then the correct
444
+ * config is already present and we just need to normalize
445
+ * the severity.
446
+ */
447
+ if (!(ruleId in first) || !(ruleId in second)) {
448
+ continue;
449
+ }
450
+
451
+ const firstRuleOptions = normalizeRuleOptions(first[ruleId]);
452
+ const secondRuleOptions = normalizeRuleOptions(second[ruleId]);
453
+
454
+ /*
455
+ * If the second rule config only has a severity (length of 1),
456
+ * then use that severity and keep the rest of the options from
457
+ * the first rule config.
458
+ */
459
+ if (secondRuleOptions.length === 1) {
460
+ result[ruleId] = [secondRuleOptions[0], ...firstRuleOptions.slice(1)];
461
+ continue;
462
+ }
463
+
464
+ /*
465
+ * In any other situation, then the second rule config takes
466
+ * precedence. That means the value at `result[ruleId]` is
467
+ * already correct and no further work is necessary.
468
+ */
469
+ } catch (ex) {
470
+ throw new Error(`Key "${ruleId}": ${ex.message}`, { cause: ex });
415
471
  }
416
472
 
417
- /*
418
- * In any other situation, then the second rule config takes
419
- * precedence. That means the value at `result[ruleId]` is
420
- * already correct and no further work is necessary.
421
- */
422
473
  }
423
474
 
424
475
  return result;
476
+
477
+
425
478
  },
426
479
 
427
480
  validate(value) {
@@ -507,7 +560,7 @@ const eslintrcKeys = [
507
560
  // Full schema
508
561
  //-----------------------------------------------------------------------------
509
562
 
510
- exports.flatConfigSchema = {
563
+ const flatConfigSchema = {
511
564
 
512
565
  // eslintrc-style keys that should always error
513
566
  ...Object.fromEntries(eslintrcKeys.map(key => [key, createEslintrcErrorSchema(key)])),
@@ -517,7 +570,7 @@ exports.flatConfigSchema = {
517
570
  linterOptions: {
518
571
  schema: {
519
572
  noInlineConfig: booleanSchema,
520
- reportUnusedDisableDirectives: booleanSchema
573
+ reportUnusedDisableDirectives: disableDirectiveSeveritySchema
521
574
  }
522
575
  },
523
576
  languageOptions: {
@@ -533,3 +586,13 @@ exports.flatConfigSchema = {
533
586
  plugins: pluginsSchema,
534
587
  rules: rulesSchema
535
588
  };
589
+
590
+ //-----------------------------------------------------------------------------
591
+ // Exports
592
+ //-----------------------------------------------------------------------------
593
+
594
+ module.exports = {
595
+ flatConfigSchema,
596
+ assertIsRuleSeverity,
597
+ assertIsRuleOptions
598
+ };
@@ -9,7 +9,8 @@
9
9
  // Requirements
10
10
  //-----------------------------------------------------------------------------
11
11
 
12
- const ajv = require("../shared/ajv")();
12
+ const ajvImport = require("../shared/ajv");
13
+ const ajv = ajvImport();
13
14
  const {
14
15
  parseRuleId,
15
16
  getRuleFromConfig,
@@ -594,9 +594,9 @@ function createIgnoreResult(filePath, baseDir) {
594
594
  const isInNodeModules = baseDir && path.dirname(path.relative(baseDir, filePath)).split(path.sep).includes("node_modules");
595
595
 
596
596
  if (isInNodeModules) {
597
- message = "File ignored by default because it is located under the node_modules directory. Use ignore pattern \"!**/node_modules/\" to override.";
597
+ message = "File ignored by default because it is located under the node_modules directory. Use ignore pattern \"!**/node_modules/\" to disable file ignore settings or use \"--no-warn-ignored\" to suppress this warning.";
598
598
  } else {
599
- message = "File ignored because of a matching ignore pattern. Use \"--no-ignore\" to override.";
599
+ message = "File ignored because of a matching ignore pattern. Use \"--no-ignore\" to disable file ignore settings or use \"--no-warn-ignored\" to suppress this warning.";
600
600
  }
601
601
 
602
602
  return {
@@ -675,7 +675,7 @@ function processOptions({
675
675
  overrideConfig = null,
676
676
  overrideConfigFile = null,
677
677
  plugins = {},
678
- reportUnusedDisableDirectives = null, // ← should be null by default because if it's a string then it overrides the 'reportUnusedDisableDirectives' setting in config files. And we cannot use `overrideConfig.reportUnusedDisableDirectives` instead because we cannot configure the `error` severity with that.
678
+ warnIgnored = true,
679
679
  ...unknownOptions
680
680
  }) {
681
681
  const errors = [];
@@ -719,6 +719,9 @@ function processOptions({
719
719
  if (unknownOptionKeys.includes("rulePaths")) {
720
720
  errors.push("'rulePaths' has been removed. Please define your rules using plugins.");
721
721
  }
722
+ if (unknownOptionKeys.includes("reportUnusedDisableDirectives")) {
723
+ errors.push("'reportUnusedDisableDirectives' has been removed. Please use the 'overrideConfig.linterOptions.reportUnusedDisableDirectives' option instead.");
724
+ }
722
725
  }
723
726
  if (typeof allowInlineConfig !== "boolean") {
724
727
  errors.push("'allowInlineConfig' must be a boolean.");
@@ -773,13 +776,8 @@ function processOptions({
773
776
  if (Array.isArray(plugins)) {
774
777
  errors.push("'plugins' doesn't add plugins to configuration to load. Please use the 'overrideConfig.plugins' option instead.");
775
778
  }
776
- if (
777
- reportUnusedDisableDirectives !== "error" &&
778
- reportUnusedDisableDirectives !== "warn" &&
779
- reportUnusedDisableDirectives !== "off" &&
780
- reportUnusedDisableDirectives !== null
781
- ) {
782
- errors.push("'reportUnusedDisableDirectives' must be any of \"error\", \"warn\", \"off\", and null.");
779
+ if (typeof warnIgnored !== "boolean") {
780
+ errors.push("'warnIgnored' must be a boolean.");
783
781
  }
784
782
  if (errors.length > 0) {
785
783
  throw new ESLintInvalidOptionsError(errors);
@@ -802,7 +800,7 @@ function processOptions({
802
800
  globInputPaths,
803
801
  ignore,
804
802
  ignorePatterns,
805
- reportUnusedDisableDirectives
803
+ warnIgnored
806
804
  };
807
805
  }
808
806
 
@@ -682,6 +682,13 @@ class ESLint {
682
682
  }
683
683
  }
684
684
 
685
+ /**
686
+ * The type of configuration used by this class.
687
+ * @type {string}
688
+ * @static
689
+ */
690
+ ESLint.configType = "eslintrc";
691
+
685
692
  //------------------------------------------------------------------------------
686
693
  // Public Interface
687
694
  //------------------------------------------------------------------------------
@@ -11,6 +11,7 @@
11
11
 
12
12
  // Note: Node.js 12 does not support fs/promises.
13
13
  const fs = require("fs").promises;
14
+ const { existsSync } = require("fs");
14
15
  const path = require("path");
15
16
  const findUp = require("find-up");
16
17
  const { version } = require("../../package.json");
@@ -83,14 +84,18 @@ const LintResultCache = require("../cli-engine/lint-result-cache");
83
84
  * doesn't do any config file lookup when `true`; considered to be a config filename
84
85
  * when a string.
85
86
  * @property {Record<string,Plugin>} [plugins] An array of plugin implementations.
86
- * @property {"error" | "warn" | "off"} [reportUnusedDisableDirectives] the severity to report unused eslint-disable directives.
87
+ * @property {boolean} warnIgnored Show warnings when the file list includes ignored files
87
88
  */
88
89
 
89
90
  //------------------------------------------------------------------------------
90
91
  // Helpers
91
92
  //------------------------------------------------------------------------------
92
93
 
93
- const FLAT_CONFIG_FILENAME = "eslint.config.js";
94
+ const FLAT_CONFIG_FILENAMES = [
95
+ "eslint.config.js",
96
+ "eslint.config.mjs",
97
+ "eslint.config.cjs"
98
+ ];
94
99
  const debug = require("debug")("eslint:flat-eslint");
95
100
  const removedFormatters = new Set(["table", "codeframe"]);
96
101
  const privateMembers = new WeakMap();
@@ -247,7 +252,7 @@ function compareResultsByFilePath(a, b) {
247
252
  */
248
253
  function findFlatConfigFile(cwd) {
249
254
  return findUp(
250
- FLAT_CONFIG_FILENAME,
255
+ FLAT_CONFIG_FILENAMES,
251
256
  { cwd }
252
257
  );
253
258
  }
@@ -447,7 +452,6 @@ async function calculateConfigArray(eslint, {
447
452
  * @param {FlatConfigArray} config.configs The config.
448
453
  * @param {boolean} config.fix If `true` then it does fix.
449
454
  * @param {boolean} config.allowInlineConfig If `true` then it uses directive comments.
450
- * @param {boolean} config.reportUnusedDisableDirectives If `true` then it reports unused `eslint-disable` comments.
451
455
  * @param {Linter} config.linter The linter instance to verify.
452
456
  * @returns {LintResult} The result of linting.
453
457
  * @private
@@ -459,7 +463,6 @@ function verifyText({
459
463
  configs,
460
464
  fix,
461
465
  allowInlineConfig,
462
- reportUnusedDisableDirectives,
463
466
  linter
464
467
  }) {
465
468
  const filePath = providedFilePath || "<text>";
@@ -479,7 +482,6 @@ function verifyText({
479
482
  allowInlineConfig,
480
483
  filename: filePathToVerify,
481
484
  fix,
482
- reportUnusedDisableDirectives,
483
485
 
484
486
  /**
485
487
  * Check if the linter should adopt a given code block or not.
@@ -747,9 +749,9 @@ class FlatESLint {
747
749
  cwd,
748
750
  fix,
749
751
  fixTypes,
750
- reportUnusedDisableDirectives,
751
752
  globInputPaths,
752
- errorOnUnmatchedPattern
753
+ errorOnUnmatchedPattern,
754
+ warnIgnored
753
755
  } = eslintOptions;
754
756
  const startTime = Date.now();
755
757
  const fixTypesSet = fixTypes ? new Set(fixTypes) : null;
@@ -764,7 +766,7 @@ class FlatESLint {
764
766
  const errorCode = error && error.code;
765
767
 
766
768
  // Ignore errors when no such file exists or file system is read only (and cache file does not exist)
767
- if (errorCode !== "ENOENT" && !(errorCode === "EROFS" && !(await fs.exists(cacheFilePath)))) {
769
+ if (errorCode !== "ENOENT" && !(errorCode === "EROFS" && !existsSync(cacheFilePath))) {
768
770
  throw error;
769
771
  }
770
772
  }
@@ -795,7 +797,11 @@ class FlatESLint {
795
797
  * pattern, then notify the user.
796
798
  */
797
799
  if (ignored) {
798
- return createIgnoreResult(filePath, cwd);
800
+ if (warnIgnored) {
801
+ return createIgnoreResult(filePath, cwd);
802
+ }
803
+
804
+ return void 0;
799
805
  }
800
806
 
801
807
  const config = configs.getConfig(filePath);
@@ -852,7 +858,6 @@ class FlatESLint {
852
858
  cwd,
853
859
  fix: fixer,
854
860
  allowInlineConfig,
855
- reportUnusedDisableDirectives,
856
861
  linter
857
862
  });
858
863
 
@@ -908,7 +913,7 @@ class FlatESLint {
908
913
 
909
914
  const {
910
915
  filePath,
911
- warnIgnored = false,
916
+ warnIgnored,
912
917
  ...unknownOptions
913
918
  } = options || {};
914
919
 
@@ -922,7 +927,7 @@ class FlatESLint {
922
927
  throw new Error("'options.filePath' must be a non-empty string or undefined");
923
928
  }
924
929
 
925
- if (typeof warnIgnored !== "boolean") {
930
+ if (typeof warnIgnored !== "boolean" && typeof warnIgnored !== "undefined") {
926
931
  throw new Error("'options.warnIgnored' must be a boolean or undefined");
927
932
  }
928
933
 
@@ -937,7 +942,7 @@ class FlatESLint {
937
942
  allowInlineConfig,
938
943
  cwd,
939
944
  fix,
940
- reportUnusedDisableDirectives
945
+ warnIgnored: constructorWarnIgnored
941
946
  } = eslintOptions;
942
947
  const results = [];
943
948
  const startTime = Date.now();
@@ -945,7 +950,9 @@ class FlatESLint {
945
950
 
946
951
  // Clear the last used config arrays.
947
952
  if (resolvedFilename && await this.isPathIgnored(resolvedFilename)) {
948
- if (warnIgnored) {
953
+ const shouldWarnIgnored = typeof warnIgnored === "boolean" ? warnIgnored : constructorWarnIgnored;
954
+
955
+ if (shouldWarnIgnored) {
949
956
  results.push(createIgnoreResult(resolvedFilename, cwd));
950
957
  }
951
958
  } else {
@@ -958,7 +965,6 @@ class FlatESLint {
958
965
  cwd,
959
966
  fix,
960
967
  allowInlineConfig,
961
- reportUnusedDisableDirectives,
962
968
  linter
963
969
  }));
964
970
  }
@@ -1110,11 +1116,20 @@ class FlatESLint {
1110
1116
  }
1111
1117
  }
1112
1118
 
1119
+ /**
1120
+ * The type of configuration used by this class.
1121
+ * @type {string}
1122
+ * @static
1123
+ */
1124
+ FlatESLint.configType = "flat";
1125
+
1113
1126
  /**
1114
1127
  * Returns whether flat config should be used.
1128
+ * @param {Object} [options] The options for this function.
1129
+ * @param {string} [options.cwd] The current working directory.
1115
1130
  * @returns {Promise<boolean>} Whether flat config should be used.
1116
1131
  */
1117
- async function shouldUseFlatConfig() {
1132
+ async function shouldUseFlatConfig({ cwd = process.cwd() } = {}) {
1118
1133
  switch (process.env.ESLINT_USE_FLAT_CONFIG) {
1119
1134
  case "true":
1120
1135
  return true;
@@ -1126,7 +1141,7 @@ async function shouldUseFlatConfig() {
1126
1141
  * If neither explicitly enabled nor disabled, then use the presence
1127
1142
  * of a flat config file to determine enablement.
1128
1143
  */
1129
- return !!(await findFlatConfigFile(process.cwd()));
1144
+ return !!(await findFlatConfigFile(cwd));
1130
1145
  }
1131
1146
  }
1132
1147