Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(react): improve option for react-refresh, aware Remix and Next.js #461

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 36 additions & 4 deletions src/configs/react.ts
Original file line number Diff line number Diff line change
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