Skip to content

Commit

Permalink
fix(react): improve option for react-refresh, aware Remix and Next.js (
Browse files Browse the repository at this point in the history
…#461)

Co-authored-by: Stephen Zhou <hi@hyoban.cc>
  • Loading branch information
antfu and hyoban committed Apr 25, 2024
1 parent e9bcb8a commit 24d4f14
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions src/configs/react.ts
Expand Up @@ -7,6 +7,15 @@ import { GLOB_TS, GLOB_TSX } from '../globs'
const ReactRefreshAllowConstantExportPackages = [
'vite',
]
const RemixPackages = [
'@remix-run/node',
'@remix-run/react',
'@remix-run/serve',
'@remix-run/dev',
]
const NextJsPackages = [
'next',
]

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

const isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some(
i => isPackageExists(i),
)
const isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some(i => isPackageExists(i))
const isUsingRemix = RemixPackages.some(i => isPackageExists(i))
const isUsingNext = NextJsPackages.some(i => isPackageExists(i))

const plugins = pluginReact.configs.all.plugins

Expand Down Expand Up @@ -91,7 +100,30 @@ export async function react(
// react refresh
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: isAllowConstantExport },
{
allowConstantExport: isAllowConstantExport,
allowExportNames: [
...(isUsingNext
? [
'config',
'generateStaticParams',
'metadata',
'generateMetadata',
'viewport',
'generateViewport',
]
: []),
...(isUsingRemix
? [
'meta',
'links',
'headers',
'loader',
'action',
]
: []),
],
},
],

// recommended rules from @eslint-react
Expand Down

0 comments on commit 24d4f14

Please sign in to comment.