From 34048301ed17b611015cc246d902bfc896944b17 Mon Sep 17 00:00:00 2001 From: Yousei Takahashi Date: Thu, 9 Oct 2025 17:18:05 +0900 Subject: [PATCH] [eprh] Fix config.flat keys to be inferred correctly --- .../eslint-plugin-react-hooks/src/index.ts | 65 ++++++++++--------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/packages/eslint-plugin-react-hooks/src/index.ts b/packages/eslint-plugin-react-hooks/src/index.ts index 6d72c1daa57a9..b64abee74db83 100644 --- a/packages/eslint-plugin-react-hooks/src/index.ts +++ b/packages/eslint-plugin-react-hooks/src/index.ts @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ -import type {Linter, Rule} from 'eslint'; +import type {ESLint, Linter, Rule} from 'eslint'; import ExhaustiveDeps from './rules/ExhaustiveDeps'; import { @@ -55,24 +55,21 @@ const recommendedLatestRuleConfigs: Linter.RulesRecord = { ...recommendedLatestCompilerRuleConfigs, }; -const plugins = ['react-hooks']; - -type ReactHooksFlatConfig = { - plugins: {react: any}; - rules: Linter.RulesRecord; +const pluginsLegacy = ['react-hooks']; +const pluginsFlat = { + 'react-hooks': {}, // Assign after creating the plugin object }; -const configs = { - recommended: { - plugins, - rules: recommendedRuleConfigs, - }, - 'recommended-latest': { - plugins, - rules: recommendedLatestRuleConfigs, - }, - flat: {} as Record, -}; +interface Plugin extends Omit { + configs: { + recommended: Linter.LegacyConfig; + 'recommended-latest': Linter.LegacyConfig; + flat: { + recommended: Linter.Config; + 'recommended-latest': Linter.Config; + }; + }; +} const plugin = { meta: { @@ -80,18 +77,28 @@ const plugin = { version: '7.0.0', }, rules, - configs, -}; - -Object.assign(configs.flat, { - 'recommended-latest': { - plugins: {'react-hooks': plugin}, - rules: configs['recommended-latest'].rules, + configs: { + recommended: { + plugins: pluginsLegacy, + rules: recommendedRuleConfigs, + }, + 'recommended-latest': { + plugins: pluginsLegacy, + rules: recommendedLatestRuleConfigs, + }, + flat: { + recommended: { + plugins: pluginsFlat, + rules: recommendedRuleConfigs, + }, + 'recommended-latest': { + plugins: pluginsFlat, + rules: recommendedLatestRuleConfigs, + }, + }, }, - recommended: { - plugins: {'react-hooks': plugin}, - rules: configs.recommended.rules, - }, -}); +} satisfies Plugin; + +pluginsFlat['react-hooks'] = plugin; export default plugin;