Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Docs: Clarify how theconfig() helper handles rule merging in flat config #11220

Closed as not planned
Labels
documentationDocumentation ("docs") that needs adding/updatinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.triageWaiting for team members to take a look
@wujekbogdan

Description

@wujekbogdan

Before You File a Documentation Request Please Confirm You Have Done The Following...

Suggested Changes

Here's my real-life config:

importjsEslintfrom"@eslint/js";importeslintConfigPrettierfrom"eslint-config-prettier/flat";importreactHooksfrom"eslint-plugin-react-hooks";importreactRefreshfrom"eslint-plugin-react-refresh";importglobalsfrom"globals";importtsEslintfrom"typescript-eslint";exportdefaulttsEslint.config(jsEslint.configs.recommended,tsEslint.configs.recommendedTypeChecked,tsEslint.configs.stylisticTypeChecked,reactHooks.configs["recommended-latest"],reactRefresh.configs.recommended,reactRefresh.configs.vite,{ignores:["dist"],},{languageOptions:{parserOptions:{project:["./tsconfig.node.json","./tsconfig.app.json"],tsconfigRootDir:import.meta.dirname,},ecmaVersion:2020,globals:globals.browser,},},{files:["**/*.js","**/*.mjs"],extends:[tsEslint.configs.disableTypeChecked],},eslintConfigPrettier,);

After setting it up, it turned out there's just one rule I'd like to override, so I turned my config into:

exportdefaulttsEslint.config(// ... configs{ignores:["dist"],},{languageOptions:{parserOptions:{project:["./tsconfig.node.json","./tsconfig.app.json"],tsconfigRootDir:import.meta.dirname,},ecmaVersion:2020,globals:globals.browser,},rules:{// The rule I added:"@typescript-eslint/consistent-type-definitions":"off",},},{files:["**/*.js","**/*.mjs"],extends:[tsEslint.configs.disableTypeChecked],},eslintConfigPrettier,);

I expected this to simply merge with the existing rules, but it turned out it overwrote all the previously set rules, includingreact-hooks/rules-of-hooks andreact-refresh/only-export-components.

My first instinct was to manually re-add all the previously defined rules:

exportdefaulttsEslint.config(// ... configs{ignores:["dist"],},{languageOptions:{parserOptions:{project:["./tsconfig.node.json","./tsconfig.app.json"],tsconfigRootDir:import.meta.dirname,},ecmaVersion:2020,globals:globals.browser,},rules:{// The rules I brought back:"react-hooks/rules-of-hooks":"error","react-hooks/exhaustive-deps":"warn","react-refresh/only-export-components":"error","@typescript-eslint/consistent-type-definitions":"off",},},{files:["**/*.js","**/*.mjs"],extends:[tsEslint.configs.disableTypeChecked],},eslintConfigPrettier,);

It worked, but the manual process didn't feel right or elegant, so I started fiddling around and figured out that I have to append therules into the next array item, instead of adding it to the entry that containslanguageOptions.

I ended up with:

importjsEslintfrom"@eslint/js";importeslintConfigPrettierfrom"eslint-config-prettier/flat";importreactHooksfrom"eslint-plugin-react-hooks";importreactRefreshfrom"eslint-plugin-react-refresh";importglobalsfrom"globals";importtsEslintfrom"typescript-eslint";exportdefaulttsEslint.config(// ... configs{ignores:["dist"],},{languageOptions:{parserOptions:{project:["./tsconfig.node.json","./tsconfig.app.json"],tsconfigRootDir:import.meta.dirname,},ecmaVersion:2020,globals:globals.browser,},},{rules:{"@typescript-eslint/consistent-type-definitions":"off",},},{files:["**/*.js","**/*.mjs"],extends:[tsEslint.configs.disableTypeChecked],},eslintConfigPrettier,);

It was just a trial-and-error process that led me to that solution, but after figuring it out I still don't really understand why it worked. Why does havingrules together withlanguageOptions prevent merging, whereas a separate entry containing just therules object is correctly merged?


What I'm proposing is adding a very explicit explanation on how to add custom rule overrides in a safe way - so that preceding rules aren't overridden OR, and maybe it's a better option, clarify how thetsEslint.config() performs merging: what's being merged and what is not.

Affected URL(s)

https://typescript-eslint.io/packages/typescript-eslint#config

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationDocumentation ("docs") that needs adding/updatinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.triageWaiting for team members to take a look

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp