eslint-plugin-primer-react 8.0.0-rc.d848c88 → 8.1.0-rc.ce584c0

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.
Files changed (33) hide show
  1. package/.github/copilot-instructions.md +159 -0
  2. package/.github/workflows/add-to-inbox.yml +2 -2
  3. package/.markdownlint-cli2.cjs +2 -2
  4. package/CHANGELOG.md +8 -2
  5. package/docs/rules/use-styled-react-import.md +128 -0
  6. package/eslint.config.js +54 -0
  7. package/package-lock.json +2000 -8406
  8. package/package.json +15 -9
  9. package/src/index.js +1 -0
  10. package/src/rules/__tests__/a11y-explicit-heading.test.js +5 -3
  11. package/src/rules/__tests__/a11y-link-in-text-block.test.js +5 -3
  12. package/src/rules/__tests__/a11y-no-duplicate-form-labels.test.js +5 -9
  13. package/src/rules/__tests__/a11y-no-title-usage.test.js +5 -3
  14. package/src/rules/__tests__/a11y-remove-disable-tooltip.test.js +5 -3
  15. package/src/rules/__tests__/a11y-tooltip-interactive-trigger.test.js +5 -3
  16. package/src/rules/__tests__/a11y-use-accessible-tooltip.test.js +5 -3
  17. package/src/rules/__tests__/direct-slot-children.test.js +5 -3
  18. package/src/rules/__tests__/enforce-button-for-link-with-nohref.test.js +5 -3
  19. package/src/rules/__tests__/enforce-css-module-identifier-casing.test.js +5 -3
  20. package/src/rules/__tests__/new-color-css-vars.test.js +5 -3
  21. package/src/rules/__tests__/no-deprecated-entrypoints.test.js +5 -3
  22. package/src/rules/__tests__/no-deprecated-experimental-components.test.js +5 -3
  23. package/src/rules/__tests__/no-deprecated-props.test.js +5 -3
  24. package/src/rules/__tests__/no-system-props.test.js +5 -4
  25. package/src/rules/__tests__/no-unnecessary-components.test.js +6 -4
  26. package/src/rules/__tests__/no-wildcard-imports.test.js +6 -43
  27. package/src/rules/__tests__/prefer-action-list-item-onselect.test.js +6 -4
  28. package/src/rules/__tests__/use-deprecated-from-deprecated.test.js +5 -3
  29. package/src/rules/__tests__/use-styled-react-import.test.js +251 -0
  30. package/src/rules/no-deprecated-experimental-components.js +0 -1
  31. package/src/rules/use-styled-react-import.js +483 -0
  32. package/.eslintignore +0 -2
  33. package/.eslintrc.js +0 -39
@@ -0,0 +1,251 @@
1
+ const rule = require('../use-styled-react-import')
2
+ const {RuleTester} = require('eslint')
3
+
4
+ const ruleTester = new RuleTester({
5
+ languageOptions: {
6
+ ecmaVersion: 'latest',
7
+ sourceType: 'module',
8
+ parserOptions: {
9
+ ecmaFeatures: {
10
+ jsx: true,
11
+ },
12
+ },
13
+ },
14
+ })
15
+
16
+ ruleTester.run('use-styled-react-import', rule, {
17
+ valid: [
18
+ // Valid: Component used without sx prop
19
+ `import { Button } from '@primer/react'
20
+ const Component = () => <Button>Click me</Button>`,
21
+
22
+ // Valid: Component with sx prop imported from styled-react
23
+ `import { Button } from '@primer/styled-react'
24
+ const Component = () => <Button sx={{ color: 'red' }}>Click me</Button>`,
25
+
26
+ // Valid: Utilities imported from styled-react
27
+ `import { sx } from '@primer/styled-react'`,
28
+
29
+ // Valid: Component not in the styled list
30
+ `import { Avatar } from '@primer/react'
31
+ const Component = () => <Avatar sx={{ color: 'red' }} />`,
32
+
33
+ // Valid: Component not imported from @primer/react
34
+ `import { Button } from '@github-ui/button'
35
+ const Component = () => <Button sx={{ color: 'red' }} />`,
36
+
37
+ // Valid: Mixed imports - component without sx prop
38
+ `import { Button, Text } from '@primer/react'
39
+ const Component = () => <Button>Click me</Button>`,
40
+
41
+ // Valid: Component without sx prop imported from styled-react (when not used)
42
+ `import { Button } from '@primer/styled-react'`,
43
+ ],
44
+ invalid: [
45
+ // Invalid: Box with sx prop imported from @primer/react
46
+ {
47
+ code: `import { Box } from '@primer/react'
48
+ const Component = () => <Box sx={{ color: 'red' }}>Content</Box>`,
49
+ output: `import { Box } from '@primer/styled-react'
50
+ const Component = () => <Box sx={{ color: 'red' }}>Content</Box>`,
51
+ errors: [
52
+ {
53
+ messageId: 'useStyledReactImport',
54
+ data: {componentName: 'Box'},
55
+ },
56
+ ],
57
+ },
58
+
59
+ // Invalid: Button with sx prop imported from @primer/react
60
+ {
61
+ code: `import { Button } from '@primer/react'
62
+ const Component = () => <Button sx={{ margin: 2 }}>Click me</Button>`,
63
+ output: `import { Button } from '@primer/styled-react'
64
+ const Component = () => <Button sx={{ margin: 2 }}>Click me</Button>`,
65
+ errors: [
66
+ {
67
+ messageId: 'useStyledReactImport',
68
+ data: {componentName: 'Button'},
69
+ },
70
+ ],
71
+ },
72
+
73
+ // Invalid: Multiple components, one with sx prop
74
+ {
75
+ code: `import { Button, Box, Avatar } from '@primer/react'
76
+ const Component = () => (
77
+ <div>
78
+ <Button>Regular button</Button>
79
+ <Box sx={{ padding: 2 }}>Styled box</Box>
80
+ <Avatar />
81
+ </div>
82
+ )`,
83
+ output: `import { Button, Avatar } from '@primer/react'
84
+ import { Box } from '@primer/styled-react'
85
+ const Component = () => (
86
+ <div>
87
+ <Button>Regular button</Button>
88
+ <Box sx={{ padding: 2 }}>Styled box</Box>
89
+ <Avatar />
90
+ </div>
91
+ )`,
92
+ errors: [
93
+ {
94
+ messageId: 'useStyledReactImport',
95
+ data: {componentName: 'Box'},
96
+ },
97
+ ],
98
+ },
99
+
100
+ // Invalid: Utility import from @primer/react that should be from styled-react
101
+ {
102
+ code: `import { sx } from '@primer/react'`,
103
+ output: `import { sx } from '@primer/styled-react'`,
104
+ errors: [
105
+ {
106
+ messageId: 'moveToStyledReact',
107
+ data: {importName: 'sx'},
108
+ },
109
+ ],
110
+ },
111
+
112
+ // Invalid: Button and Link, only Button uses sx
113
+ {
114
+ code: `import { Button, Link } from '@primer/react'
115
+ const Component = () => <Button sx={{ color: 'red' }}>Click me</Button>`,
116
+ output: `import { Link } from '@primer/react'
117
+ import { Button } from '@primer/styled-react'
118
+ const Component = () => <Button sx={{ color: 'red' }}>Click me</Button>`,
119
+ errors: [
120
+ {
121
+ messageId: 'useStyledReactImport',
122
+ data: {componentName: 'Button'},
123
+ },
124
+ ],
125
+ },
126
+
127
+ // Invalid: Button imported from styled-react but used without sx prop
128
+ {
129
+ code: `import { Button } from '@primer/styled-react'
130
+ const Component = () => <Button>Click me</Button>`,
131
+ output: `import { Button } from '@primer/react'
132
+ const Component = () => <Button>Click me</Button>`,
133
+ errors: [
134
+ {
135
+ messageId: 'usePrimerReactImport',
136
+ data: {componentName: 'Button'},
137
+ },
138
+ ],
139
+ },
140
+
141
+ // Invalid: <Link /> and <StyledButton /> imported from styled-react but used without sx prop
142
+ {
143
+ code: `import { Button } from '@primer/react'
144
+ import { Button as StyledButton, Link } from '@primer/styled-react'
145
+ const Component = () => (
146
+ <div>
147
+ <Link />
148
+ <Button>Regular button</Button>
149
+ <StyledButton>Styled button</StyledButton>
150
+ </div>
151
+ )`,
152
+ output: `import { Button, Link } from '@primer/react'
153
+
154
+ const Component = () => (
155
+ <div>
156
+ <Link />
157
+ <Button>Regular button</Button>
158
+ <Button>Styled button</Button>
159
+ </div>
160
+ )`,
161
+ errors: [
162
+ {
163
+ messageId: 'usePrimerReactImport',
164
+ data: {componentName: 'Button'},
165
+ },
166
+ {
167
+ messageId: 'usePrimerReactImport',
168
+ data: {componentName: 'Link'},
169
+ },
170
+ {
171
+ messageId: 'usePrimerReactImport',
172
+ data: {componentName: 'Button'},
173
+ },
174
+ ],
175
+ },
176
+
177
+ // Invalid: Box imported from styled-react but used without sx prop
178
+ {
179
+ code: `import { Box } from '@primer/styled-react'
180
+ const Component = () => <Box>Content</Box>`,
181
+ output: `import { Box } from '@primer/react'
182
+ const Component = () => <Box>Content</Box>`,
183
+ errors: [
184
+ {
185
+ messageId: 'usePrimerReactImport',
186
+ data: {componentName: 'Box'},
187
+ },
188
+ ],
189
+ },
190
+
191
+ // Invalid: Multiple components from styled-react, one used without sx
192
+ {
193
+ code: `import { Button, Box } from '@primer/styled-react'
194
+ const Component = () => (
195
+ <div>
196
+ <Button>Regular button</Button>
197
+ <Box sx={{ padding: 2 }}>Styled box</Box>
198
+ </div>
199
+ )`,
200
+ output: `import { Box } from '@primer/styled-react'
201
+ import { Button } from '@primer/react'
202
+ const Component = () => (
203
+ <div>
204
+ <Button>Regular button</Button>
205
+ <Box sx={{ padding: 2 }}>Styled box</Box>
206
+ </div>
207
+ )`,
208
+ errors: [
209
+ {
210
+ messageId: 'usePrimerReactImport',
211
+ data: {componentName: 'Button'},
212
+ },
213
+ ],
214
+ },
215
+
216
+ // Invalid: Button used both with and without sx prop - should use alias
217
+ {
218
+ code: `import { Button, Link } from '@primer/react'
219
+ const Component = () => (
220
+ <div>
221
+ <Link sx={{ color: 'red' }} />
222
+ <Button>Regular button</Button>
223
+ <Button sx={{ color: 'red' }}>Styled button</Button>
224
+ </div>
225
+ )`,
226
+ output: `import { Button } from '@primer/react'
227
+ import { Button as StyledButton, Link } from '@primer/styled-react'
228
+ const Component = () => (
229
+ <div>
230
+ <Link sx={{ color: 'red' }} />
231
+ <Button>Regular button</Button>
232
+ <StyledButton sx={{ color: 'red' }}>Styled button</StyledButton>
233
+ </div>
234
+ )`,
235
+ errors: [
236
+ {
237
+ messageId: 'useStyledReactImportWithAlias',
238
+ data: {componentName: 'Button', aliasName: 'StyledButton'},
239
+ },
240
+ {
241
+ messageId: 'useStyledReactImport',
242
+ data: {componentName: 'Link'},
243
+ },
244
+ {
245
+ messageId: 'useAliasedComponent',
246
+ data: {componentName: 'Button', aliasName: 'StyledButton'},
247
+ },
248
+ ],
249
+ },
250
+ ],
251
+ })
@@ -52,7 +52,6 @@ module.exports = {
52
52
  }
53
53
 
54
54
  if (experimental.length > 0) {
55
- // eslint-disable-next-line i18n-text/no-en
56
55
  const message = `The experimental ${components.join(', ')} ${
57
56
  components.length > 1 ? 'are' : 'is'
58
57
  } deprecated. Please import from the stable entrypoint (@primer/react) if available. Check https://primer.style/product/getting-started/react/migration-guides/ for migration guidance or https://primer.style/product/components/ for alternative components.`