From 3384cbb063d69a681a4ab7c543b563dc4c113dec Mon Sep 17 00:00:00 2001 From: Matt Mower Date: Mon, 27 Oct 2025 11:36:14 -0700 Subject: [PATCH 1/3] [eprh] Adhere to ESLint.Plugin type - Use TS `satisfies` operator to ensure `plugin` adheres to the ESLint.Plugin shape while retaining its actual shape for export. - Assign configs as part of `plugin` assignment, only delaying the assignment of the `plugin` property in flat configs. This improves exported types without hacky assertions. - BREAKING CHANGE: flatten `configs` to match the expected shape: - Flat configs are now the default: - `configs.recommended` - `configs['recommended-latest']` - Legacy configs are now prefixed: - `configs['legacy-recommended']` - `configs['legacy-recommended-latest']` --- packages/eslint-plugin-react-hooks/README.md | 8 +-- .../eslint-plugin-react-hooks/src/index.ts | 57 +++++++------------ 2 files changed, 26 insertions(+), 39 deletions(-) diff --git a/packages/eslint-plugin-react-hooks/README.md b/packages/eslint-plugin-react-hooks/README.md index a1b4bcabb59fd..5843314592d7f 100644 --- a/packages/eslint-plugin-react-hooks/README.md +++ b/packages/eslint-plugin-react-hooks/README.md @@ -24,7 +24,7 @@ import reactHooks from 'eslint-plugin-react-hooks'; import { defineConfig } from 'eslint/config'; export default defineConfig([ - reactHooks.configs.flat.recommended, + reactHooks.configs.recommended, ]); ``` @@ -36,17 +36,17 @@ import reactHooks from 'eslint-plugin-react-hooks'; import { defineConfig } from 'eslint/config'; export default defineConfig([ - reactHooks.configs.flat['recommended-latest'], + reactHooks.configs['recommended-latest'], ]); ``` ### Legacy Config (.eslintrc) -If you are still using ESLint below 9.0.0, the `recommended` preset can also be used to enable all recommended rules. +If you are still using ESLint below 9.0.0, the `legacy-recommended` preset can also be used to enable all recommended rules. ```js { - "extends": ["plugin:react-hooks/recommended"], + "extends": ["plugin:react-hooks/legacy-recommended"], // ... } diff --git a/packages/eslint-plugin-react-hooks/src/index.ts b/packages/eslint-plugin-react-hooks/src/index.ts index 924299d898948..f82cb852d40fb 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 {Linter, Rule, ESLint} from 'eslint'; import ExhaustiveDeps from './rules/ExhaustiveDeps'; import { @@ -55,46 +55,33 @@ const recommendedLatestRuleConfigs: Linter.RulesRecord = { ...recommendedLatestCompilerRuleConfigs, }; -const plugins = ['react-hooks']; - -type ReactHooksFlatConfig = { - plugins: {react: any}; - rules: Linter.RulesRecord; -}; - -const configs = { - recommended: { - plugins, - rules: recommendedRuleConfigs, - }, - 'recommended-latest': { - plugins, - rules: recommendedLatestRuleConfigs, - }, - flat: {} as { - recommended: ReactHooksFlatConfig; - 'recommended-latest': ReactHooksFlatConfig; - }, -}; - const plugin = { meta: { name: 'eslint-plugin-react-hooks', version: '7.0.0', }, rules, - configs, -}; - -Object.assign(configs.flat, { - 'recommended-latest': { - plugins: {'react-hooks': plugin}, - rules: configs['recommended-latest'].rules, - }, - recommended: { - plugins: {'react-hooks': plugin}, - rules: configs.recommended.rules, + configs: { + 'legacy-recommended': { + plugins: ['react-hooks'], + rules: recommendedRuleConfigs, + }, + 'legacy-recommended-latest': { + plugins: ['react-hooks'], + rules: recommendedLatestRuleConfigs, + }, + recommended: { + plugins: {'react-hooks': {}}, + rules: recommendedRuleConfigs, + }, + 'recommended-latest': { + plugins: {'react-hooks': {}}, + rules: recommendedLatestRuleConfigs, + }, }, -}); +} satisfies ESLint.Plugin; + +plugin.configs.recommended.plugins['react-hooks'] = plugin; +plugin.configs['recommended-latest'].plugins['react-hooks'] = plugin; export default plugin; From ea15273d4bed08e5a574821a5188d0f2988d2a5d Mon Sep 17 00:00:00 2001 From: Matt Mower Date: Mon, 27 Oct 2025 17:02:07 -0700 Subject: [PATCH 2/3] [eprh] Adhere to ESLint.Plugin type (Revisions) - Switch to legacy suffix instead of prefix --- packages/eslint-plugin-react-hooks/README.md | 4 ++-- packages/eslint-plugin-react-hooks/src/index.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/eslint-plugin-react-hooks/README.md b/packages/eslint-plugin-react-hooks/README.md index 5843314592d7f..571f0d1b3fc2f 100644 --- a/packages/eslint-plugin-react-hooks/README.md +++ b/packages/eslint-plugin-react-hooks/README.md @@ -42,11 +42,11 @@ export default defineConfig([ ### Legacy Config (.eslintrc) -If you are still using ESLint below 9.0.0, the `legacy-recommended` preset can also be used to enable all recommended rules. +If you are still using ESLint below 9.0.0, the `recommended-legacy` preset can also be used to enable all recommended rules. ```js { - "extends": ["plugin:react-hooks/legacy-recommended"], + "extends": ["plugin:react-hooks/recommended-legacy"], // ... } diff --git a/packages/eslint-plugin-react-hooks/src/index.ts b/packages/eslint-plugin-react-hooks/src/index.ts index f82cb852d40fb..816733f797c46 100644 --- a/packages/eslint-plugin-react-hooks/src/index.ts +++ b/packages/eslint-plugin-react-hooks/src/index.ts @@ -62,11 +62,11 @@ const plugin = { }, rules, configs: { - 'legacy-recommended': { + 'recommended-legacy': { plugins: ['react-hooks'], rules: recommendedRuleConfigs, }, - 'legacy-recommended-latest': { + 'recommended-latest-legacy': { plugins: ['react-hooks'], rules: recommendedLatestRuleConfigs, }, From 6f3b15c178a84cee751032819a8945d4e6625957 Mon Sep 17 00:00:00 2001 From: Matt Mower Date: Wed, 29 Oct 2025 15:56:10 -0700 Subject: [PATCH 3/3] [eprh] Adhere to ESLint.Plugin type (Revisions) - Update fixtures --- compiler/packages/eslint-plugin-react-compiler/README.md | 2 +- fixtures/eslint-v6/.eslintrc.json | 2 +- fixtures/eslint-v7/.eslintrc.json | 2 +- fixtures/eslint-v8/.eslintrc.json | 2 +- fixtures/eslint-v9/eslint.config.ts | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/packages/eslint-plugin-react-compiler/README.md b/compiler/packages/eslint-plugin-react-compiler/README.md index 3bf175f85e873..2b237c4a11fc8 100644 --- a/compiler/packages/eslint-plugin-react-compiler/README.md +++ b/compiler/packages/eslint-plugin-react-compiler/README.md @@ -28,7 +28,7 @@ import react from "eslint-plugin-react" export default [ // Your existing config - { ...pluginReact.configs.flat.recommended, settings: { react: { version: "detect" } } }, + { ...pluginReact.configs.recommended, settings: { react: { version: "detect" } } }, + reactCompiler.configs.recommended ] ``` diff --git a/fixtures/eslint-v6/.eslintrc.json b/fixtures/eslint-v6/.eslintrc.json index 672da7a085a64..92b01f8bde6bc 100644 --- a/fixtures/eslint-v6/.eslintrc.json +++ b/fixtures/eslint-v6/.eslintrc.json @@ -1,6 +1,6 @@ { "root": true, - "extends": ["plugin:react-hooks/recommended"], + "extends": ["plugin:react-hooks/recommended-legacy"], "parserOptions": { "ecmaVersion": 2020, "sourceType": "module", diff --git a/fixtures/eslint-v7/.eslintrc.json b/fixtures/eslint-v7/.eslintrc.json index 672da7a085a64..92b01f8bde6bc 100644 --- a/fixtures/eslint-v7/.eslintrc.json +++ b/fixtures/eslint-v7/.eslintrc.json @@ -1,6 +1,6 @@ { "root": true, - "extends": ["plugin:react-hooks/recommended"], + "extends": ["plugin:react-hooks/recommended-legacy"], "parserOptions": { "ecmaVersion": 2020, "sourceType": "module", diff --git a/fixtures/eslint-v8/.eslintrc.json b/fixtures/eslint-v8/.eslintrc.json index 672da7a085a64..92b01f8bde6bc 100644 --- a/fixtures/eslint-v8/.eslintrc.json +++ b/fixtures/eslint-v8/.eslintrc.json @@ -1,6 +1,6 @@ { "root": true, - "extends": ["plugin:react-hooks/recommended"], + "extends": ["plugin:react-hooks/recommended-legacy"], "parserOptions": { "ecmaVersion": 2020, "sourceType": "module", diff --git a/fixtures/eslint-v9/eslint.config.ts b/fixtures/eslint-v9/eslint.config.ts index f7d0bddac443e..c8c0c08dbbbc9 100644 --- a/fixtures/eslint-v9/eslint.config.ts +++ b/fixtures/eslint-v9/eslint.config.ts @@ -2,7 +2,7 @@ import {defineConfig} from 'eslint/config'; import reactHooks from 'eslint-plugin-react-hooks'; export default defineConfig([ - reactHooks.configs.flat['recommended-latest'], + reactHooks.configs['recommended-latest'], { languageOptions: { ecmaVersion: 'latest',