Skip to content

Commit 8efc2d0

Browse files
authored
feat: unflag TypeScript config files (#19266)
1 parent 87a9352 commit 8efc2d0

File tree

7 files changed

+86
-166
lines changed

7 files changed

+86
-166
lines changed

docs/src/use/configure/configuration-files.md

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -517,18 +517,6 @@ For more information about using feature flags, see [Feature Flags](../../flags/
517517

518518
## TypeScript Configuration Files
519519

520-
::: warning
521-
This feature is currently experimental and may change in future versions.
522-
:::
523-
524-
You need to enable this feature through the `unstable_ts_config` feature flag:
525-
526-
```bash
527-
npx eslint --flag unstable_ts_config
528-
```
529-
530-
For more information about using feature flags, see [Feature Flags](../../flags/).
531-
532520
For Deno and Bun, TypeScript configuration files are natively supported; for Node.js, you must install the optional dev dependency [`jiti`](https://github.com/unjs/jiti) in version 2.0.0 or later in your project (this dependency is not automatically installed by ESLint):
533521

534522
```bash
@@ -591,5 +579,5 @@ If you have multiple ESLint configuration files, ESLint prioritizes JavaScript f
591579
To override this behavior, use the `--config` or `-c` command line option to specify a different configuration file:
592580

593581
```bash
594-
npx eslint --flag unstable_ts_config --config eslint.config.ts
582+
npx eslint --config eslint.config.ts
595583
```

lib/cli.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,16 +341,15 @@ const cli = {
341341
/**
342342
* Calculates the command string for the --inspect-config operation.
343343
* @param {string} configFile The path to the config file to inspect.
344-
* @param {boolean} hasUnstableTSConfigFlag `true` if the `unstable_ts_config` flag is enabled, `false` if it's not.
345344
* @returns {Promise<string>} The command string to execute.
346345
*/
347-
async calculateInspectConfigFlags(configFile, hasUnstableTSConfigFlag) {
346+
async calculateInspectConfigFlags(configFile) {
348347

349348
// find the config file
350349
const {
351350
configFilePath,
352351
basePath
353-
} = await locateConfigFileToUse({ cwd: process.cwd(), configFile }, hasUnstableTSConfigFlag);
352+
} = await locateConfigFileToUse({ cwd: process.cwd(), configFile });
354353

355354
return ["--config", configFilePath, "--basePath", basePath];
356355
},
@@ -451,7 +450,7 @@ const cli = {
451450
try {
452451
const flatOptions = await translateOptions(options, "flat");
453452
const spawn = require("cross-spawn");
454-
const flags = await cli.calculateInspectConfigFlags(flatOptions.overrideConfigFile, flatOptions.flags ? flatOptions.flags.includes("unstable_ts_config") : false);
453+
const flags = await cli.calculateInspectConfigFlags(flatOptions.overrideConfigFile);
455454

456455
spawn.sync("npx", ["@eslint/config-inspector@latest", ...flags], { encoding: "utf8", stdio: "inherit" });
457456
} catch (error) {

lib/config/config-loader.js

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ const { FlatConfigArray } = require("./flat-config-array");
3131
* @property {Array<FlatConfigObject>} [defaultConfigs] The default configs to use.
3232
* @property {Array<string>} [ignorePatterns] The ignore patterns to use.
3333
* @property {FlatConfigObject|Array<FlatConfigObject>} overrideConfig The override config to use.
34-
* @property {boolean} allowTS Indicates if TypeScript configuration files are allowed.
3534
*/
3635

3736
//------------------------------------------------------------------------------
@@ -41,10 +40,7 @@ const { FlatConfigArray } = require("./flat-config-array");
4140
const FLAT_CONFIG_FILENAMES = [
4241
"eslint.config.js",
4342
"eslint.config.mjs",
44-
"eslint.config.cjs"
45-
];
46-
47-
const TS_FLAT_CONFIG_FILENAMES = [
43+
"eslint.config.cjs",
4844
"eslint.config.ts",
4945
"eslint.config.mts",
5046
"eslint.config.cts"
@@ -119,10 +115,9 @@ function isRunningInDeno() {
119115
/**
120116
* Load the config array from the given filename.
121117
* @param {string} filePath The filename to load from.
122-
* @param {boolean} allowTS Indicates if TypeScript configuration files are allowed.
123118
* @returns {Promise<any>} The config loaded from the config file.
124119
*/
125-
async function loadConfigFile(filePath, allowTS) {
120+
async function loadConfigFile(filePath) {
126121

127122
debug(`Loading config from ${filePath}`);
128123

@@ -171,7 +166,7 @@ async function loadConfigFile(filePath, allowTS) {
171166
*
172167
* When Node.js supports native TypeScript imports, we can remove this check.
173168
*/
174-
if (allowTS && isTS && !isDeno && !isBun) {
169+
if (isTS && !isDeno && !isBun) {
175170

176171
// eslint-disable-next-line no-use-before-define -- `ConfigLoader.loadJiti` can be overwritten for testing
177172
const { createJiti } = await ConfigLoader.loadJiti().catch(() => {
@@ -261,8 +256,7 @@ class ConfigLoader {
261256
const resultPromise = ConfigLoader.locateConfigFileToUse({
262257
useConfigFile: this.#options.configFile,
263258
cwd: this.#options.cwd,
264-
fromDirectory,
265-
allowTS: this.#options.allowTS
259+
fromDirectory
266260
});
267261

268262
// ensure `ConfigLoader.locateConfigFileToUse` is called only once for `fromDirectory`
@@ -443,15 +437,10 @@ class ConfigLoader {
443437
* @param {string|false|undefined} options.useConfigFile The path to the config file to use.
444438
* @param {string} options.cwd Path to a directory that should be considered as the current working directory.
445439
* @param {string} [options.fromDirectory] The directory from which to start searching. Defaults to `cwd`.
446-
* @param {boolean} options.allowTS Indicates if TypeScript configuration files are allowed.
447440
* @returns {Promise<{configFilePath:string|undefined,basePath:string}>} Location information for
448441
* the config file.
449442
*/
450-
static async locateConfigFileToUse({ useConfigFile, cwd, fromDirectory = cwd, allowTS }) {
451-
452-
const configFilenames = allowTS
453-
? [...FLAT_CONFIG_FILENAMES, ...TS_FLAT_CONFIG_FILENAMES]
454-
: FLAT_CONFIG_FILENAMES;
443+
static async locateConfigFileToUse({ useConfigFile, cwd, fromDirectory = cwd }) {
455444

456445
// determine where to load config file from
457446
let configFilePath;
@@ -464,7 +453,7 @@ class ConfigLoader {
464453
} else if (useConfigFile !== false) {
465454
debug("Searching for eslint.config.js");
466455
configFilePath = await findUp(
467-
configFilenames,
456+
FLAT_CONFIG_FILENAMES,
468457
{ cwd: fromDirectory }
469458
);
470459

@@ -497,8 +486,7 @@ class ConfigLoader {
497486
ignoreEnabled,
498487
ignorePatterns,
499488
overrideConfig,
500-
defaultConfigs = [],
501-
allowTS
489+
defaultConfigs = []
502490
} = options;
503491

504492
debug(`Calculating config array from config file ${configFilePath} and base path ${basePath}`);
@@ -509,7 +497,7 @@ class ConfigLoader {
509497
if (configFilePath) {
510498

511499
debug(`Loading config file ${configFilePath}`);
512-
const fileConfig = await loadConfigFile(configFilePath, allowTS);
500+
const fileConfig = await loadConfigFile(configFilePath);
513501

514502
if (Array.isArray(fileConfig)) {
515503
configs.push(...fileConfig);
@@ -618,8 +606,7 @@ class LegacyConfigLoader extends ConfigLoader {
618606
if (!this.#configFilePath) {
619607
this.#configFilePath = ConfigLoader.locateConfigFileToUse({
620608
useConfigFile: this.#options.configFile,
621-
cwd: this.#options.cwd,
622-
allowTS: this.#options.allowTS
609+
cwd: this.#options.cwd
623610
});
624611
}
625612

lib/eslint/eslint.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,13 @@ function compareResultsByFilePath(a, b) {
266266
* This function is used primarily by the `--inspect-config` option. For now,
267267
* we will maintain the existing behavior, which is to search up from the cwd.
268268
* @param {ESLintOptions} options The ESLint instance options.
269-
* @param {boolean} allowTS `true` if the `unstable_ts_config` flag is enabled, `false` if it's not.
270269
* @returns {Promise<{configFilePath:string|undefined;basePath:string}>} Location information for
271270
* the config file.
272271
*/
273-
async function locateConfigFileToUse({ configFile, cwd }, allowTS) {
272+
async function locateConfigFileToUse({ configFile, cwd }) {
274273

275274
const configLoader = new ConfigLoader({
276275
cwd,
277-
allowTS,
278276
configFile
279277
});
280278

@@ -469,8 +467,7 @@ class ESLint {
469467
configFile: processedOptions.configFile,
470468
ignoreEnabled: processedOptions.ignore,
471469
ignorePatterns: processedOptions.ignorePatterns,
472-
defaultConfigs,
473-
allowTS: processedOptions.flags.includes("unstable_ts_config")
470+
defaultConfigs
474471
};
475472

476473
this.#configLoader = processedOptions.flags.includes("unstable_config_lookup_from_file")

lib/shared/flags.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
*/
1111
const activeFlags = new Map([
1212
["test_only", "Used only for testing."],
13-
["unstable_config_lookup_from_file", "Look up `eslint.config.js` from the file being linted."],
14-
["unstable_ts_config", "Enable TypeScript configuration files."]
13+
["unstable_config_lookup_from_file", "Look up `eslint.config.js` from the file being linted."]
1514
]);
1615

1716
/**
1817
* The set of flags that used to be active but no longer have an effect.
1918
* @type {Map<string, string>}
2019
*/
2120
const inactiveFlags = new Map([
22-
["test_only_old", "Used only for testing."]
21+
["test_only_old", "Used only for testing."],
22+
["unstable_ts_config", "This flag is no longer required to enable TypeScript configuration files."]
2323
]);
2424

2525
module.exports = {

tests/fixtures/ts-config-files/helper.ts

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,15 @@
44
* and namespaces from other TypeScript files.
55
*/
66

7-
export type RuleLevelAndOptions<Options extends any[] = any[]> = Prepend<
8-
Partial<Options>,
9-
RuleLevel
10-
>;
11-
12-
export type StringSeverity = "off" | "warn" | "error";
7+
import { Linter } from "eslint";
138

149
export const enum Severity {
1510
"Off" = 0,
1611
"Warn" = 1,
1712
"Error" = 2,
1813
}
1914

20-
export type RuleLevel = Severity | StringSeverity;
21-
22-
export type RuleEntry<Options extends any[] = any[]> =
23-
| RuleLevel
24-
| RuleLevelAndOptions<Options>;
25-
26-
export interface RulesRecord {
27-
[rule: string]: RuleEntry;
28-
}
29-
30-
export interface FlatConfig<Rules extends RulesRecord = RulesRecord> {
31-
name?: string;
32-
files?: Array<string | string[]>;
33-
ignores?: string[];
34-
linterOptions?: {
35-
noInlineConfig?: boolean;
36-
reportUnusedDisableDirectives?: Severity | StringSeverity | boolean;
37-
};
38-
processor?: string;
39-
plugins?: Record<string, any>;
40-
rules?: Partial<Rules>;
41-
settings?: Record<string, unknown>;
42-
}
15+
export type FlatConfig = Linter.Config;
4316

4417
export namespace ESLintNameSpace {
4518
export const enum StringSeverity {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy