Skip to content

Commit 28b7fdd

Browse files
Merge branch 'main' into copilot/fix-375
2 parents af1d34d + 5902197 commit 28b7fdd

File tree

7 files changed

+966
-578
lines changed

7 files changed

+966
-578
lines changed

.changeset/cyan-carrots-boil.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-primer-react": patch
3+
---
4+
5+
Fix for deprecated and experimental import paths

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# eslint-plugin-primer-react
22

3+
## 8.2.0
4+
5+
### Minor Changes
6+
7+
- [#407](https://github.com/primer/eslint-plugin-primer-react/pull/407) [`2f25480`](https://github.com/primer/eslint-plugin-primer-react/commit/2f25480c3341c1d1afb6fc040c5c5deee416d71c) Thanks [@jonrohan](https://github.com/jonrohan)! - Make `use-styled-react-import` rule configurable
8+
9+
### Patch Changes
10+
11+
- [#406](https://github.com/primer/eslint-plugin-primer-react/pull/406) [`d72e8c4`](https://github.com/primer/eslint-plugin-primer-react/commit/d72e8c4c172d1c37da201a20cde0b7b2bd9ab283) Thanks [@jonrohan](https://github.com/jonrohan)! - Fixes for `use-styled-react-import` rule for compound components.
12+
313
## 8.1.0
414

515
### Minor Changes

docs/rules/use-styled-react-import.md

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Enforce importing components that use `sx` prop from `@primer/styled-react` inst
1212

1313
This rule detects when certain Primer React components are used with the `sx` prop and ensures they are imported from the temporary `@primer/styled-react` package instead of `@primer/react`. When the same components are used without the `sx` prop, it ensures they are imported from `@primer/react` instead of `@primer/styled-react`.
1414

15-
When a component is used both with and without the `sx` prop in the same file, the rule will import the styled version with an alias (e.g., `StyledButton`) and update the JSX usage accordingly to avoid naming conflicts.
15+
When a component is used with the `sx` prop anywhere in the file, the entire component import is moved to `@primer/styled-react`, simplifying the import structure.
1616

1717
It also moves certain types and utilities to the styled-react package.
1818

@@ -111,17 +111,64 @@ const Component = () => <Button>Click me</Button>
111111
```
112112

113113
```jsx
114-
// When a component is used both ways, use an alias for the styled version
115-
import {Button} from '@primer/react'
116-
import {Button as StyledButton} from '@primer/styled-react'
114+
// When a component is used with sx prop anywhere, import from styled-react
115+
import {Button} from '@primer/styled-react'
117116

118117
const Component1 = () => <Button>Click me</Button>
119-
const Component2 = () => <StyledButton sx={{color: 'red'}}>Styled me</StyledButton>
118+
const Component2 = () => <Button sx={{color: 'red'}}>Styled me</Button>
120119
```
121120

122121
## Options
123122

124-
This rule has no options.
123+
This rule accepts an optional configuration object with the following properties:
124+
125+
- `styledComponents` (array of strings): Components that should be imported from `@primer/styled-react` when used with `sx` prop. Defaults to the list shown above.
126+
- `styledTypes` (array of strings): Types that should always be imported from `@primer/styled-react`. Defaults to `['BoxProps', 'SxProp', 'BetterSystemStyleObject']`.
127+
- `styledUtilities` (array of strings): Utilities that should always be imported from `@primer/styled-react`. Defaults to `['sx']`.
128+
129+
### Example Configuration
130+
131+
```json
132+
{
133+
"rules": {
134+
"@primer/primer-react/use-styled-react-import": [
135+
"error",
136+
{
137+
"styledComponents": ["Button", "Box", "CustomComponent"],
138+
"styledTypes": ["BoxProps", "CustomProps"],
139+
"styledUtilities": ["sx", "customSx"]
140+
}
141+
]
142+
}
143+
}
144+
```
145+
146+
### Configuration Examples
147+
148+
#### ❌ Incorrect with custom configuration
149+
150+
```jsx
151+
// With styledComponents: ["CustomButton"]
152+
import {CustomButton} from '@primer/react'
153+
154+
const Component = () => <CustomButton sx={{color: 'red'}}>Click me</CustomButton>
155+
```
156+
157+
#### ✅ Correct with custom configuration
158+
159+
```jsx
160+
// With styledComponents: ["CustomButton"]
161+
import {CustomButton} from '@primer/styled-react'
162+
163+
const Component = () => <CustomButton sx={{color: 'red'}}>Click me</CustomButton>
164+
```
165+
166+
```jsx
167+
// Box is not in custom styledComponents list, so it can be used with sx from @primer/react
168+
import {Box} from '@primer/react'
169+
170+
const Component = () => <Box sx={{color: 'red'}}>Content</Box>
171+
```
125172

126173
## When Not To Use It
127174

0 commit comments

Comments
 (0)