Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Enhancement: support ESLint's new defineConfig string config references #10934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
4 tasks done
niklaswimmer opened this issue Mar 10, 2025 · 3 comments · Fixed by #10973
Closed
4 tasks done

Enhancement: support ESLint's new defineConfig string config references #10934

niklaswimmer opened this issue Mar 10, 2025 · 3 comments · Fixed by #10973
Labels
accepting prs Go ahead, send a pull request that resolves this issue enhancement New feature or request locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.

Comments

@niklaswimmer
Copy link

niklaswimmer commented Mar 10, 2025

Before You File a Proposal Please Confirm You Have Done The Following...

Relevant Package

typescript-eslint

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Description

With ESLint v9.22 they added their own defineConfig config helper (similar to config), which does again support extends. I of course immediately tried to rewrite my ESLint config to use the new helper:

import { defineConfig, globalIgnores } from "eslint/config";
import ts from "typescript-eslint";

export default defineConfig(
    {
        plugins: {
            ts: ts.plugin
        },
        extends: [
            "ts/strict",
            "ts/stylistic",
        ],
        rules: {
            "ts/no-inferrable-types": [
                "error",
                { ignoreParameters: true, ignoreProperties: true },
            ],
        },
    },
);

Running npx eslint fails with the following error:

Oops! Something went wrong! :(

ESLint: 9.22.0

TypeError: Plugin config "ts/strict" is an eslintrc config and cannot be used in this context.
    at deepNormalizePluginConfig (C:\Users\niklaswimmer\Dev\test\node_modules\@eslint\config-helpers\dist\cjs\index.cjs:231:9)
    at findPluginConfig (C:\Users\niklaswimmer\Dev\test\node_modules\@eslint\config-helpers\dist\cjs\index.cjs:262:9)
    at C:\Users\niklaswimmer\Dev\test\node_modules\@eslint\config-helpers\dist\cjs\index.cjs:394:25
    at Array.map (<anonymous>)
    at processExtends (C:\Users\niklaswimmer\Dev\test\node_modules\@eslint\config-helpers\dist\cjs\index.cjs:392:36)
    at C:\Users\niklaswimmer\Dev\test\node_modules\@eslint\config-helpers\dist\cjs\index.cjs:464:38
    at Array.flatMap (<anonymous>)
    at processConfigList (C:\Users\niklaswimmer\Dev\test\node_modules\@eslint\config-helpers\dist\cjs\index.cjs:464:20)
    at defineConfig (C:\Users\niklaswimmer\Dev\test\node_modules\@eslint\config-helpers\dist\cjs\index.cjs:499:9)
    at file:///C:/Users/niklaswimmer/Dev/test/eslint.config.mjs?mtime=1741610408364:37:16

My understandig is that when given ts/strict ESLint tries to access ts.plugin.configs.strict, which is not the same as ts.configs.strict and not compatible with flat configs.

Additional Info

I marked this as enhancement and not as bug because the "fix" is to simply use ts.configs.strict instead of "ts/strict" (and use the full rule namespace instead of just "ts"), but I expect the current behavior to be confusing for new users (ESLint shows both options in their docs, but if one of them does not work, it will be confusing).

@bradzacher
Copy link
Member

Unfortunately the new string references ignore where we have provided flat configs for users - via tseslint.configs.recommended etc.

Instead it tries to access the configs via the plugin - I.e. Via tseslint.plugin.configs.recommended. This access path leads to our legacy configs.

We will continue to work this way for the foreseeable future. We cannot and will not change the plugin to break legacy config users.

For now please use our existing supported and documented method to access our flat configs. https://typescript-eslint.io/users/configs

Once eslint advances the backwards compatibility story here we can revisit this. See this eslint core issue for that: eslint/eslint#18095

@bradzacher bradzacher closed this as not planned Won't fix, can't repro, duplicate, stale Mar 10, 2025
@bradzacher bradzacher added blocked by external API Blocked by a tool we depend on exposing an API, such as TypeScript's Type Relationship API and removed triage Waiting for team members to take a look labels Mar 10, 2025
@niklaswimmer
Copy link
Author

Alright, yeah that makes sense. Thanks for the quick response :)

@github-actions github-actions bot added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Mar 18, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2025
@kirkwaiblinger kirkwaiblinger added triage Waiting for team members to take a look and removed blocked by external API Blocked by a tool we depend on exposing an API, such as TypeScript's Type Relationship API locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. labels Mar 18, 2025
@kirkwaiblinger
Copy link
Member

Reopening this in light of eslint/eslint#19513 being resolved 🚀.

As I understand it, the action item on our side for now would be to export our flat configs on the plugin object with the flat/ prefix.

Not sure if it's critical but we probably want to do this in a way that ensures that require('typescript-eslint').configs.recommended, require('typescript-eslint').plugin.configs['flat/recommended'], and require('@typescript-eslint/eslint-plugin').configs['flat/recommended'] are all referentially ===.

@typescript-eslint typescript-eslint unlocked this conversation Mar 18, 2025
@kirkwaiblinger kirkwaiblinger added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for team members to take a look labels Mar 18, 2025
@bradzacher bradzacher changed the title Enhancement: better support ESLint's new defineConfig/extends Enhancement: support ESLint's new defineConfig string config references Mar 19, 2025
@github-actions github-actions bot added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Apr 18, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 18, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue enhancement New feature or request locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants