eslint-plugin-primer-react 4.0.3 → 4.0.4-rc.5058fcb
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/.changeset/README.md +3 -3
- package/.eslintrc.js +39 -0
- package/.github/dependabot.yml +11 -5
- package/.github/workflows/add-to-inbox.yml +33 -0
- package/.github/workflows/ci.yml +34 -18
- package/.github/workflows/release.yml +2 -2
- package/.github/workflows/release_canary.yml +8 -5
- package/.github/workflows/release_candidate.yml +4 -4
- package/.markdownlint-cli2.cjs +26 -0
- package/.nvmrc +1 -0
- package/.prettierignore +3 -0
- package/CHANGELOG.md +7 -1
- package/README.md +4 -2
- package/docs/rules/a11y-explicit-heading.md +17 -7
- package/docs/rules/a11y-tooltip-interactive-trigger.md +6 -2
- package/docs/rules/direct-slot-children.md +49 -46
- package/docs/rules/new-color-css-vars-have-fallback.md +25 -0
- package/docs/rules/new-css-color-vars.md +19 -14
- package/docs/rules/no-deprecated-colors.md +91 -82
- package/docs/rules/no-system-props.md +12 -5
- package/package-lock.json +15583 -0
- package/package.json +22 -14
- package/src/configs/components.js +19 -19
- package/src/configs/recommended.js +9 -8
- package/src/index.js +4 -3
- package/src/rules/__tests__/a11y-explicit-heading.test.js +22 -25
- package/src/rules/__tests__/a11y-tooltip-interactive-trigger.test.js +43 -43
- package/src/rules/__tests__/direct-slot-children.test.js +36 -36
- package/src/rules/__tests__/new-color-css-vars.test.js +612 -44
- package/src/rules/__tests__/new-css-vars-have-fallback.test.js +31 -0
- package/src/rules/__tests__/no-deprecated-colors.test.js +66 -66
- package/src/rules/__tests__/no-system-props.test.js +51 -51
- package/src/rules/a11y-explicit-heading.js +16 -13
- package/src/rules/a11y-tooltip-interactive-trigger.js +21 -22
- package/src/rules/direct-slot-children.js +11 -11
- package/src/rules/new-color-css-vars-have-fallback.js +87 -0
- package/src/rules/new-color-css-vars.js +97 -83
- package/src/rules/no-deprecated-colors.js +15 -15
- package/src/rules/no-system-props.js +21 -21
- package/src/url.js +1 -1
- package/src/utils/__tests__/flatten-components.test.js +13 -13
- package/src/utils/css-variable-map.json +538 -184
- package/src/utils/flatten-components.js +11 -11
- package/src/utils/is-imported-from.js +1 -1
- package/src/utils/new-color-css-vars-map.json +326 -0
- /package/.github/{workflows/CODEOWNERS → CODEOWNERS} +0 -0
|
@@ -1,82 +1,91 @@
|
|
|
1
|
-
# Disallow references to deprecated color variables (no-deprecated-colors)
|
|
2
|
-
|
|
3
|
-
🔧 The `--fix` option on the [ESLint CLI](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
1
|
+
# Disallow references to deprecated color variables (no-deprecated-colors)
|
|
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
|
+
[Theming](https://primer.style/react/theming) in Primer React is made possible by a theme object that defines your
|
|
7
|
+
application's colors, spacing, fonts, and more. The color variables in Primer React's
|
|
8
|
+
[default theme object](https://primer.style/react/theme-reference) are pulled from
|
|
9
|
+
[Primer Primitives](https://github.com/primer/primitives). When a color variable is deprecated in Primer Primitives,
|
|
10
|
+
it's important to remove references to that color variable in your application before it's removed from the library.
|
|
11
|
+
|
|
12
|
+
## Rule details
|
|
13
|
+
|
|
14
|
+
This rule disallows references to color variables that are deprecated in
|
|
15
|
+
[Primer Primitives](https://github.com/primer/primitives).
|
|
16
|
+
|
|
17
|
+
👎 Examples of **incorrect** code for this rule:
|
|
18
|
+
|
|
19
|
+
```jsx
|
|
20
|
+
/* eslint primer-react/no-deprecated-colors: "error" */
|
|
21
|
+
import {Box, themeGet} from '@primer/react'
|
|
22
|
+
import styled from 'styled-components'
|
|
23
|
+
|
|
24
|
+
const SystemPropExample() = () => <Box color="some.deprecated.color">Incorrect</Box>
|
|
25
|
+
|
|
26
|
+
const SxPropExample() = () => <Box sx={{color: 'some.deprecated.color'}}>Incorrect</Box>
|
|
27
|
+
|
|
28
|
+
const SxPropExample2() = () => <Box sx={{boxShadow: theme => `0 1px 2px ${theme.colors.some.deprecated.color}`}}>Incorrect</Box>
|
|
29
|
+
|
|
30
|
+
const ThemeGetExample = styled.div`
|
|
31
|
+
color: ${themeGet('colors.some.deprecated.color')};
|
|
32
|
+
`
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
👍 Examples of **correct** code for this rule:
|
|
36
|
+
|
|
37
|
+
```jsx
|
|
38
|
+
/* eslint primer-react/no-deprecated-colors: "error" */
|
|
39
|
+
import {Box, themeGet} from '@primer/react'
|
|
40
|
+
import styled from 'styled-components'
|
|
41
|
+
|
|
42
|
+
const SystemPropExample() = () => <Box color="some.color">Correct</Box>
|
|
43
|
+
|
|
44
|
+
const SxPropExample() = () => <Box sx={{color: 'some.color'}}>Correct</Box>
|
|
45
|
+
|
|
46
|
+
const SxPropExample2() = () => <Box sx={{boxShadow: theme => `0 1px 2px ${theme.colors.some.color}`}}>Correct</Box>
|
|
47
|
+
|
|
48
|
+
const ThemeGetExample = styled.div`
|
|
49
|
+
color: ${themeGet('colors.some.color')};
|
|
50
|
+
`
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Options
|
|
54
|
+
|
|
55
|
+
- `skipImportCheck` (default: `false`)
|
|
56
|
+
|
|
57
|
+
By default, the `no-deprecated-colors` rule will only check for deprecated colors used in functions and components
|
|
58
|
+
that are imported from `@primer/react`. You can disable this behavior by setting `skipImportCheck` to `true`. This is
|
|
59
|
+
useful for linting custom components that pass color-related props down to Primer React components.
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
/* eslint primer-react/no-deprecated-colors: ["warn", {"skipImportCheck": true}] */
|
|
63
|
+
import {Box} from '@primer/react'
|
|
64
|
+
|
|
65
|
+
function MyBox({color, children}) {
|
|
66
|
+
return <Box color={color}>{children}</Box>
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function App() {
|
|
70
|
+
// Enabling `skipImportCheck` will find deprecated colors used like this:
|
|
71
|
+
return <MyBox color="text.primary">Hello</MyBox>
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
- `checkAllStrings` (default: `false`)
|
|
76
|
+
|
|
77
|
+
If `checkAllStrings` is set to `true`, the `no-deprecated-colors` rule will check for deprecated colors in all
|
|
78
|
+
strings. This is useful for catching uses of deprecated colors outside system props and the `sx` prop.
|
|
79
|
+
|
|
80
|
+
```js
|
|
81
|
+
/* eslint primer-react/no-deprecated-colors: ["warn", {"checkAllStrings": true}] */
|
|
82
|
+
import {Box} from '@primer/react'
|
|
83
|
+
|
|
84
|
+
function ExampleComponent() {
|
|
85
|
+
const styles = {
|
|
86
|
+
// Enabling `checkAllStrings` will find deprecated colors used like this:
|
|
87
|
+
color: 'text.primary',
|
|
88
|
+
}
|
|
89
|
+
return <Box sx={styles}>Hello</Box>
|
|
90
|
+
}
|
|
91
|
+
```
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
# Disallow use of styled-system props (no-system-props)
|
|
2
2
|
|
|
3
|
-
🔧 The `--fix` option on the [ESLint CLI](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can
|
|
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.
|
|
4
5
|
|
|
5
|
-
[Styled-system](https://styled-system.com/table) props are deprecated in Primer components (excluding utility
|
|
6
|
+
[Styled-system](https://styled-system.com/table) props are deprecated in Primer components (excluding utility
|
|
7
|
+
components).
|
|
6
8
|
|
|
7
9
|
## Rule details
|
|
8
10
|
|
|
9
|
-
This rule disallows the use of any styled-system prop on Primer components, as the `sx` prop is now the prefered way to
|
|
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.
|
|
10
13
|
|
|
11
14
|
\*The two non-deprecated utility components (`Box` and `Text`) are allowed to use system props.
|
|
12
15
|
|
|
@@ -43,11 +46,15 @@ import {Avatar} from 'some-other-library'
|
|
|
43
46
|
|
|
44
47
|
- `skipImportCheck` (default: `false`)
|
|
45
48
|
|
|
46
|
-
By default, the `no-system-props` rule will only check for styled system props used in functions and components that
|
|
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.
|
|
47
52
|
|
|
48
53
|
- `includeUtilityComponents` (default: `false`)
|
|
49
54
|
|
|
50
|
-
By default, `Box` and `Text` are excluded because styled system props are not deprecated in our utility components. If
|
|
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`.
|
|
51
58
|
|
|
52
59
|
```js
|
|
53
60
|
/* eslint primer-react/no-system-props: ["warn", {"includeUtilityComponents": true}] */
|