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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# eslint-plugin-primer-react
|
|
2
2
|
|
|
3
|
+
## 9.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [#577](https://github.com/primer/eslint-plugin-primer-react/pull/577) [`f0c6656`](https://github.com/primer/eslint-plugin-primer-react/commit/f0c66568b76a3acc9c03c29ce1530026b6878903) Thanks [@francinelucca](https://github.com/francinelucca)! - - BREAKING CHANGE: Deleted the `no-system-props` rule to eliminate checks for styled-system props in components.
|
|
8
|
+
- BREAKING CHANGE: Removed the `no-unnecessary-components` rule that enforced the use of plain HTML elements over `Box` and `Text` when not using `sx` for styling.
|
|
9
|
+
- BREAKING CHANGE: Eliminated the `use-styled-react-import` rule that enforced importing components from `@primer/styled-react` when using the `sx` prop.
|
|
10
|
+
- Removed styled-system, @types/styled-system dependencies
|
|
11
|
+
|
|
3
12
|
## 8.6.1
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -46,11 +46,9 @@ ESLint rules for Primer React
|
|
|
46
46
|
- [no-deprecated-entrypoints](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/no-deprecated-entrypoints.md)
|
|
47
47
|
- [no-deprecated-experimental-components](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/no-deprecated-experimental-components.md)
|
|
48
48
|
- [no-deprecated-props](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/no-deprecated-props.md)
|
|
49
|
-
|
|
50
|
-
- [no-unnecessary-components](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/no-unnecessary-components.md)
|
|
49
|
+
|
|
51
50
|
- [no-use-responsive-value](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/no-use-responsive-value.md)
|
|
52
51
|
- [no-wildcard-imports](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/no-wildcard-imports.md)
|
|
53
52
|
- [prefer-action-list-item-onselect](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/prefer-action-list-item-onselect.md)
|
|
54
53
|
- [spread-props-first](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/spread-props-first.md)
|
|
55
54
|
- [use-deprecated-from-deprecated](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/use-deprecated-from-deprecated.md)
|
|
56
|
-
- [use-styled-react-import](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/use-styled-react-import.md)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-primer-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0-rc.e1d461c",
|
|
4
4
|
"description": "ESLint rules for Primer React",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"engines": {
|
|
@@ -31,19 +31,17 @@
|
|
|
31
31
|
"eslint": "^9.0.0"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@styled-system/props": "^5.1.5",
|
|
35
34
|
"@typescript-eslint/utils": "^8.50.0",
|
|
36
35
|
"eslint-plugin-github": "^6.0.0",
|
|
37
36
|
"eslint-plugin-jsx-a11y": "^6.7.1",
|
|
38
37
|
"eslint-traverse": "^1.0.0",
|
|
39
38
|
"lodash": "^4.17.21",
|
|
40
|
-
"styled-system": "^5.1.5",
|
|
41
39
|
"typescript": "^6.0.3"
|
|
42
40
|
},
|
|
43
41
|
"devDependencies": {
|
|
44
42
|
"@changesets/changelog-github": "^0.7.0",
|
|
45
43
|
"@changesets/cli": "^2.27.9",
|
|
46
|
-
"@github/markdownlint-github": "^0.
|
|
44
|
+
"@github/markdownlint-github": "^0.8.1",
|
|
47
45
|
"@github/prettier-config": "0.0.6",
|
|
48
46
|
"@types/jest": "^30.0.0",
|
|
49
47
|
"@types/node": "^25.0.2",
|
|
@@ -11,7 +11,7 @@ module.exports = {
|
|
|
11
11
|
extends: ['plugin:github/react'],
|
|
12
12
|
rules: {
|
|
13
13
|
'primer-react/direct-slot-children': 'error',
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
'primer-react/no-deprecated-experimental-components': 'warn',
|
|
16
16
|
'primer-react/a11y-tooltip-interactive-trigger': 'error',
|
|
17
17
|
'primer-react/new-color-css-vars': 'error',
|
|
@@ -21,7 +21,7 @@ module.exports = {
|
|
|
21
21
|
'primer-react/no-deprecated-props': 'warn',
|
|
22
22
|
'primer-react/a11y-remove-disable-tooltip': 'error',
|
|
23
23
|
'primer-react/a11y-use-accessible-tooltip': 'error',
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
'primer-react/prefer-action-list-item-onselect': 'error',
|
|
26
26
|
'primer-react/no-use-responsive-value': 'error',
|
|
27
27
|
},
|
package/src/index.js
CHANGED
|
@@ -15,14 +15,12 @@ module.exports = {
|
|
|
15
15
|
'no-deprecated-entrypoints': require('./rules/no-deprecated-entrypoints'),
|
|
16
16
|
'no-deprecated-experimental-components': require('./rules/no-deprecated-experimental-components'),
|
|
17
17
|
'no-deprecated-props': require('./rules/no-deprecated-props'),
|
|
18
|
-
|
|
19
|
-
'no-unnecessary-components': require('./rules/no-unnecessary-components'),
|
|
18
|
+
|
|
20
19
|
'no-use-responsive-value': require('./rules/no-use-responsive-value'),
|
|
21
20
|
'no-wildcard-imports': require('./rules/no-wildcard-imports'),
|
|
22
21
|
'prefer-action-list-item-onselect': require('./rules/prefer-action-list-item-onselect'),
|
|
23
22
|
'spread-props-first': require('./rules/spread-props-first'),
|
|
24
23
|
'use-deprecated-from-deprecated': require('./rules/use-deprecated-from-deprecated'),
|
|
25
|
-
'use-styled-react-import': require('./rules/use-styled-react-import'),
|
|
26
24
|
'no-deprecated-octicon': require('./rules/no-deprecated-octicon'),
|
|
27
25
|
},
|
|
28
26
|
configs: {
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
# Disallow use of styled-system props (no-system-props)
|
|
2
|
-
|
|
3
|
-
🔧 The `--fix` option on the [ESLint CLI](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can
|
|
4
|
-
automatically fix some of the problems reported by this rule.
|
|
5
|
-
|
|
6
|
-
[Styled-system](https://styled-system.com/table) props are deprecated in Primer components (excluding utility
|
|
7
|
-
components).
|
|
8
|
-
|
|
9
|
-
## Rule details
|
|
10
|
-
|
|
11
|
-
This rule disallows the use of any styled-system prop on Primer components, as the `sx` prop is now the prefered way to
|
|
12
|
-
apply additional styling.
|
|
13
|
-
|
|
14
|
-
\*The two non-deprecated utility components (`Box` and `Text`) are allowed to use system props.
|
|
15
|
-
|
|
16
|
-
👎 Examples of **incorrect** code for this rule:
|
|
17
|
-
|
|
18
|
-
```jsx
|
|
19
|
-
/* eslint primer-react/no-system-props: "error" */
|
|
20
|
-
import {Button} from '@primer/react'
|
|
21
|
-
|
|
22
|
-
<Button width={200} />
|
|
23
|
-
<Button width={200} sx={{height: 300}} />
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
👍 Examples of **correct** code for this rule:
|
|
27
|
-
|
|
28
|
-
```jsx
|
|
29
|
-
/* eslint primer-react/no-system-props: "error" */
|
|
30
|
-
import {Box, Button, ProgressBar} from '@primer/react'
|
|
31
|
-
import {Avatar} from 'some-other-library'
|
|
32
|
-
// Non-system props are allowed
|
|
33
|
-
<Button someOtherProp="foo" />
|
|
34
|
-
// If you need to override styles, use the `sx` prop instead of system props
|
|
35
|
-
<Button sx={{mr: 2}} />
|
|
36
|
-
// Some component prop names overlap with styled-system prop names.
|
|
37
|
-
// These props are still allowed
|
|
38
|
-
<ProgressBar bg="success.emphasis" />
|
|
39
|
-
// Utility components like Box and Text still accept system props
|
|
40
|
-
<Box mr={2} />
|
|
41
|
-
// System props passed to non-Primer components are allowed
|
|
42
|
-
<Avatar mr={2} />
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
## Options
|
|
46
|
-
|
|
47
|
-
- `skipImportCheck` (default: `false`)
|
|
48
|
-
|
|
49
|
-
By default, the `no-system-props` rule will only check for styled system props used in functions and components that
|
|
50
|
-
are imported from `@primer/react`. You can disable this behavior by setting `skipImportCheck` to `true`. This is
|
|
51
|
-
useful for linting custom components that pass styled system props down to Primer React components.
|
|
52
|
-
|
|
53
|
-
- `includeUtilityComponents` (default: `false`)
|
|
54
|
-
|
|
55
|
-
By default, `Box` and `Text` are excluded because styled system props are not deprecated in our utility components. If
|
|
56
|
-
you prefer to avoid styled system props there as well for consistency, you can set `includeUtilityComponents` to
|
|
57
|
-
`true`.
|
|
58
|
-
|
|
59
|
-
```js
|
|
60
|
-
/* eslint primer-react/no-system-props: ["warn", {"includeUtilityComponents": true}] */
|
|
61
|
-
import {Box} from '@primer/react'
|
|
62
|
-
|
|
63
|
-
function App() {
|
|
64
|
-
// Enabling `includeUtilityComponents` will find system prop usage on utility components like this:
|
|
65
|
-
return <Box width={200} />
|
|
66
|
-
}
|
|
67
|
-
```
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
# Disallow unnecessary use of `Box` and `Text` components (no-unnecessary-components)
|
|
2
|
-
|
|
3
|
-
🔧 The `--fix` option on the [ESLint CLI](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can
|
|
4
|
-
automatically fix some of the problems reported by this rule.
|
|
5
|
-
|
|
6
|
-
## Rule details
|
|
7
|
-
|
|
8
|
-
The [`Box`](https://primer.style/components/box) and [`Text`](https://primer.style/components/text)
|
|
9
|
-
Primer React components are utilities that exist solely to provide access to `sx` or styled-system
|
|
10
|
-
props.
|
|
11
|
-
|
|
12
|
-
If these props are not being used, plain HTML element provide better performance, simpler code,
|
|
13
|
-
and improved linting support.
|
|
14
|
-
|
|
15
|
-
This rule is auto-fixable in nearly all cases. Autofixing respects the presence of an `as` prop.
|
|
16
|
-
|
|
17
|
-
👎 Examples of **incorrect** code for this rule:
|
|
18
|
-
|
|
19
|
-
```jsx
|
|
20
|
-
/* eslint primer-react/no-unnecessary-components: "error" */
|
|
21
|
-
import {Box, Text} from '@primer/react'
|
|
22
|
-
|
|
23
|
-
<Box>Content</Box>
|
|
24
|
-
<Box style={{padding: '16px'}} className="danger-box">Content</Box>
|
|
25
|
-
<Box as="section">Content</Box>
|
|
26
|
-
|
|
27
|
-
<Text>Content</Text>
|
|
28
|
-
<Text style={{fontSize: '24px'}} className="large-text">Content</Text>
|
|
29
|
-
<Text as="p">Content</Text>
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
👍 Examples of **correct** code for this rule:
|
|
33
|
-
|
|
34
|
-
```jsx
|
|
35
|
-
/* eslint primer-react/no-system-props: "error" */
|
|
36
|
-
import {Box, Text} from '@primer/react'
|
|
37
|
-
|
|
38
|
-
// Prefer plain HTML elements (autofixable)
|
|
39
|
-
<div>Content</div>
|
|
40
|
-
<div style={{padding: '16px'}} className="danger-box">Content</div>
|
|
41
|
-
<section>Content</section>
|
|
42
|
-
|
|
43
|
-
<span>Content</span>
|
|
44
|
-
<span style={{fontSize: '24px'}} className="large-text">Content</span>
|
|
45
|
-
<p>Content</p>
|
|
46
|
-
|
|
47
|
-
// sx props are allowed
|
|
48
|
-
<Box sx={{p: 2}}>Content</Box>
|
|
49
|
-
<Text sx={{mt: 2}} as="p">Content</Text>
|
|
50
|
-
|
|
51
|
-
// styled-system props are allowed
|
|
52
|
-
<Box p={2}>Content</Box>
|
|
53
|
-
<Text mt={2} as="p">Content</Text>
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
```jsx
|
|
57
|
-
/* eslint primer-react/no-system-props: ["error", {skipImportCheck: false}] */
|
|
58
|
-
import {Box, Text} from '@primer/brand'
|
|
59
|
-
|
|
60
|
-
// Other components with the same name are allowed
|
|
61
|
-
<Box>Content</Box>
|
|
62
|
-
<Text>Content</Text>
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
## Options
|
|
66
|
-
|
|
67
|
-
- `skipImportCheck` (default: `false`)
|
|
68
|
-
|
|
69
|
-
By default, the rule will only check for incorrect uses of `Box` and `Text` components that are are imported from `@primer/react`. You can disable this behavior (checking all components with these names regardless of import source) by setting `skipImportCheck` to `true`.
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
# use-styled-react-import
|
|
2
|
-
|
|
3
|
-
💼 This rule is _disabled_ in the ✅ `recommended` config.
|
|
4
|
-
|
|
5
|
-
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
|
|
6
|
-
|
|
7
|
-
<!-- end auto-generated rule header -->
|
|
8
|
-
|
|
9
|
-
Enforce importing components that use `sx` prop from `@primer/styled-react` instead of `@primer/react`, and vice versa.
|
|
10
|
-
|
|
11
|
-
## Rule Details
|
|
12
|
-
|
|
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
|
-
|
|
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
|
-
|
|
17
|
-
It also moves certain types and utilities to the styled-react package.
|
|
18
|
-
|
|
19
|
-
### Components that should be imported from `@primer/styled-react` when used with `sx`:
|
|
20
|
-
|
|
21
|
-
- ActionList
|
|
22
|
-
- ActionMenu
|
|
23
|
-
- Box
|
|
24
|
-
- Breadcrumbs
|
|
25
|
-
- Button
|
|
26
|
-
- Flash
|
|
27
|
-
- FormControl
|
|
28
|
-
- Heading
|
|
29
|
-
- IconButton
|
|
30
|
-
- Label
|
|
31
|
-
- Link
|
|
32
|
-
- LinkButton
|
|
33
|
-
- PageLayout
|
|
34
|
-
- Text
|
|
35
|
-
- TextInput
|
|
36
|
-
- Truncate
|
|
37
|
-
- Octicon
|
|
38
|
-
- Dialog
|
|
39
|
-
|
|
40
|
-
### Types and utilities that should always be imported from `@primer/styled-react`:
|
|
41
|
-
|
|
42
|
-
- `BoxProps` (type)
|
|
43
|
-
- `SxProp` (type)
|
|
44
|
-
- `BetterSystemStyleObject` (type)
|
|
45
|
-
- `sx` (utility)
|
|
46
|
-
|
|
47
|
-
## Examples
|
|
48
|
-
|
|
49
|
-
### ❌ Incorrect
|
|
50
|
-
|
|
51
|
-
```jsx
|
|
52
|
-
import {Button, Link} from '@primer/react'
|
|
53
|
-
|
|
54
|
-
const Component = () => <Button sx={{color: 'red'}}>Click me</Button>
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
```jsx
|
|
58
|
-
import {Box} from '@primer/react'
|
|
59
|
-
|
|
60
|
-
const Component = () => <Box sx={{padding: 2}}>Content</Box>
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
```jsx
|
|
64
|
-
import {sx} from '@primer/react'
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
```jsx
|
|
68
|
-
import {Button} from '@primer/styled-react'
|
|
69
|
-
|
|
70
|
-
const Component = () => <Button>Click me</Button>
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
```jsx
|
|
74
|
-
import {Button} from '@primer/react'
|
|
75
|
-
|
|
76
|
-
const Component1 = () => <Button>Click me</Button>
|
|
77
|
-
const Component2 = () => <Button sx={{color: 'red'}}>Styled me</Button>
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
### ✅ Correct
|
|
81
|
-
|
|
82
|
-
```jsx
|
|
83
|
-
import {Link} from '@primer/react'
|
|
84
|
-
import {Button} from '@primer/styled-react'
|
|
85
|
-
|
|
86
|
-
const Component = () => <Button sx={{color: 'red'}}>Click me</Button>
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
```jsx
|
|
90
|
-
import {Box} from '@primer/styled-react'
|
|
91
|
-
|
|
92
|
-
const Component = () => <Box sx={{padding: 2}}>Content</Box>
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
```jsx
|
|
96
|
-
import {sx} from '@primer/styled-react'
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
```jsx
|
|
100
|
-
// Components without sx prop can stay in @primer/react
|
|
101
|
-
import {Button} from '@primer/react'
|
|
102
|
-
|
|
103
|
-
const Component = () => <Button>Click me</Button>
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
```jsx
|
|
107
|
-
// Components imported from styled-react but used without sx prop should be moved back
|
|
108
|
-
import {Button} from '@primer/react'
|
|
109
|
-
|
|
110
|
-
const Component = () => <Button>Click me</Button>
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
```jsx
|
|
114
|
-
// When a component is used with sx prop anywhere, import from styled-react
|
|
115
|
-
import {Button} from '@primer/styled-react'
|
|
116
|
-
|
|
117
|
-
const Component1 = () => <Button>Click me</Button>
|
|
118
|
-
const Component2 = () => <Button sx={{color: 'red'}}>Styled me</Button>
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
## Options
|
|
122
|
-
|
|
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
|
-
```
|
|
172
|
-
|
|
173
|
-
## When Not To Use It
|
|
174
|
-
|
|
175
|
-
This rule is specifically for migrating components that use the `sx` prop to the temporary `@primer/styled-react` package. If you're not using the `sx` prop or not participating in this migration, you can disable this rule.
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
const rule = require('../no-system-props')
|
|
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('no-system-props', rule, {
|
|
17
|
-
valid: [
|
|
18
|
-
`import {Button} from '@primer/react'; <Button sx={{width: 200}} />`,
|
|
19
|
-
`import {Button} from 'coles-cool-design-system'; <Button width={200} />`,
|
|
20
|
-
`import {Button} from '@primer/react'; <Button someOtherProp="foo" />`,
|
|
21
|
-
`import {Box} from '@primer/react'; <Box width={200} />`,
|
|
22
|
-
`import {ProgressBar} from '@primer/react'; <ProgressBar bg="howdy" />`,
|
|
23
|
-
`import {Button} from '@primer/react'; <Button {...someExpression()} />`,
|
|
24
|
-
`import {Button} from '@primer/react'; <Button variant="large" />`,
|
|
25
|
-
`import {Button} from '@primer/react'; <Button size="large" />`,
|
|
26
|
-
`import {ActionMenu} from '@primer/react'; <ActionMenu.Overlay width="large" />`,
|
|
27
|
-
`import {Breadcrumbs} from '@primer/react'; <Breadcrumbs overflow="auto" />`,
|
|
28
|
-
{code: `<img width="200px" />`, options: [{skipImportCheck: true}]},
|
|
29
|
-
{code: `<Placeholder width="200px" />`, options: [{skipImportCheck: true, ignoreNames: ['Placeholder']}]},
|
|
30
|
-
{
|
|
31
|
-
code: `<Placeholder.Header width="200px" />`,
|
|
32
|
-
options: [{skipImportCheck: true, ignoreNames: ['Placeholder.Header']}],
|
|
33
|
-
},
|
|
34
|
-
],
|
|
35
|
-
invalid: [
|
|
36
|
-
{
|
|
37
|
-
code: `import {Button} from '@primer/react'; <Button width={200} />`,
|
|
38
|
-
output: `import {Button} from '@primer/react'; <Button sx={{width: 200}} />`,
|
|
39
|
-
errors: [
|
|
40
|
-
{
|
|
41
|
-
messageId: 'noSystemProps',
|
|
42
|
-
data: {propNames: 'width', componentName: 'Button'},
|
|
43
|
-
},
|
|
44
|
-
],
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
code: `import {Button} from '@primer/react'; <Button width="200" />`,
|
|
48
|
-
output: `import {Button} from '@primer/react'; <Button sx={{width: "200"}} />`,
|
|
49
|
-
errors: [
|
|
50
|
-
{
|
|
51
|
-
messageId: 'noSystemProps',
|
|
52
|
-
data: {propNames: 'width', componentName: 'Button'},
|
|
53
|
-
},
|
|
54
|
-
],
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
code: `import {Button} from '@primer/react'; <Button width={"200"} />`,
|
|
58
|
-
output: `import {Button} from '@primer/react'; <Button sx={{width: "200"}} />`,
|
|
59
|
-
errors: [
|
|
60
|
-
{
|
|
61
|
-
messageId: 'noSystemProps',
|
|
62
|
-
data: {propNames: 'width', componentName: 'Button'},
|
|
63
|
-
},
|
|
64
|
-
],
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
code: `import {Button} from '@primer/react'; <Button width={myWidth} />`,
|
|
68
|
-
output: `import {Button} from '@primer/react'; <Button sx={{width: myWidth}} />`,
|
|
69
|
-
errors: [
|
|
70
|
-
{
|
|
71
|
-
messageId: 'noSystemProps',
|
|
72
|
-
data: {propNames: 'width', componentName: 'Button'},
|
|
73
|
-
},
|
|
74
|
-
],
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
code: `import {Button} from '@primer/react'; <Button width={200} height={100} />`,
|
|
78
|
-
output: `import {Button} from '@primer/react'; <Button sx={{width: 200, height: 100}} />`,
|
|
79
|
-
errors: [
|
|
80
|
-
{
|
|
81
|
-
messageId: 'noSystemProps',
|
|
82
|
-
data: {propNames: 'width, height', componentName: 'Button'},
|
|
83
|
-
},
|
|
84
|
-
],
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
code: `import {Button} from '@primer/react'; <Button width={200} sx={{height: 200}} />`,
|
|
88
|
-
output: `import {Button} from '@primer/react'; <Button sx={{height: 200, width: 200}} />`,
|
|
89
|
-
errors: [
|
|
90
|
-
{
|
|
91
|
-
messageId: 'noSystemProps',
|
|
92
|
-
data: {propNames: 'width', componentName: 'Button'},
|
|
93
|
-
},
|
|
94
|
-
],
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
code: `import {Button} from '@primer/react'; <Button width={200} sx={{width: 300}} />`,
|
|
98
|
-
output: `import {Button} from '@primer/react'; <Button sx={{width: 300}} />`,
|
|
99
|
-
errors: [
|
|
100
|
-
{
|
|
101
|
-
messageId: 'noSystemProps',
|
|
102
|
-
data: {propNames: 'width', componentName: 'Button'},
|
|
103
|
-
},
|
|
104
|
-
],
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
code: `import {Button} from '@primer/react'; <Button width={200} sx={myStylez} />`,
|
|
108
|
-
errors: [
|
|
109
|
-
{
|
|
110
|
-
messageId: 'noSystemProps',
|
|
111
|
-
data: {propNames: 'width', componentName: 'Button'},
|
|
112
|
-
},
|
|
113
|
-
],
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
code: `import {Button} from '@primer/react'; <Button width={200} sx={{...partialStyles, width: 100}} />`,
|
|
117
|
-
output: `import {Button} from '@primer/react'; <Button sx={{...partialStyles, width: 100}} />`,
|
|
118
|
-
errors: [
|
|
119
|
-
{
|
|
120
|
-
messageId: 'noSystemProps',
|
|
121
|
-
data: {propNames: 'width', componentName: 'Button'},
|
|
122
|
-
},
|
|
123
|
-
],
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
code: `import {Label} from '@primer/react'; <Label width={200} outline />`,
|
|
127
|
-
output: `import {Label} from '@primer/react'; <Label outline sx={{width: 200}} />`,
|
|
128
|
-
errors: [
|
|
129
|
-
{
|
|
130
|
-
messageId: 'noSystemProps',
|
|
131
|
-
data: {propNames: 'width', componentName: 'Label'},
|
|
132
|
-
},
|
|
133
|
-
],
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
code: `import {Box} from '@primer/react'; <Box width={200} />`,
|
|
137
|
-
output: `import {Box} from '@primer/react'; <Box sx={{width: 200}} />`,
|
|
138
|
-
options: [{includeUtilityComponents: true}],
|
|
139
|
-
errors: [
|
|
140
|
-
{
|
|
141
|
-
messageId: 'noSystemProps',
|
|
142
|
-
data: {propNames: 'width', componentName: 'Box'},
|
|
143
|
-
},
|
|
144
|
-
],
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
code: `import {Text} from '@primer/react'; <Text width={200} />`,
|
|
148
|
-
output: `import {Text} from '@primer/react'; <Text sx={{width: 200}} />`,
|
|
149
|
-
options: [{includeUtilityComponents: true}],
|
|
150
|
-
errors: [
|
|
151
|
-
{
|
|
152
|
-
messageId: 'noSystemProps',
|
|
153
|
-
data: {propNames: 'width', componentName: 'Text'},
|
|
154
|
-
},
|
|
155
|
-
],
|
|
156
|
-
},
|
|
157
|
-
{
|
|
158
|
-
code: `import {Button} from '../Button'; <Button width={200} />`,
|
|
159
|
-
options: [{skipImportCheck: true}],
|
|
160
|
-
output: `import {Button} from '../Button'; <Button sx={{width: 200}} />`,
|
|
161
|
-
errors: [
|
|
162
|
-
{
|
|
163
|
-
messageId: 'noSystemProps',
|
|
164
|
-
data: {propNames: 'width', componentName: 'Button'},
|
|
165
|
-
},
|
|
166
|
-
],
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
code: `import {Foo} from '../Foo'; <Foo width={200} />`,
|
|
170
|
-
options: [{skipImportCheck: true}],
|
|
171
|
-
output: `import {Foo} from '../Foo'; <Foo sx={{width: 200}} />`,
|
|
172
|
-
errors: [
|
|
173
|
-
{
|
|
174
|
-
messageId: 'noSystemProps',
|
|
175
|
-
data: {propNames: 'width', componentName: 'Foo'},
|
|
176
|
-
},
|
|
177
|
-
],
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
code: `import {Button} from '@primer/react'; <Button.Counter width={200} />`,
|
|
181
|
-
output: `import {Button} from '@primer/react'; <Button.Counter sx={{width: 200}} />`,
|
|
182
|
-
errors: [
|
|
183
|
-
{
|
|
184
|
-
messageId: 'noSystemProps',
|
|
185
|
-
data: {propNames: 'width', componentName: 'Button.Counter'},
|
|
186
|
-
},
|
|
187
|
-
],
|
|
188
|
-
},
|
|
189
|
-
],
|
|
190
|
-
})
|