[feat] migrate `react-x/prefer-react-namespace-import` to `import-x/prefer-namespace-import` Rule with Custom Patterns
Describe the problem
Context
This rule was previously proposed at #803. In the eslint-react's context only includes "react" and "react-dom" or other React renderer packages, which are less sensitive to tree-shaking needs. We propose migrating this rule to a more generalized implementation under import-x to serve broader use cases.
Rationale
While modern bundlers support tree-shaking for both import styles, many projects still rely on import * as mod from "source" to enforce tree-shaking or just for consistent code style. This rule remains necessary for such codebases.
Proposed Rule
Implement a import-x/prefer-namespace-import rule with a patterns configuration to match scoped/prefixed packages (e.g., @scope/*, prefix-*) and auto-fix them to namespace imports.
Configuration Example
{
"rules": {
"import-x/prefer-namespace-import": [
"error",
{
"patterns": ["foo"], // Simple string match
// OR RegExp patterns
"patterns": ["/^@scope/", "/^prefix-/"]
}
]
}
}
Auto-Fix Example
// Before
import foo from "foo";
// After auto-fix
import * as foo from "foo";
Describe the solution you'd like
No response
Alternatives considered
No response
Additional context
No response