eslint 9.26.0 → 9.28.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 (41) hide show
  1. package/README.md +7 -2
  2. package/bin/eslint.js +7 -11
  3. package/conf/rule-type-list.json +2 -1
  4. package/lib/cli-engine/cli-engine.js +7 -7
  5. package/lib/cli.js +19 -16
  6. package/lib/config/config-loader.js +42 -39
  7. package/lib/config/config.js +362 -16
  8. package/lib/eslint/eslint-helpers.js +3 -1
  9. package/lib/eslint/eslint.js +31 -13
  10. package/lib/eslint/legacy-eslint.js +6 -6
  11. package/lib/languages/js/source-code/source-code.js +40 -6
  12. package/lib/linter/apply-disable-directives.js +1 -1
  13. package/lib/linter/file-context.js +11 -0
  14. package/lib/linter/linter.js +102 -140
  15. package/lib/linter/report-translator.js +2 -1
  16. package/lib/linter/{node-event-generator.js → source-code-traverser.js} +143 -87
  17. package/lib/options.js +7 -0
  18. package/lib/rule-tester/rule-tester.js +3 -3
  19. package/lib/rules/func-style.js +57 -7
  20. package/lib/rules/index.js +1 -0
  21. package/lib/rules/max-params.js +32 -7
  22. package/lib/rules/no-array-constructor.js +51 -1
  23. package/lib/rules/no-implicit-globals.js +31 -15
  24. package/lib/rules/no-magic-numbers.js +98 -5
  25. package/lib/rules/no-shadow.js +262 -6
  26. package/lib/rules/no-unassigned-vars.js +80 -0
  27. package/lib/rules/no-use-before-define.js +97 -1
  28. package/lib/rules/no-useless-escape.js +24 -2
  29. package/lib/rules/prefer-arrow-callback.js +9 -0
  30. package/lib/rules/prefer-named-capture-group.js +7 -1
  31. package/lib/services/processor-service.js +1 -1
  32. package/lib/services/suppressions-service.js +5 -3
  33. package/lib/services/warning-service.js +85 -0
  34. package/lib/shared/flags.js +1 -0
  35. package/lib/types/index.d.ts +132 -9
  36. package/lib/types/rules.d.ts +66 -3
  37. package/package.json +11 -11
  38. package/lib/config/flat-config-helpers.js +0 -128
  39. package/lib/config/rule-validator.js +0 -199
  40. package/lib/mcp/mcp-server.js +0 -66
  41. package/lib/shared/types.js +0 -229
@@ -10,16 +10,31 @@
10
10
  //-----------------------------------------------------------------------------
11
11
 
12
12
  const { deepMergeArrays } = require("../shared/deep-merge-arrays");
13
- const { getRuleFromConfig } = require("./flat-config-helpers");
14
13
  const { flatConfigSchema, hasMethod } = require("./flat-config-schema");
15
- const { RuleValidator } = require("./rule-validator");
16
14
  const { ObjectSchema } = require("@eslint/config-array");
15
+ const ajvImport = require("../shared/ajv");
16
+ const ajv = ajvImport();
17
+ const ruleReplacements = require("../../conf/replacements.json");
17
18
 
18
19
  //-----------------------------------------------------------------------------
19
- // Helpers
20
+ // Typedefs
20
21
  //-----------------------------------------------------------------------------
21
22
 
22
- const ruleValidator = new RuleValidator();
23
+ /**
24
+ * @import { RuleDefinition } from "@eslint/core";
25
+ * @import { Linter } from "eslint";
26
+ */
27
+
28
+ //-----------------------------------------------------------------------------
29
+ // Private Members
30
+ //------------------------------------------------------------------------------
31
+
32
+ // JSON schema that disallows passing any options
33
+ const noOptionsSchema = Object.freeze({
34
+ type: "array",
35
+ minItems: 0,
36
+ maxItems: 0,
37
+ });
23
38
 
24
39
  const severities = new Map([
25
40
  [0, 0],
@@ -30,6 +45,174 @@ const severities = new Map([
30
45
  ["error", 2],
31
46
  ]);
32
47
 
48
+ /**
49
+ * A collection of compiled validators for rules that have already
50
+ * been validated.
51
+ * @type {WeakMap}
52
+ */
53
+ const validators = new WeakMap();
54
+
55
+ //-----------------------------------------------------------------------------
56
+ // Helpers
57
+ //-----------------------------------------------------------------------------
58
+
59
+ /**
60
+ * Throws a helpful error when a rule cannot be found.
61
+ * @param {Object} ruleId The rule identifier.
62
+ * @param {string} ruleId.pluginName The ID of the rule to find.
63
+ * @param {string} ruleId.ruleName The ID of the rule to find.
64
+ * @param {Object} config The config to search in.
65
+ * @throws {TypeError} For missing plugin or rule.
66
+ * @returns {void}
67
+ */
68
+ function throwRuleNotFoundError({ pluginName, ruleName }, config) {
69
+ const ruleId = pluginName === "@" ? ruleName : `${pluginName}/${ruleName}`;
70
+
71
+ const errorMessageHeader = `Key "rules": Key "${ruleId}"`;
72
+
73
+ let errorMessage = `${errorMessageHeader}: Could not find plugin "${pluginName}" in configuration.`;
74
+
75
+ const missingPluginErrorMessage = errorMessage;
76
+
77
+ // if the plugin exists then we need to check if the rule exists
78
+ if (config.plugins && config.plugins[pluginName]) {
79
+ const replacementRuleName = ruleReplacements.rules[ruleName];
80
+
81
+ if (pluginName === "@" && replacementRuleName) {
82
+ errorMessage = `${errorMessageHeader}: Rule "${ruleName}" was removed and replaced by "${replacementRuleName}".`;
83
+ } else {
84
+ errorMessage = `${errorMessageHeader}: Could not find "${ruleName}" in plugin "${pluginName}".`;
85
+
86
+ // otherwise, let's see if we can find the rule name elsewhere
87
+ for (const [otherPluginName, otherPlugin] of Object.entries(
88
+ config.plugins,
89
+ )) {
90
+ if (otherPlugin.rules && otherPlugin.rules[ruleName]) {
91
+ errorMessage += ` Did you mean "${otherPluginName}/${ruleName}"?`;
92
+ break;
93
+ }
94
+ }
95
+ }
96
+
97
+ // falls through to throw error
98
+ }
99
+
100
+ const error = new TypeError(errorMessage);
101
+
102
+ if (errorMessage === missingPluginErrorMessage) {
103
+ error.messageTemplate = "config-plugin-missing";
104
+ error.messageData = { pluginName, ruleId };
105
+ }
106
+
107
+ throw error;
108
+ }
109
+
110
+ /**
111
+ * The error type when a rule has an invalid `meta.schema`.
112
+ */
113
+ class InvalidRuleOptionsSchemaError extends Error {
114
+ /**
115
+ * Creates a new instance.
116
+ * @param {string} ruleId Id of the rule that has an invalid `meta.schema`.
117
+ * @param {Error} processingError Error caught while processing the `meta.schema`.
118
+ */
119
+ constructor(ruleId, processingError) {
120
+ super(
121
+ `Error while processing options validation schema of rule '${ruleId}': ${processingError.message}`,
122
+ { cause: processingError },
123
+ );
124
+ this.code = "ESLINT_INVALID_RULE_OPTIONS_SCHEMA";
125
+ }
126
+ }
127
+
128
+ /**
129
+ * Parses a ruleId into its plugin and rule parts.
130
+ * @param {string} ruleId The rule ID to parse.
131
+ * @returns {{pluginName:string,ruleName:string}} The plugin and rule
132
+ * parts of the ruleId;
133
+ */
134
+ function parseRuleId(ruleId) {
135
+ let pluginName, ruleName;
136
+
137
+ // distinguish between core rules and plugin rules
138
+ if (ruleId.includes("/")) {
139
+ // mimic scoped npm packages
140
+ if (ruleId.startsWith("@")) {
141
+ pluginName = ruleId.slice(0, ruleId.lastIndexOf("/"));
142
+ } else {
143
+ pluginName = ruleId.slice(0, ruleId.indexOf("/"));
144
+ }
145
+
146
+ ruleName = ruleId.slice(pluginName.length + 1);
147
+ } else {
148
+ pluginName = "@";
149
+ ruleName = ruleId;
150
+ }
151
+
152
+ return {
153
+ pluginName,
154
+ ruleName,
155
+ };
156
+ }
157
+
158
+ /**
159
+ * Retrieves a rule instance from a given config based on the ruleId.
160
+ * @param {string} ruleId The rule ID to look for.
161
+ * @param {Linter.Config} config The config to search.
162
+ * @returns {RuleDefinition|undefined} The rule if found
163
+ * or undefined if not.
164
+ */
165
+ function getRuleFromConfig(ruleId, config) {
166
+ const { pluginName, ruleName } = parseRuleId(ruleId);
167
+
168
+ return config.plugins?.[pluginName]?.rules?.[ruleName];
169
+ }
170
+
171
+ /**
172
+ * Gets a complete options schema for a rule.
173
+ * @param {RuleDefinition} rule A rule object
174
+ * @throws {TypeError} If `meta.schema` is specified but is not an array, object or `false`.
175
+ * @returns {Object|null} JSON Schema for the rule's options. `null` if `meta.schema` is `false`.
176
+ */
177
+ function getRuleOptionsSchema(rule) {
178
+ if (!rule.meta) {
179
+ return { ...noOptionsSchema }; // default if `meta.schema` is not specified
180
+ }
181
+
182
+ const schema = rule.meta.schema;
183
+
184
+ if (typeof schema === "undefined") {
185
+ return { ...noOptionsSchema }; // default if `meta.schema` is not specified
186
+ }
187
+
188
+ // `schema:false` is an allowed explicit opt-out of options validation for the rule
189
+ if (schema === false) {
190
+ return null;
191
+ }
192
+
193
+ if (typeof schema !== "object" || schema === null) {
194
+ throw new TypeError("Rule's `meta.schema` must be an array or object");
195
+ }
196
+
197
+ // ESLint-specific array form needs to be converted into a valid JSON Schema definition
198
+ if (Array.isArray(schema)) {
199
+ if (schema.length) {
200
+ return {
201
+ type: "array",
202
+ items: schema,
203
+ minItems: 0,
204
+ maxItems: schema.length,
205
+ };
206
+ }
207
+
208
+ // `schema:[]` is an explicit way to specify that the rule does not accept any options
209
+ return { ...noOptionsSchema };
210
+ }
211
+
212
+ // `schema:<object>` is assumed to be a valid JSON Schema definition
213
+ return schema;
214
+ }
215
+
33
216
  /**
34
217
  * Splits a plugin identifier in the form a/b/c into two parts: a/b and c.
35
218
  * @param {string} identifier The identifier to parse.
@@ -82,6 +265,27 @@ function getObjectId(object) {
82
265
  return name;
83
266
  }
84
267
 
268
+ /**
269
+ * Asserts that a value is not a function.
270
+ * @param {any} value The value to check.
271
+ * @param {string} key The key of the value in the object.
272
+ * @param {string} objectKey The key of the object being checked.
273
+ * @returns {void}
274
+ * @throws {TypeError} If the value is a function.
275
+ */
276
+ function assertNotFunction(value, key, objectKey) {
277
+ if (typeof value === "function") {
278
+ const error = new TypeError(
279
+ `Cannot serialize key "${key}" in "${objectKey}": Function values are not supported.`,
280
+ );
281
+
282
+ error.messageTemplate = "config-serialize-function";
283
+ error.messageData = { key, objectKey };
284
+
285
+ throw error;
286
+ }
287
+ }
288
+
85
289
  /**
86
290
  * Converts a languageOptions object to a JSON representation.
87
291
  * @param {Record<string, any>} languageOptions The options to create a JSON
@@ -91,6 +295,14 @@ function getObjectId(object) {
91
295
  * @throws {TypeError} If a function is found in the languageOptions.
92
296
  */
93
297
  function languageOptionsToJSON(languageOptions, objectKey = "languageOptions") {
298
+ if (typeof languageOptions.toJSON === "function") {
299
+ const result = languageOptions.toJSON();
300
+
301
+ assertNotFunction(result, "toJSON", objectKey);
302
+
303
+ return result;
304
+ }
305
+
94
306
  const result = {};
95
307
 
96
308
  for (const [key, value] of Object.entries(languageOptions)) {
@@ -98,7 +310,10 @@ function languageOptionsToJSON(languageOptions, objectKey = "languageOptions") {
98
310
  if (typeof value === "object") {
99
311
  const name = getObjectId(value);
100
312
 
101
- if (name && hasMethod(value)) {
313
+ if (typeof value.toJSON === "function") {
314
+ result[key] = value.toJSON();
315
+ assertNotFunction(result[key], key, objectKey);
316
+ } else if (name && hasMethod(value)) {
102
317
  result[key] = name;
103
318
  } else {
104
319
  result[key] = languageOptionsToJSON(value, key);
@@ -106,16 +321,7 @@ function languageOptionsToJSON(languageOptions, objectKey = "languageOptions") {
106
321
  continue;
107
322
  }
108
323
 
109
- if (typeof value === "function") {
110
- const error = new TypeError(
111
- `Cannot serialize key "${key}" in ${objectKey}: Function values are not supported.`,
112
- );
113
-
114
- error.messageTemplate = "config-serialize-function";
115
- error.messageData = { key, objectKey };
116
-
117
- throw error;
118
- }
324
+ assertNotFunction(value, key, objectKey);
119
325
  }
120
326
 
121
327
  result[key] = value;
@@ -124,6 +330,29 @@ function languageOptionsToJSON(languageOptions, objectKey = "languageOptions") {
124
330
  return result;
125
331
  }
126
332
 
333
+ /**
334
+ * Gets or creates a validator for a rule.
335
+ * @param {Object} rule The rule to get a validator for.
336
+ * @param {string} ruleId The ID of the rule (for error reporting).
337
+ * @returns {Function|null} A validation function or null if no validation is needed.
338
+ * @throws {InvalidRuleOptionsSchemaError} If a rule's `meta.schema` is invalid.
339
+ */
340
+ function getOrCreateValidator(rule, ruleId) {
341
+ if (!validators.has(rule)) {
342
+ try {
343
+ const schema = getRuleOptionsSchema(rule);
344
+
345
+ if (schema) {
346
+ validators.set(rule, ajv.compile(schema));
347
+ }
348
+ } catch (err) {
349
+ throw new InvalidRuleOptionsSchemaError(ruleId, err);
350
+ }
351
+ }
352
+
353
+ return validators.get(rule);
354
+ }
355
+
127
356
  //-----------------------------------------------------------------------------
128
357
  // Exports
129
358
  //-----------------------------------------------------------------------------
@@ -252,7 +481,7 @@ class Config {
252
481
  // Process the rules
253
482
  if (this.rules) {
254
483
  this.#normalizeRulesConfig();
255
- ruleValidator.validate(this);
484
+ this.validateRulesConfig(this.rules);
256
485
  }
257
486
  }
258
487
 
@@ -291,6 +520,15 @@ class Config {
291
520
  };
292
521
  }
293
522
 
523
+ /**
524
+ * Gets a rule configuration by its ID.
525
+ * @param {string} ruleId The ID of the rule to get.
526
+ * @returns {RuleDefinition|undefined} The rule definition from the plugin, or `undefined` if the rule is not found.
527
+ */
528
+ getRuleDefinition(ruleId) {
529
+ return getRuleFromConfig(ruleId, this);
530
+ }
531
+
294
532
  /**
295
533
  * Normalizes the rules configuration. Ensures that each rule config is
296
534
  * an array and that the severity is a number. Applies meta.defaultOptions.
@@ -323,6 +561,114 @@ class Config {
323
561
  this.rules[ruleId] = ruleConfig;
324
562
  }
325
563
  }
564
+
565
+ /**
566
+ * Validates all of the rule configurations in the given rules config
567
+ * against the plugins in this instance. This is used primarily to
568
+ * validate inline configuration rules while inting.
569
+ * @param {Object} rulesConfig The rules config to validate.
570
+ * @returns {void}
571
+ * @throws {Error} If a rule's configuration does not match its schema.
572
+ * @throws {TypeError} If the rulesConfig is not provided or is invalid.
573
+ * @throws {InvalidRuleOptionsSchemaError} If a rule's `meta.schema` is invalid.
574
+ * @throws {TypeError} If a rule is not found in the plugins.
575
+ */
576
+ validateRulesConfig(rulesConfig) {
577
+ if (!rulesConfig) {
578
+ throw new TypeError("Config is required for validation.");
579
+ }
580
+
581
+ for (const [ruleId, ruleOptions] of Object.entries(rulesConfig)) {
582
+ // check for edge case
583
+ if (ruleId === "__proto__") {
584
+ continue;
585
+ }
586
+
587
+ /*
588
+ * If a rule is disabled, we don't do any validation. This allows
589
+ * users to safely set any value to 0 or "off" without worrying
590
+ * that it will cause a validation error.
591
+ *
592
+ * Note: ruleOptions is always an array at this point because
593
+ * this validation occurs after FlatConfigArray has merged and
594
+ * normalized values.
595
+ */
596
+ if (ruleOptions[0] === 0) {
597
+ continue;
598
+ }
599
+
600
+ const rule = getRuleFromConfig(ruleId, this);
601
+
602
+ if (!rule) {
603
+ throwRuleNotFoundError(parseRuleId(ruleId), this);
604
+ }
605
+
606
+ const validateRule = getOrCreateValidator(rule, ruleId);
607
+
608
+ if (validateRule) {
609
+ validateRule(ruleOptions.slice(1));
610
+
611
+ if (validateRule.errors) {
612
+ throw new Error(
613
+ `Key "rules": Key "${ruleId}":\n${validateRule.errors
614
+ .map(error => {
615
+ if (
616
+ error.keyword === "additionalProperties" &&
617
+ error.schema === false &&
618
+ typeof error.parentSchema?.properties ===
619
+ "object" &&
620
+ typeof error.params?.additionalProperty ===
621
+ "string"
622
+ ) {
623
+ const expectedProperties = Object.keys(
624
+ error.parentSchema.properties,
625
+ ).map(property => `"${property}"`);
626
+
627
+ return `\tValue ${JSON.stringify(error.data)} ${error.message}.\n\t\tUnexpected property "${error.params.additionalProperty}". Expected properties: ${expectedProperties.join(", ")}.\n`;
628
+ }
629
+
630
+ return `\tValue ${JSON.stringify(error.data)} ${error.message}.\n`;
631
+ })
632
+ .join("")}`,
633
+ );
634
+ }
635
+ }
636
+ }
637
+ }
638
+
639
+ /**
640
+ * Gets a complete options schema for a rule.
641
+ * @param {RuleDefinition} ruleDefinition A rule definition object.
642
+ * @throws {TypeError} If `meta.schema` is specified but is not an array, object or `false`.
643
+ * @returns {Object|null} JSON Schema for the rule's options. `null` if `meta.schema` is `false`.
644
+ */
645
+ static getRuleOptionsSchema(ruleDefinition) {
646
+ return getRuleOptionsSchema(ruleDefinition);
647
+ }
648
+
649
+ /**
650
+ * Normalizes the severity value of a rule's configuration to a number
651
+ * @param {(number|string|[number, ...*]|[string, ...*])} ruleConfig A rule's configuration value, generally
652
+ * received from the user. A valid config value is either 0, 1, 2, the string "off" (treated the same as 0),
653
+ * the string "warn" (treated the same as 1), the string "error" (treated the same as 2), or an array
654
+ * whose first element is one of the above values. Strings are matched case-insensitively.
655
+ * @returns {(0|1|2)} The numeric severity value if the config value was valid, otherwise 0.
656
+ */
657
+ static getRuleNumericSeverity(ruleConfig) {
658
+ const severityValue = Array.isArray(ruleConfig)
659
+ ? ruleConfig[0]
660
+ : ruleConfig;
661
+
662
+ if (severities.has(severityValue)) {
663
+ return severities.get(severityValue);
664
+ }
665
+
666
+ if (typeof severityValue === "string") {
667
+ return severities.get(severityValue.toLowerCase()) ?? 0;
668
+ }
669
+
670
+ return 0;
671
+ }
326
672
  }
327
673
 
328
674
  module.exports = { Config };
@@ -30,10 +30,12 @@ const MINIMATCH_OPTIONS = { dot: true };
30
30
 
31
31
  /**
32
32
  * @import { ESLintOptions } from "./eslint.js";
33
- * @import { LintMessage, LintResult } from "../shared/types.js";
34
33
  * @import { ConfigLoader, LegacyConfigLoader } from "../config/config-loader.js";
35
34
  */
36
35
 
36
+ /** @typedef {import("../types").Linter.LintMessage} LintMessage */
37
+ /** @typedef {import("../types").ESLint.LintResult} LintResult */
38
+
37
39
  /**
38
40
  * @typedef {Object} GlobSearch
39
41
  * @property {Array<string>} patterns The normalized patterns to use for a search.
@@ -14,7 +14,6 @@ const { existsSync } = require("node:fs");
14
14
  const path = require("node:path");
15
15
  const { version } = require("../../package.json");
16
16
  const { Linter } = require("../linter");
17
- const { getRuleFromConfig } = require("../config/flat-config-helpers");
18
17
  const { defaultConfig } = require("../config/default-config");
19
18
  const {
20
19
  Legacy: {
@@ -41,6 +40,7 @@ const { pathToFileURL } = require("node:url");
41
40
  const LintResultCache = require("../cli-engine/lint-result-cache");
42
41
  const { Retrier } = require("@humanwhocodes/retry");
43
42
  const { ConfigLoader, LegacyConfigLoader } = require("../config/config-loader");
43
+ const { WarningService } = require("../services/warning-service");
44
44
 
45
45
  /*
46
46
  * This is necessary to allow overwriting writeFile for testing purposes.
@@ -57,17 +57,21 @@ const { ConfigLoader, LegacyConfigLoader } = require("../config/config-loader");
57
57
  * @import { CLIEngineLintReport } from "./legacy-eslint.js";
58
58
  * @import { FlatConfigArray } from "../config/flat-config-array.js";
59
59
  * @import { RuleDefinition } from "@eslint/core";
60
- * @import { ConfigData, DeprecatedRuleInfo, LintMessage, LintResult, ResultsMeta } from "../shared/types.js";
61
60
  */
62
61
 
63
62
  /** @typedef {ReturnType<ConfigArray.extractConfig>} ExtractedConfig */
63
+ /** @typedef {import("../types").Linter.Config} Config */
64
+ /** @typedef {import("../types").ESLint.DeprecatedRuleUse} DeprecatedRuleInfo */
65
+ /** @typedef {import("../types").Linter.LintMessage} LintMessage */
66
+ /** @typedef {import("../types").ESLint.LintResult} LintResult */
64
67
  /** @typedef {import("../types").ESLint.Plugin} Plugin */
68
+ /** @typedef {import("../types").ESLint.ResultsMeta} ResultsMeta */
65
69
 
66
70
  /**
67
71
  * The options with which to configure the ESLint instance.
68
72
  * @typedef {Object} ESLintOptions
69
73
  * @property {boolean} [allowInlineConfig] Enable or disable inline configuration comments.
70
- * @property {ConfigData|Array<ConfigData>} [baseConfig] Base config, extended by all configs used with this instance
74
+ * @property {Config|Array<Config>} [baseConfig] Base config, extended by all configs used with this instance
71
75
  * @property {boolean} [cache] Enable result caching.
72
76
  * @property {string} [cacheLocation] The cache file to use instead of .eslintcache.
73
77
  * @property {"metadata" | "content"} [cacheStrategy] The strategy used to detect changed files.
@@ -79,7 +83,7 @@ const { ConfigLoader, LegacyConfigLoader } = require("../config/config-loader");
79
83
  * @property {boolean} [globInputPaths] Set to false to skip glob resolution of input file paths to lint (default: true). If false, each input file paths is assumed to be a non-glob path to an existing file.
80
84
  * @property {boolean} [ignore] False disables all ignore patterns except for the default ones.
81
85
  * @property {string[]} [ignorePatterns] Ignore file patterns to use in addition to config ignores. These patterns are relative to `cwd`.
82
- * @property {ConfigData|Array<ConfigData>} [overrideConfig] Override config, overrides all configs used with this instance
86
+ * @property {Config|Array<Config>} [overrideConfig] Override config, overrides all configs used with this instance
83
87
  * @property {boolean|string} [overrideConfigFile] Searches for default config file when falsy;
84
88
  * doesn't do any config file lookup when `true`; considered to be a config filename
85
89
  * when a string.
@@ -159,7 +163,7 @@ function getOrFindUsedDeprecatedRules(eslint, maybeFilePath) {
159
163
  if (getRuleSeverity(ruleConf) === 0) {
160
164
  continue;
161
165
  }
162
- const rule = getRuleFromConfig(ruleId, config);
166
+ const rule = config.getRuleDefinition(ruleId);
163
167
  const meta = rule && rule.meta;
164
168
 
165
169
  if (meta && meta.deprecated) {
@@ -353,7 +357,7 @@ function shouldMessageBeFixed(message, config, fixTypes) {
353
357
  return fixTypes.has("directive");
354
358
  }
355
359
 
356
- const rule = message.ruleId && getRuleFromConfig(message.ruleId, config);
360
+ const rule = message.ruleId && config.getRuleDefinition(message.ruleId);
357
361
 
358
362
  return Boolean(rule && rule.meta && fixTypes.has(rule.meta.type));
359
363
  }
@@ -387,6 +391,20 @@ function getFixerForFixTypes(fix, fixTypesSet, config) {
387
391
  originalFix(message);
388
392
  }
389
393
 
394
+ /**
395
+ * Retrieves flags from the environment variable ESLINT_FLAGS.
396
+ * @param {string[]} flags The flags defined via the API.
397
+ * @returns {string[]} The merged flags to use.
398
+ */
399
+ function mergeEnvironmentFlags(flags) {
400
+ if (!process.env.ESLINT_FLAGS) {
401
+ return flags;
402
+ }
403
+
404
+ const envFlags = process.env.ESLINT_FLAGS.trim().split(/\s*,\s*/gu);
405
+ return Array.from(new Set([...envFlags, ...flags]));
406
+ }
407
+
390
408
  //-----------------------------------------------------------------------------
391
409
  // Main API
392
410
  //-----------------------------------------------------------------------------
@@ -414,10 +432,12 @@ class ESLint {
414
432
  constructor(options = {}) {
415
433
  const defaultConfigs = [];
416
434
  const processedOptions = processOptions(options);
435
+ const warningService = new WarningService();
417
436
  const linter = new Linter({
418
437
  cwd: processedOptions.cwd,
419
438
  configType: "flat",
420
- flags: processedOptions.flags,
439
+ flags: mergeEnvironmentFlags(processedOptions.flags),
440
+ warningService,
421
441
  });
422
442
 
423
443
  const cacheFilePath = getCacheFile(
@@ -440,6 +460,7 @@ class ESLint {
440
460
  hasUnstableNativeNodeJsTSConfigFlag: linter.hasFlag(
441
461
  "unstable_native_nodejs_ts_config",
442
462
  ),
463
+ warningService,
443
464
  };
444
465
 
445
466
  this.#configLoader = linter.hasFlag("unstable_config_lookup_from_file")
@@ -479,10 +500,7 @@ class ESLint {
479
500
 
480
501
  // Check for the .eslintignore file, and warn if it's present.
481
502
  if (existsSync(path.resolve(processedOptions.cwd, ".eslintignore"))) {
482
- process.emitWarning(
483
- 'The ".eslintignore" file is no longer supported. Switch to using the "ignores" property in "eslint.config.js": https://eslint.org/docs/latest/use/configure/migration-guide#ignoring-files',
484
- "ESLintIgnoreWarning",
485
- );
503
+ warningService.emitESLintIgnoreWarning();
486
504
  }
487
505
  }
488
506
 
@@ -611,7 +629,7 @@ class ESLint {
611
629
  if (!config) {
612
630
  throw createExtraneousResultsError();
613
631
  }
614
- const rule = getRuleFromConfig(ruleId, config);
632
+ const rule = config.getRuleDefinition(ruleId);
615
633
 
616
634
  // ignore unknown rules
617
635
  if (rule) {
@@ -1068,7 +1086,7 @@ class ESLint {
1068
1086
  * This is the same logic used by the ESLint CLI executable to determine
1069
1087
  * configuration for each file it processes.
1070
1088
  * @param {string} filePath The path of the file to retrieve a config object for.
1071
- * @returns {Promise<ConfigData|undefined>} A configuration object for the file
1089
+ * @returns {Promise<Config|undefined>} A configuration object for the file
1072
1090
  * or `undefined` if there is no configuration data for the object.
1073
1091
  */
1074
1092
  async calculateConfigForFile(filePath) {
@@ -30,14 +30,14 @@ const { version } = require("../../package.json");
30
30
  //------------------------------------------------------------------------------
31
31
 
32
32
  /** @typedef {import("../cli-engine/cli-engine").LintReport} CLIEngineLintReport */
33
- /** @typedef {import("../shared/types").DeprecatedRuleInfo} DeprecatedRuleInfo */
34
- /** @typedef {import("../shared/types").ConfigData} ConfigData */
35
- /** @typedef {import("../shared/types").LintMessage} LintMessage */
36
- /** @typedef {import("../shared/types").SuppressedLintMessage} SuppressedLintMessage */
37
- /** @typedef {import("../shared/types").LintResult} LintResult */
38
- /** @typedef {import("../shared/types").ResultsMeta} ResultsMeta */
33
+ /** @typedef {import("../types").ESLint.ConfigData} ConfigData */
34
+ /** @typedef {import("../types").ESLint.DeprecatedRuleUse} DeprecatedRuleInfo */
35
+ /** @typedef {import("../types").Linter.LintMessage} LintMessage */
36
+ /** @typedef {import("../types").ESLint.LintResult} LintResult */
39
37
  /** @typedef {import("../types").ESLint.Plugin} Plugin */
38
+ /** @typedef {import("../types").ESLint.ResultsMeta} ResultsMeta */
40
39
  /** @typedef {import("../types").Rule.RuleModule} Rule */
40
+ /** @typedef {import("../types").Linter.SuppressedLintMessage} SuppressedLintMessage */
41
41
 
42
42
  /**
43
43
  * The main formatter object.