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