Skip to content

Commit edadec4

Browse files
authored
Check all strings
1 parent 30d0a35 commit edadec4

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

src/rules/__tests__/no-deprecated-colors.test.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const ruleTester = new RuleTester({
2323

2424
ruleTester.run('no-deprecated-colors', rule, {
2525
valid: [
26-
`import {Box} from '@other/design-system'; <Box color="text.primary">Hello</Box>`,
26+
// `import {Box} from '@other/design-system'; <Box color="text.primary">Hello</Box>`,
2727
`import {Box} from "@primer/components"; <Box color="fg.default">Hello</Box>`,
2828
`import {hello} from "@primer/components"; hello("colors.text.primary")`,
2929
`import {themeGet} from "@primer/components"; themeGet("space.text.primary")`,
@@ -34,6 +34,15 @@ ruleTester.run('no-deprecated-colors', rule, {
3434
`import {Box} from '@primer/components'; <Box sx={{color: "fg.default"}}>Hello</Box>`
3535
],
3636
invalid: [
37+
{
38+
code: `{color: 'text.primary'}`,
39+
output: `{color: "fg.default"}`,
40+
errors: [
41+
{
42+
message: '"text.primary" is deprecated. Use "fg.default" instead.'
43+
}
44+
]
45+
},
3746
{
3847
code: `import {Box} from "@primer/components"; function Example() { return <Box color="text.primary">Hello</Box> }`,
3948
output: `import {Box} from "@primer/components"; function Example() { return <Box color="fg.default">Hello</Box> }`,

src/rules/no-deprecated-colors.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ module.exports = {
2525
const skipImportCheck = context.options[0] ? context.options[0].skipImportCheck : false
2626

2727
return {
28+
Literal(node) {
29+
if (Object.keys(deprecations).includes(node.value)) {
30+
replaceDeprecatedColor(context, node, node.value)
31+
}
32+
},
2833
JSXOpeningElement(node) {
2934
// Skip if component was not imported from @primer/components
3035
if (!skipImportCheck && !isPrimerComponent(node.name, context.getScope(node))) {
@@ -43,15 +48,15 @@ module.exports = {
4348
if (propName === 'sx' && attribute.value.expression.type === 'ObjectExpression') {
4449
// Search all properties of the sx object (even nested properties)
4550
traverse(context, attribute.value, path => {
46-
if (path.node.type === 'Property' && path.node.value.type === 'Literal') {
47-
const prop = path.node
48-
const propName = prop.key.name
49-
const propValue = prop.value.value
50-
51-
if (styledSystemColorProps.includes(propName) && Object.keys(deprecations).includes(propValue)) {
52-
replaceDeprecatedColor(context, prop.value, propValue)
53-
}
54-
}
51+
// if (path.node.type === 'Property' && path.node.value.type === 'Literal') {
52+
// const prop = path.node
53+
// const propName = prop.key.name
54+
// const propValue = prop.value.value
55+
56+
// if (styledSystemColorProps.includes(propName) && Object.keys(deprecations).includes(propValue)) {
57+
// replaceDeprecatedColor(context, prop.value, propValue)
58+
// }
59+
// }
5560

5661
// Check functions passed to sx object properties
5762
// (e.g. boxShadow: theme => `0 1px 2px ${theme.colors.text.primary}` )
@@ -84,9 +89,9 @@ module.exports = {
8489
}
8590

8691
// Check if styled-system color prop is using a deprecated color
87-
if (styledSystemColorProps.includes(propName) && Object.keys(deprecations).includes(propValue)) {
88-
replaceDeprecatedColor(context, attribute.value, propValue)
89-
}
92+
// if (styledSystemColorProps.includes(propName) && Object.keys(deprecations).includes(propValue)) {
93+
// replaceDeprecatedColor(context, attribute.value, propValue)
94+
// }
9095
}
9196
},
9297
CallExpression(node) {

0 commit comments

Comments
 (0)