eslint-plugin-primer-react 8.6.1 → 9.0.0-rc.e1d461c
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 +9 -0
- package/README.md +1 -3
- package/package.json +2 -4
- package/src/configs/recommended.js +2 -2
- package/src/index.js +1 -3
- package/docs/rules/no-system-props.md +0 -67
- package/docs/rules/no-unnecessary-components.md +0 -69
- package/docs/rules/use-styled-react-import.md +0 -175
- package/src/rules/__tests__/no-system-props.test.js +0 -190
- package/src/rules/__tests__/no-unnecessary-components.test.js +0 -240
- package/src/rules/__tests__/use-styled-react-import.test.js +0 -537
- package/src/rules/no-system-props.js +0 -206
- package/src/rules/no-unnecessary-components.js +0 -160
- package/src/rules/use-styled-react-import.js +0 -435
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
const {RuleTester} = require('@typescript-eslint/rule-tester')
|
|
4
|
-
|
|
5
|
-
const path = require('node:path')
|
|
6
|
-
const rule = require('../no-unnecessary-components')
|
|
7
|
-
const {components} = require('../no-unnecessary-components')
|
|
8
|
-
|
|
9
|
-
const prcImport = 'import React from "react"; import {Box, Text} from "@primer/react";'
|
|
10
|
-
const styledReactImport = 'import React from "react"; import {Box, Text} from "@primer/styled-react";'
|
|
11
|
-
const brandImport = 'import React from "react"; import {Box, Text} from "@primer/react-brand";'
|
|
12
|
-
|
|
13
|
-
/** @param {string} content */
|
|
14
|
-
const jsx = content => `export const Component = () => <>${content}</>`
|
|
15
|
-
|
|
16
|
-
const sxObjectDeclaration = `const props = {sx: {color: "red"}};`
|
|
17
|
-
const asObjectDeclaration = `const props = {as: "table"};`
|
|
18
|
-
const stringRecordDeclaration = `const props: Record<string, any> = {};`
|
|
19
|
-
const testIdObjectDeclaration = `const props = {'data-testid': 'xyz'};`
|
|
20
|
-
const componentDeclaration = `const OtherComponent = ({children}: {children: React.ReactNode}) => <>{children}</>;`
|
|
21
|
-
const asConstDeclaration = `const as = "p";`
|
|
22
|
-
|
|
23
|
-
const ruleTester = new RuleTester({
|
|
24
|
-
languageOptions: {
|
|
25
|
-
parser: require('@typescript-eslint/parser'),
|
|
26
|
-
parserOptions: {
|
|
27
|
-
tsconfigRootDir: path.resolve(__dirname, 'fixtures'),
|
|
28
|
-
project: path.resolve(__dirname, 'fixtures', 'tsconfig.json'),
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
defaultFilenames: {
|
|
32
|
-
ts: 'file.ts',
|
|
33
|
-
tsx: 'File.tsx',
|
|
34
|
-
},
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
jest.retryTimes(0, {logErrorsBeforeRetry: true})
|
|
38
|
-
|
|
39
|
-
const filename = 'File.tsx'
|
|
40
|
-
|
|
41
|
-
ruleTester.run('unnecessary-components', rule, {
|
|
42
|
-
valid: [
|
|
43
|
-
{name: 'Unrelated JSX', code: jsx('<span>Hello World</span>'), filename},
|
|
44
|
-
...Object.keys(components).flatMap(component => [
|
|
45
|
-
{
|
|
46
|
-
name: `Non-PRC ${component}`,
|
|
47
|
-
code: `${brandImport}${jsx(`<${component}>Hello World</${component}>`)}`,
|
|
48
|
-
filename,
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
name: `${component} with sx prop`,
|
|
52
|
-
code: `${prcImport}${jsx(`<${component} sx={{color: "red"}}>Hello World</${component}>`)}`,
|
|
53
|
-
filename,
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
name: `${component} with any styled-system prop`,
|
|
57
|
-
code: `${prcImport}${jsx(`<${component} flex="row">Hello World</${component}>`)}`,
|
|
58
|
-
filename,
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
name: `${component} with spread sx prop`,
|
|
62
|
-
code: `${prcImport}${sxObjectDeclaration}${jsx(`<${component} {...props}>Hello World</${component}>`)}`,
|
|
63
|
-
filename,
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
name: `${component} with string index spread props`,
|
|
67
|
-
code: `${prcImport}${stringRecordDeclaration}${jsx(`<${component} {...props}>Hello World</${component}>`)}`,
|
|
68
|
-
filename,
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
name: `${component} from @primer/styled-react with sx prop`,
|
|
72
|
-
code: `${styledReactImport}${jsx(`<${component} sx={{color: "red"}}>Hello World</${component}>`)}`,
|
|
73
|
-
filename,
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
name: `${component} from @primer/styled-react with any styled-system prop`,
|
|
77
|
-
code: `${styledReactImport}${jsx(`<${component} flex="row">Hello World</${component}>`)}`,
|
|
78
|
-
filename,
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
name: `${component} from @primer/styled-react with spread sx prop`,
|
|
82
|
-
code: `${styledReactImport}${sxObjectDeclaration}${jsx(`<${component} {...props}>Hello World</${component}>`)}`,
|
|
83
|
-
filename,
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
name: `${component} from @primer/styled-react with string index spread props`,
|
|
87
|
-
code: `${styledReactImport}${stringRecordDeclaration}${jsx(`<${component} {...props}>Hello World</${component}>`)}`,
|
|
88
|
-
filename,
|
|
89
|
-
},
|
|
90
|
-
]),
|
|
91
|
-
{
|
|
92
|
-
name: `Text with weight prop`,
|
|
93
|
-
code: `${prcImport}${jsx(`<Text weight='medium'>Hello World</Text>`)}`,
|
|
94
|
-
filename,
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
name: `Text with size prop`,
|
|
98
|
-
code: `${prcImport}${jsx(`<Text size='small'>Hello World</Text>`)}`,
|
|
99
|
-
filename,
|
|
100
|
-
},
|
|
101
|
-
],
|
|
102
|
-
invalid: Object.entries(components).flatMap(([component, {messageId, replacement}]) => [
|
|
103
|
-
{
|
|
104
|
-
name: `${component} without any styled-system props`,
|
|
105
|
-
code: `${prcImport}${jsx(`<${component}>Hello World</${component}>`)}`,
|
|
106
|
-
output: `${prcImport}${jsx(`<${replacement}>Hello World</${replacement}>`)}`,
|
|
107
|
-
errors: [{messageId}],
|
|
108
|
-
filename,
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
name: `Self-closing ${component} without any styled-system props`,
|
|
112
|
-
code: `${prcImport}${jsx(`<${component} />`)}`,
|
|
113
|
-
output: `${prcImport}${jsx(`<${replacement} />`)}`,
|
|
114
|
-
errors: [{messageId}],
|
|
115
|
-
filename,
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
name: `${component} with spread props without sx`,
|
|
119
|
-
code: `${prcImport}${testIdObjectDeclaration}${jsx(`<${component} {...props}>Hello World</${component}>`)}`,
|
|
120
|
-
output: `${prcImport}${testIdObjectDeclaration}${jsx(`<${replacement} {...props}>Hello World</${replacement}>`)}`,
|
|
121
|
-
errors: [{messageId}],
|
|
122
|
-
filename,
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
name: `${component} with string element 'as' prop`,
|
|
126
|
-
code: `${prcImport}${jsx(`<${component} as="code">Hello world</${component}>`)}`,
|
|
127
|
-
// There is extra whitespace here we don't worry about since formatters would get rid of it
|
|
128
|
-
output: `${prcImport}${jsx(`<code >Hello world</code>`)}`,
|
|
129
|
-
errors: [{messageId}],
|
|
130
|
-
filename,
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
name: `${component} with single-character 'as' prop`,
|
|
134
|
-
code: `${prcImport}${jsx(`<${component} as="p">Hello world</${component}>`)}`,
|
|
135
|
-
output: `${prcImport}${jsx(`<p >Hello world</p>`)}`,
|
|
136
|
-
errors: [{messageId}],
|
|
137
|
-
filename,
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
name: `${component} with string element 'as' prop surrounded by unnecessary braces`,
|
|
141
|
-
code: `${prcImport}${jsx(`<${component} as={"code"}>Hello world</${component}>`)}`,
|
|
142
|
-
output: `${prcImport}${jsx(`<code >Hello world</code>`)}`,
|
|
143
|
-
errors: [{messageId}],
|
|
144
|
-
filename,
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
name: `${component} with component reference 'as' prop`,
|
|
148
|
-
code: `${prcImport}${componentDeclaration}${jsx(`<${component} as={OtherComponent}>Hello world</${component}>`)}`,
|
|
149
|
-
output: `${prcImport}${componentDeclaration}${jsx(`<OtherComponent >Hello world</OtherComponent>`)}`,
|
|
150
|
-
errors: [{messageId}],
|
|
151
|
-
filename,
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
name: `${component} with spread 'as' prop`,
|
|
155
|
-
code: `${prcImport}${asObjectDeclaration}${jsx(`<${component} {...props}>Hello world</${component}>`)}`,
|
|
156
|
-
output: null,
|
|
157
|
-
errors: [{messageId}],
|
|
158
|
-
filename,
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
name: `${component} with unusable lowercase reference 'as' prop`,
|
|
162
|
-
code: `${prcImport}${asConstDeclaration}${jsx(`<${component} as={as}>Hello world</${component}>`)}`,
|
|
163
|
-
output: null,
|
|
164
|
-
errors: [{messageId}],
|
|
165
|
-
filename,
|
|
166
|
-
},
|
|
167
|
-
{
|
|
168
|
-
name: `Non-PRC ${component} when \`skipImportCheck\` is enabled`,
|
|
169
|
-
code: `${brandImport}${jsx(`<${component}>Hello World</${component}>`)}`,
|
|
170
|
-
output: `${brandImport}${jsx(`<${replacement}>Hello World</${replacement}>`)}`,
|
|
171
|
-
filename,
|
|
172
|
-
errors: [{messageId}],
|
|
173
|
-
options: [{skipImportCheck: true}],
|
|
174
|
-
},
|
|
175
|
-
{
|
|
176
|
-
name: `${component} from @primer/styled-react without any styled-system props`,
|
|
177
|
-
code: `${styledReactImport}${jsx(`<${component}>Hello World</${component}>`)}`,
|
|
178
|
-
output: `${styledReactImport}${jsx(`<${replacement}>Hello World</${replacement}>`)}`,
|
|
179
|
-
errors: [{messageId}],
|
|
180
|
-
filename,
|
|
181
|
-
},
|
|
182
|
-
{
|
|
183
|
-
name: `Self-closing ${component} from @primer/styled-react without any styled-system props`,
|
|
184
|
-
code: `${styledReactImport}${jsx(`<${component} />`)}`,
|
|
185
|
-
output: `${styledReactImport}${jsx(`<${replacement} />`)}`,
|
|
186
|
-
errors: [{messageId}],
|
|
187
|
-
filename,
|
|
188
|
-
},
|
|
189
|
-
{
|
|
190
|
-
name: `${component} from @primer/styled-react with spread props without sx`,
|
|
191
|
-
code: `${styledReactImport}${testIdObjectDeclaration}${jsx(`<${component} {...props}>Hello World</${component}>`)}`,
|
|
192
|
-
output: `${styledReactImport}${testIdObjectDeclaration}${jsx(`<${replacement} {...props}>Hello World</${replacement}>`)}`,
|
|
193
|
-
errors: [{messageId}],
|
|
194
|
-
filename,
|
|
195
|
-
},
|
|
196
|
-
{
|
|
197
|
-
name: `${component} from @primer/styled-react with string element 'as' prop`,
|
|
198
|
-
code: `${styledReactImport}${jsx(`<${component} as="code">Hello world</${component}>`)}`,
|
|
199
|
-
// There is extra whitespace here we don't worry about since formatters would get rid of it
|
|
200
|
-
output: `${styledReactImport}${jsx(`<code >Hello world</code>`)}`,
|
|
201
|
-
errors: [{messageId}],
|
|
202
|
-
filename,
|
|
203
|
-
},
|
|
204
|
-
{
|
|
205
|
-
name: `${component} from @primer/styled-react with single-character 'as' prop`,
|
|
206
|
-
code: `${styledReactImport}${jsx(`<${component} as="p">Hello world</${component}>`)}`,
|
|
207
|
-
output: `${styledReactImport}${jsx(`<p >Hello world</p>`)}`,
|
|
208
|
-
errors: [{messageId}],
|
|
209
|
-
filename,
|
|
210
|
-
},
|
|
211
|
-
{
|
|
212
|
-
name: `${component} from @primer/styled-react with string element 'as' prop surrounded by unnecessary braces`,
|
|
213
|
-
code: `${styledReactImport}${jsx(`<${component} as={"code"}>Hello world</${component}>`)}`,
|
|
214
|
-
output: `${styledReactImport}${jsx(`<code >Hello world</code>`)}`,
|
|
215
|
-
errors: [{messageId}],
|
|
216
|
-
filename,
|
|
217
|
-
},
|
|
218
|
-
{
|
|
219
|
-
name: `${component} from @primer/styled-react with component reference 'as' prop`,
|
|
220
|
-
code: `${styledReactImport}${componentDeclaration}${jsx(`<${component} as={OtherComponent}>Hello world</${component}>`)}`,
|
|
221
|
-
output: `${styledReactImport}${componentDeclaration}${jsx(`<OtherComponent >Hello world</OtherComponent>`)}`,
|
|
222
|
-
errors: [{messageId}],
|
|
223
|
-
filename,
|
|
224
|
-
},
|
|
225
|
-
{
|
|
226
|
-
name: `${component} from @primer/styled-react with spread 'as' prop`,
|
|
227
|
-
code: `${styledReactImport}${asObjectDeclaration}${jsx(`<${component} {...props}>Hello world</${component}>`)}`,
|
|
228
|
-
output: null,
|
|
229
|
-
errors: [{messageId}],
|
|
230
|
-
filename,
|
|
231
|
-
},
|
|
232
|
-
{
|
|
233
|
-
name: `${component} from @primer/styled-react with unusable lowercase reference 'as' prop`,
|
|
234
|
-
code: `${styledReactImport}${asConstDeclaration}${jsx(`<${component} as={as}>Hello world</${component}>`)}`,
|
|
235
|
-
output: null,
|
|
236
|
-
errors: [{messageId}],
|
|
237
|
-
filename,
|
|
238
|
-
},
|
|
239
|
-
]),
|
|
240
|
-
})
|