@@ -13,6 +13,9 @@ module.exports = {
13
13
properties : {
14
14
skipImportCheck : {
15
15
type : 'boolean'
16
+ } ,
17
+ checkAllStrings : {
18
+ type : 'boolean'
16
19
}
17
20
} ,
18
21
additionalProperties : false
@@ -24,9 +27,14 @@ module.exports = {
24
27
// used in any components (not just ones that are imported from `@primer/components`).
25
28
const skipImportCheck = context . options [ 0 ] ? context . options [ 0 ] . skipImportCheck : false
26
29
30
+ const checkAllStrings = context . options [ 0 ] ? context . options [ 0 ] . checkAllStrings : false
31
+
32
+ // Track visited string literals to avoid reporting the same string multiple times
33
+ const visitedStrings = new Set ( )
34
+
27
35
return {
28
36
Literal ( node ) {
29
- if ( Object . keys ( deprecations ) . includes ( node . value ) ) {
37
+ if ( checkAllStrings && Object . keys ( deprecations ) . includes ( node . value ) && ! visitedStrings . has ( node ) ) {
30
38
replaceDeprecatedColor ( context , node , node . value )
31
39
}
32
40
} ,
@@ -48,15 +56,16 @@ module.exports = {
48
56
if ( propName === 'sx' && attribute . value . expression . type === 'ObjectExpression' ) {
49
57
// Search all properties of the sx object (even nested properties)
50
58
traverse ( context , attribute . value , path => {
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
- // }
59
+ if ( path . node . type === 'Property' && path . node . value . type === 'Literal' ) {
60
+ const prop = path . node
61
+ const propName = prop . key . name
62
+ const propValue = prop . value . value
63
+
64
+ if ( styledSystemColorProps . includes ( propName ) && Object . keys ( deprecations ) . includes ( propValue ) ) {
65
+ replaceDeprecatedColor ( context , prop . value , propValue )
66
+ visitedStrings . add ( prop . value )
67
+ }
68
+ }
60
69
61
70
// Check functions passed to sx object properties
62
71
// (e.g. boxShadow: theme => `0 1px 2px ${theme.colors.text.primary}` )
@@ -89,9 +98,10 @@ module.exports = {
89
98
}
90
99
91
100
// Check if styled-system color prop is using a deprecated color
92
- // if (styledSystemColorProps.includes(propName) && Object.keys(deprecations).includes(propValue)) {
93
- // replaceDeprecatedColor(context, attribute.value, propValue)
94
- // }
101
+ if ( styledSystemColorProps . includes ( propName ) && Object . keys ( deprecations ) . includes ( propValue ) ) {
102
+ replaceDeprecatedColor ( context , attribute . value , propValue )
103
+ visitedStrings . add ( attribute . value )
104
+ }
95
105
}
96
106
} ,
97
107
CallExpression ( node ) {
0 commit comments