-
Notifications
You must be signed in to change notification settings - Fork 20
Description
Description
The react-refresh/only-export-components
rule's allowExportNames
option currently only supports exact matches. When attempting to use a RegExp pattern (/.*Context$/
) or wildcard pattern (*Context
), the rule still flags context exports as warnings.
Current Setup
// .eslintrc.js
module.exports = {
rules: {
'react-refresh/only-export-components': [
'warn',
{
allowConstantExport: true,
allowExportNames: [/.*Context$/]
}
]
}
}
Current Behavior
Despite configuring the rule with a RegExp pattern to match context exports, the rule still produces warnings for files that export both a context and its provider:
export const ToastContext = createContext<DisplayToast>(defaultDisplayToast)
export const ToastProvider: FunctionComponent<ToastProviderProps> = ({ children }) => {
// ...
}
Proposed Behavior
Allow pattern matching in allowExportNames
using either:
- RegExp patterns:
[/.*Context$/]
- Glob patterns:
["*Context"]
This would make the configuration more maintainable and align with pattern-matching capabilities found in other ESLint rules.
Use Cases
- Context exports (
*Context
) - Framework-specific exports (e.g., Next.js
get*Props
, Remix*Loader
) - Common patterns in component libraries (
*Provider
,*Consumer
)
Impact
This enhancement would:
- Reduce configuration boilerplate
- Make configurations more maintainable
- Better support common React patterns and conventions
- Align with pattern-matching capabilities found in other ESLint rules
Environment
- eslint-plugin-react-refresh: 0.4.20
- ESLint: 9.25.1
- Node.js: v18.20.6
- TypeScript: 5.4.2 (inferred from @typescript-eslint version)
Additional Context
The current workaround is to list each context export individually:
{
allowExportNames: [
"ToastContext",
"ConfirmationContext",
"LoaderContext",
// ... and so on
]
}
This becomes unwieldy in larger applications with many contexts and makes the configuration harder to maintain.