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', diff --git a/packages/eslint-plugin-react-hooks/README.md b/packages/eslint-plugin-react-hooks/README.md index a1b4bcabb59fd..571f0d1b3fc2f 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 `recommended-legacy` preset can also be used to enable all recommended rules. ```js { - "extends": ["plugin:react-hooks/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 924299d898948..816733f797c46 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: { + 'recommended-legacy': { + plugins: ['react-hooks'], + rules: recommendedRuleConfigs, + }, + 'recommended-latest-legacy': { + 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;