-
Couldn't load subscription status.
- Fork 10
Make use-styled-react-import rule configurable
#407
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
Conversation
🦋 Changeset detectedLatest commit: b5b4df3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR makes the use-styled-react-import ESLint rule configurable by converting hardcoded component, type, and utility lists into configurable options while maintaining full backward compatibility.
- Replaces static
Setobjects with configurable arrays that can be customized via rule options - Adds JSON schema validation for the new configuration properties
- Extends test coverage to verify custom configuration scenarios work correctly
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/rules/use-styled-react-import.js |
Converts hardcoded arrays to configurable options with schema validation and maintains backward compatibility through defaults |
src/rules/__tests__/use-styled-react-import.test.js |
Adds comprehensive test cases for custom configuration scenarios including valid/invalid usage patterns |
docs/rules/use-styled-react-import.md |
Updates documentation with new "Options" section explaining configuration properties and usage examples |
This PR converts the hardcoded data structures in the
use-styled-react-importESLint 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-reactwhen used withsxpropstyledTypes- Types that should always be imported from@primer/styled-reactstyledUtilities- Utilities that should always be imported from@primer/styled-reactAdded 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:
{ "rules": { "@primer/primer-react/use-styled-react-import": [ "error", { "styledComponents": ["Button", "Box", "CustomComponent"], "styledTypes": ["BoxProps", "CustomProps"], "styledUtilities": ["sx", "customSx"] } ] } }🧪 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)
{ "rules": { "@primer/primer-react/use-styled-react-import": "error" } }After (new capability)
{ "rules": { "@primer/primer-react/use-styled-react-import": [ "error", { "styledComponents": ["CustomButton", "CustomBox"], "styledUtilities": ["customSx"] } ] } }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.