eslint-plugin-primer-react 0.4.2-rc.8a50dcc → 0.4.2-rc.ddd5385
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
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
- [#
|
|
7
|
+
- [#7](https://github.com/primer/eslint-plugin-primer-react/pull/7) [`d9dfb8d`](https://github.com/primer/eslint-plugin-primer-react/commit/d9dfb8de6d6dc42efe606517db7a0dd90d5c5578) Thanks [@colebemis](https://github.com/colebemis)! - Add `skipImportCheck` option. By default, the `no-deprecated-colors` rule will only check for deprecated colors used in functions and components that are imported from `@primer/components`. 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.
|
|
8
|
+
|
|
9
|
+
* [#6](https://github.com/primer/eslint-plugin-primer-react/pull/6) [`dd14594`](https://github.com/primer/eslint-plugin-primer-react/commit/dd14594b05e4d800baa76771f5b911d77352a983) Thanks [@colebemis](https://github.com/colebemis)! - The `no-deprecated-colors` rule can now find deprecated colors in the following cases:
|
|
8
10
|
|
|
9
11
|
- Nested `sx` properties:
|
|
10
12
|
|
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
|
|
3
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
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.
|
|
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
6
|
|
|
7
7
|
## Rule details
|
|
8
8
|
|
|
9
9
|
This rule disallows references to color variables that are deprecated in [Primer Primitives](https://github.com/primer/primitives).
|
|
10
10
|
|
|
11
|
-
|
|
12
11
|
👎 Examples of **incorrect** code for this rule:
|
|
13
12
|
|
|
14
13
|
```jsx
|
|
@@ -21,7 +20,7 @@ const SystemPropExample() = () => <Box color="some.deprecated.color">Incorrect</
|
|
|
21
20
|
const SxPropExample() = () => <Box sx={{color: 'some.deprecated.color'}}>Incorrect</Box>
|
|
22
21
|
|
|
23
22
|
const ThemeGetExample = styled.div`
|
|
24
|
-
color: ${themeGet('some.deprecated.color')};
|
|
23
|
+
color: ${themeGet('colors.some.deprecated.color')};
|
|
25
24
|
`
|
|
26
25
|
```
|
|
27
26
|
|
|
@@ -37,6 +36,17 @@ const SystemPropExample() = () => <Box color="some.color">Incorrect</Box>
|
|
|
37
36
|
const SxPropExample() = () => <Box sx={{color: 'some.color'}}>Incorrect</Box>
|
|
38
37
|
|
|
39
38
|
const ThemeGetExample = styled.div`
|
|
40
|
-
color: ${themeGet('some.color')};
|
|
39
|
+
color: ${themeGet('colors.some.color')};
|
|
41
40
|
`
|
|
42
41
|
```
|
|
42
|
+
|
|
43
|
+
## Options
|
|
44
|
+
|
|
45
|
+
- `skipImportCheck` (default: `false`)
|
|
46
|
+
|
|
47
|
+
By default, the `no-deprecated-colors` rule will only check for deprecated colors used in functions and components that are imported from `@primer/components`. 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.
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
"primer-react/no-deprecated-colors": ["warn", {"skipImportCheck": true}]
|
|
52
|
+
```
|
package/package.json
CHANGED
|
@@ -43,6 +43,16 @@ ruleTester.run('no-deprecated-colors', rule, {
|
|
|
43
43
|
}
|
|
44
44
|
]
|
|
45
45
|
},
|
|
46
|
+
{
|
|
47
|
+
code: `import {Box} from "../components"; function Example() { return <Box color="text.primary">Hello</Box> }`,
|
|
48
|
+
output: `import {Box} from "../components"; function Example() { return <Box color="fg.default">Hello</Box> }`,
|
|
49
|
+
options: [{skipImportCheck: true}],
|
|
50
|
+
errors: [
|
|
51
|
+
{
|
|
52
|
+
message: '"text.primary" is deprecated. Use "fg.default" instead.'
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
},
|
|
46
56
|
{
|
|
47
57
|
code: `import Box from '@primer/components/lib-esm/Box'; function Example() { return <Box color="text.primary">Hello</Box> }`,
|
|
48
58
|
output: `import Box from '@primer/components/lib-esm/Box'; function Example() { return <Box color="fg.default">Hello</Box> }`,
|
|
@@ -6,13 +6,28 @@ const styledSystemColorProps = ['color', 'bg', 'backgroundColor', 'borderColor',
|
|
|
6
6
|
module.exports = {
|
|
7
7
|
meta: {
|
|
8
8
|
type: 'suggestion',
|
|
9
|
-
fixable: 'code'
|
|
9
|
+
fixable: 'code',
|
|
10
|
+
schema: [
|
|
11
|
+
{
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
skipImportCheck: {
|
|
15
|
+
type: 'boolean'
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
additionalProperties: false
|
|
19
|
+
}
|
|
20
|
+
]
|
|
10
21
|
},
|
|
11
22
|
create(context) {
|
|
23
|
+
// If `skipImportCheck` is true, this rule will check for deprecated colors
|
|
24
|
+
// used in any components (not just ones that are imported from `@primer/components`).
|
|
25
|
+
const skipImportCheck = context.options[0] ? context.options[0].skipImportCheck : false
|
|
26
|
+
|
|
12
27
|
return {
|
|
13
28
|
JSXOpeningElement(node) {
|
|
14
29
|
// Skip if component was not imported from @primer/components
|
|
15
|
-
if (!isPrimerComponent(node.name, context.getScope(node))) {
|
|
30
|
+
if (!skipImportCheck && !isPrimerComponent(node.name, context.getScope(node))) {
|
|
16
31
|
return
|
|
17
32
|
}
|
|
18
33
|
|
|
@@ -77,7 +92,10 @@ module.exports = {
|
|
|
77
92
|
CallExpression(node) {
|
|
78
93
|
// Skip if not calling the `themeGet` or `get` function
|
|
79
94
|
// `get` is the internal version of `themeGet` that's used in the primer/react repository
|
|
80
|
-
if (
|
|
95
|
+
if (
|
|
96
|
+
!isThemeGet(node.callee, context.getScope(node), skipImportCheck) &&
|
|
97
|
+
!isGet(node.callee, context.getScope(node))
|
|
98
|
+
) {
|
|
81
99
|
return
|
|
82
100
|
}
|
|
83
101
|
|
|
@@ -123,11 +141,17 @@ function isPrimerComponent(identifier, scope) {
|
|
|
123
141
|
return isImportedFrom(/^@primer\/components/, identifier, scope)
|
|
124
142
|
}
|
|
125
143
|
|
|
126
|
-
function isThemeGet(identifier, scope) {
|
|
127
|
-
|
|
144
|
+
function isThemeGet(identifier, scope, skipImportCheck = false) {
|
|
145
|
+
if (!skipImportCheck) {
|
|
146
|
+
return isImportedFrom(/^@primer\/components/, identifier, scope) && identifier.name === 'themeGet'
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return identifier.name === 'themeGet'
|
|
128
150
|
}
|
|
129
151
|
|
|
152
|
+
// `get` is the internal version of `themeGet` that's used in the primer/react repository.
|
|
130
153
|
function isGet(identifier, scope) {
|
|
154
|
+
// This is a flaky way to check for the `get` function and should probably be improved.
|
|
131
155
|
return isImportedFrom(/^\.\.?\/constants$/, identifier, scope) && identifier.name === 'get'
|
|
132
156
|
}
|
|
133
157
|
|