Make use-styled-react-import
rule configurable
#407
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR converts the hardcoded data structures in the
use-styled-react-import
ESLint rule into configurable arguments, making the rule more flexible for different project needs while maintaining full backward compatibility.Changes Made
🔧 Core Implementation Changes
Converted static data structures to configurable options in
src/rules/use-styled-react-import.js
:styledComponents
- Components that should be imported from@primer/styled-react
when used withsx
propstyledTypes
- Types that should always be imported from@primer/styled-react
styledUtilities
- Utilities that should always be imported from@primer/styled-react
Added JSON Schema validation for configuration options with proper type checking and descriptions
Maintained backward compatibility - rule works identically with no configuration (uses same defaults as before)
📝 Configuration Options
The rule now accepts an optional configuration object:
🧪 Testing Improvements
src/rules/__tests__/use-styled-react-import.test.js
:📚 Documentation Updates
docs/rules/use-styled-react-import.md
:Benefits
✅ Flexibility
✅ Backward Compatibility
✅ Developer Experience
Usage Examples
Before (unchanged)
After (new capability)
Code Examples
Custom Component Configuration
❌ Invalid with custom config:
✅ Valid with custom config:
✅ Components not in custom list are unaffected:
Testing
Migration Guide
No migration required! This is a purely additive change. Existing rule configurations will continue to work exactly as before.
To take advantage of the new configuration options, simply add the configuration object as shown in the examples above.