Skip to content

Commit a7a8b1a

Browse files
authored
Revert "[Breaking] Remove no-deprecated-colors plugin (#169)"
This reverts commit 2576a9f.
1 parent 2576a9f commit a7a8b1a

9 files changed

+524
-6
lines changed

.changeset/shiny-kiwis-hammer.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ ESLint rules for Primer React
3232
## Rules
3333

3434
- [direct-slot-children](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/direct-slot-children.md)
35+
- [no-deprecated-colors](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/no-deprecated-colors.md)
3536
- [no-system-props](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/no-system-props.md)
3637
- [a11y-tooltip-interactive-trigger](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/a11y-tooltip-interactive-trigger.md)
3738
- [a11y-explicit-heading](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/a11y-explicit-heading.md)

docs/rules/no-deprecated-colors.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +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+
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+
```

package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
},
2626
"homepage": "https://github.com/primer/eslint-plugin-primer-react#readme",
2727
"peerDependencies": {
28+
"@primer/primitives": ">=4.6.2",
2829
"eslint": "^8.42.0"
2930
},
3031
"dependencies": {
@@ -40,6 +41,7 @@
4041
"@changesets/cli": "^2.16.0",
4142
"@github/markdownlint-github": "^0.6.0",
4243
"@github/prettier-config": "0.0.6",
44+
"@primer/primitives": "^7.14.0",
4345
"eslint": "^8.42.0",
4446
"eslint-plugin-prettier": "^5.0.1",
4547
"jest": "^29.7.0",

src/configs/recommended.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = {
1111
extends: ['plugin:github/react'],
1212
rules: {
1313
'primer-react/direct-slot-children': 'error',
14+
'primer-react/no-deprecated-colors': 'warn',
1415
'primer-react/no-system-props': 'warn',
1516
'primer-react/a11y-tooltip-interactive-trigger': 'error',
1617
'primer-react/new-color-css-vars': 'error',

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = {
22
rules: {
33
'direct-slot-children': require('./rules/direct-slot-children'),
4+
'no-deprecated-colors': require('./rules/no-deprecated-colors'),
45
'no-deprecated-entrypoints': require('./rules/no-deprecated-entrypoints'),
56
'no-system-props': require('./rules/no-system-props'),
67
'a11y-tooltip-interactive-trigger': require('./rules/a11y-tooltip-interactive-trigger'),

0 commit comments

Comments
 (0)