eslint-plugin-primer-react 8.1.0 → 8.2.0-rc.1772227

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # eslint-plugin-primer-react
2
2
 
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
+
3
13
  ## 8.1.0
4
14
 
5
15
  ### Minor Changes
@@ -12,7 +12,7 @@ Enforce importing components that use `sx` prop from `@primer/styled-react` inst
12
12
 
13
13
  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`.
14
14
 
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.
16
16
 
17
17
  It also moves certain types and utilities to the styled-react package.
18
18
 
@@ -111,17 +111,64 @@ const Component = () => <Button>Click me</Button>
111
111
  ```
112
112
 
113
113
  ```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'
117
116
 
118
117
  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>
120
119
  ```
121
120
 
122
121
  ## Options
123
122
 
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
+ ```
125
172
 
126
173
  ## When Not To Use It
127
174