eslint-plugin-primer-react 5.4.0 → 6.0.0-rc.0df8090
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 +10 -0
- package/docs/rules/no-unnecessary-components.md +69 -0
- package/docs/rules/use-deprecated-from-deprecated.md +25 -0
- package/jest.config.js +7 -0
- package/package-lock.json +14680 -0
- package/package.json +7 -3
- package/src/configs/recommended.js +1 -0
- package/src/index.js +2 -0
- package/src/rules/__tests__/fixtures/File.tsx +1 -0
- package/src/rules/__tests__/fixtures/file.ts +1 -0
- package/src/rules/__tests__/fixtures/tsconfig.json +7 -0
- package/src/rules/__tests__/no-unnecessary-components.test.js +153 -0
- package/src/rules/__tests__/use-deprecated-from-deprecated.test.js +66 -0
- package/src/rules/no-unnecessary-components.js +160 -0
- package/src/rules/use-deprecated-from-deprecated.js +130 -0
- package/src/utils/is-primer-component.js +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# eslint-plugin-primer-react
|
|
2
2
|
|
|
3
|
+
## 6.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [#207](https://github.com/primer/eslint-plugin-primer-react/pull/207) [`baff792`](https://github.com/primer/eslint-plugin-primer-react/commit/baff792c0aa01a29374e44e8aa770dbe2cb889a1) Thanks [@iansan5653](https://github.com/iansan5653)! - [Breaking] Adds `no-unnecessary-components` lint rule and enables it by default. This may raise new (typically autofixable) lint errors in existing codebases.
|
|
8
|
+
|
|
9
|
+
### Minor Changes
|
|
10
|
+
|
|
11
|
+
- [#204](https://github.com/primer/eslint-plugin-primer-react/pull/204) [`e2cab87`](https://github.com/primer/eslint-plugin-primer-react/commit/e2cab872c265f4211750436fad32fe5fd8927c5c) Thanks [@joshblack](https://github.com/joshblack)! - Add use-deprecated-from-deprecated rule
|
|
12
|
+
|
|
3
13
|
## 5.4.0
|
|
4
14
|
|
|
5
15
|
### Minor Changes
|
|
@@ -0,0 +1,69 @@
|
|
|
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`.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Use Deprecated from Deprecated
|
|
2
|
+
|
|
3
|
+
## Rule Details
|
|
4
|
+
|
|
5
|
+
This rule enforces the usage of deprecated imports from `@primer/react/deprecated`.
|
|
6
|
+
|
|
7
|
+
👎 Examples of **incorrect** code for this rule
|
|
8
|
+
|
|
9
|
+
```jsx
|
|
10
|
+
import {Dialog} from '@primer/react'
|
|
11
|
+
|
|
12
|
+
function ExampleComponent() {
|
|
13
|
+
return <Dialog>{/* ... */}</Dialog>
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
👍 Examples of **correct** code for this rule:
|
|
18
|
+
|
|
19
|
+
```jsx
|
|
20
|
+
import {Dialog} from '@primer/react/deprecated'
|
|
21
|
+
|
|
22
|
+
function ExampleComponent() {
|
|
23
|
+
return <Dialog>{/* ... */}</Dialog>
|
|
24
|
+
}
|
|
25
|
+
```
|