Skip to content

Commit 24d4f14

Browse files
antfuhyoban
andauthoredApr 25, 2024··
fix(react): improve option for react-refresh, aware Remix and Next.js (#461)
Co-authored-by: Stephen Zhou <hi@hyoban.cc>
1 parent e9bcb8a commit 24d4f14

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed
 

‎src/configs/react.ts

+36-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ import { GLOB_TS, GLOB_TSX } from '../globs'
77
const ReactRefreshAllowConstantExportPackages = [
88
'vite',
99
]
10+
const RemixPackages = [
11+
'@remix-run/node',
12+
'@remix-run/react',
13+
'@remix-run/serve',
14+
'@remix-run/dev',
15+
]
16+
const NextJsPackages = [
17+
'next',
18+
]
1019

1120
export async function react(
1221
options: OptionsTypeScriptWithTypes & OptionsOverrides & OptionsFiles = {},
@@ -39,9 +48,9 @@ export async function react(
3948
interopDefault(import('@typescript-eslint/parser')),
4049
] as const)
4150

42-
const isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some(
43-
i => isPackageExists(i),
44-
)
51+
const isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some(i => isPackageExists(i))
52+
const isUsingRemix = RemixPackages.some(i => isPackageExists(i))
53+
const isUsingNext = NextJsPackages.some(i => isPackageExists(i))
4554

4655
const plugins = pluginReact.configs.all.plugins
4756

@@ -91,7 +100,30 @@ export async function react(
91100
// react refresh
92101
'react-refresh/only-export-components': [
93102
'warn',
94-
{ allowConstantExport: isAllowConstantExport },
103+
{
104+
allowConstantExport: isAllowConstantExport,
105+
allowExportNames: [
106+
...(isUsingNext
107+
? [
108+
'config',
109+
'generateStaticParams',
110+
'metadata',
111+
'generateMetadata',
112+
'viewport',
113+
'generateViewport',
114+
]
115+
: []),
116+
...(isUsingRemix
117+
? [
118+
'meta',
119+
'links',
120+
'headers',
121+
'loader',
122+
'action',
123+
]
124+
: []),
125+
],
126+
},
95127
],
96128

97129
// recommended rules from @eslint-react

0 commit comments

Comments
 (0)
Please sign in to comment.