11/* eslint-disable perfectionist/sort-objects */
2- import type { OptionsFiles , OptionsOverrides , OptionsTypeScriptParserOptions , OptionsTypeScriptWithTypes , TypedFlatConfigItem } from '../types'
2+ import type { OptionsFiles , OptionsReact , OptionsTypeScriptParserOptions , OptionsTypeScriptWithTypes , TypedFlatConfigItem } from '../types'
33
44import { isPackageExists } from 'local-pkg'
55import { GLOB_ASTRO_TS , GLOB_MARKDOWN , GLOB_SRC , GLOB_TS , GLOB_TSX } from '../globs'
@@ -25,9 +25,12 @@ const ReactRouterPackages = [
2525const NextJsPackages = [
2626 'next' ,
2727]
28+ const ReactCompilerPackages = [
29+ 'babel-plugin-react-compiler' ,
30+ ]
2831
2932export async function react (
30- options : OptionsTypeScriptParserOptions & OptionsTypeScriptWithTypes & OptionsOverrides & OptionsFiles = { } ,
33+ options : OptionsTypeScriptParserOptions & OptionsTypeScriptWithTypes & OptionsReact & OptionsFiles = { } ,
3134) : Promise < TypedFlatConfigItem [ ] > {
3235 const {
3336 files = [ GLOB_SRC ] ,
@@ -38,6 +41,7 @@ export async function react(
3841 ] ,
3942 overrides = { } ,
4043 tsconfigPath,
44+ reactCompiler = ReactCompilerPackages . some ( i => isPackageExists ( i ) ) ,
4145 } = options
4246
4347 await ensurePackages ( [
@@ -153,8 +157,31 @@ export async function react(
153157 'react-dom/no-use-form-state' : 'error' ,
154158 'react-dom/no-void-elements-with-children' : 'error' ,
155159
156- // recommended rules eslint-plugin-react-hooks https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hooks/src/rules
157- ...pluginReactHooks . configs . recommended . rules ,
160+ // recommended rules eslint-plugin-react-hooks https://github.com/facebook/react/blob/main/packages/eslint-plugin-react-hooks/README.md
161+ // Core hooks rules
162+ 'react-hooks/rules-of-hooks' : 'error' ,
163+ 'react-hooks/exhaustive-deps' : 'warn' ,
164+
165+ // React Compiler rules
166+ ...( reactCompiler
167+ ? {
168+ 'react-hooks/config' : 'error' ,
169+ 'react-hooks/error-boundaries' : 'error' ,
170+ 'react-hooks/component-hook-factories' : 'error' ,
171+ 'react-hooks/gating' : 'error' ,
172+ 'react-hooks/globals' : 'error' ,
173+ 'react-hooks/immutability' : 'error' ,
174+ 'react-hooks/preserve-manual-memoization' : 'error' ,
175+ 'react-hooks/purity' : 'error' ,
176+ 'react-hooks/refs' : 'error' ,
177+ 'react-hooks/set-state-in-effect' : 'error' ,
178+ 'react-hooks/set-state-in-render' : 'error' ,
179+ 'react-hooks/static-components' : 'error' ,
180+ 'react-hooks/unsupported-syntax' : 'warn' ,
181+ 'react-hooks/use-memo' : 'error' ,
182+ 'react-hooks/incompatible-library' : 'warn' ,
183+ }
184+ : { } ) ,
158185
159186 // recommended rules from eslint-plugin-react-hooks-extra https://eslint-react.xyz/docs/rules/overview#hooks-extra-rules
160187 'react-hooks-extra/no-direct-set-state-in-use-effect' : 'warn' ,
0 commit comments