@@ -6,7 +6,7 @@ module.exports = {
6
6
hasSuggestions : true ,
7
7
fixable : 'code' ,
8
8
docs : {
9
- description : 'Disallow the use of CSS color variables in React '
9
+ description : 'Upgrade legacy CSS variables to Primitives v8 in sx prop '
10
10
} ,
11
11
schema : [
12
12
{
@@ -65,56 +65,12 @@ module.exports = {
65
65
}
66
66
} else if (
67
67
styledSystemProps . includes ( node . name . name ) &&
68
+ node . value &&
68
69
node . value . type === 'Literal' &&
69
70
typeof node . value . value === 'string'
70
71
) {
71
72
checkForVariables ( node . value , node . value . value )
72
73
}
73
- } ,
74
- TaggedTemplateExpression ( node ) {
75
- if ( node . tag . type !== 'MemberExpression' ) {
76
- return
77
- }
78
-
79
- if ( node . tag . object . name !== 'styled' ) {
80
- return
81
- }
82
-
83
- const DECLARATION_REGEX = / ( .+ ) : ( v a r \( - - c o l o r - .+ \) ) ; /
84
-
85
- // const StyledComponent = styled.div`
86
- // color: var(--color-fg-example);
87
- // background: var(--color-bg-example);
88
- // `;
89
- for ( const templateElement of node . quasi . quasis ) {
90
- const rawValue = templateElement . value . raw
91
- const match = rawValue . match ( DECLARATION_REGEX )
92
- if ( ! match ) {
93
- continue
94
- }
95
-
96
- const property = match [ 1 ] . trim ( )
97
- const value = match [ 2 ] . trim ( )
98
-
99
- for ( const [ cssVar , replacements ] of Object . entries ( cssVars ) ) {
100
- const regex = new RegExp ( `var\\(${ cssVar } \\)` , 'g' )
101
-
102
- for ( const { props, replacement} of replacements ) {
103
- if ( ! props . includes ( property ) ) {
104
- continue
105
- }
106
-
107
- if ( ! regex . test ( value ) ) {
108
- continue
109
- }
110
-
111
- context . report ( {
112
- node,
113
- message : `Replace var(${ cssVar } ) with var(${ replacement } , var(${ cssVar } ))`
114
- } )
115
- }
116
- }
117
- }
118
74
}
119
75
}
120
76
@@ -126,7 +82,11 @@ module.exports = {
126
82
if ( Array . isArray ( cssVars [ cssVar ] ) ) {
127
83
cssVars [ cssVar ] . forEach ( cssVarObject => {
128
84
const regex = new RegExp ( `var\\(${ cssVar } \\)` , 'g' )
129
- if ( cssVarObject . props . some ( prop => rawText . includes ( prop ) ) && regex . test ( rawText ) ) {
85
+ if (
86
+ cssVarObject . props . some ( prop => rawText . includes ( prop ) ) &&
87
+ regex . test ( rawText ) &&
88
+ ! rawText . includes ( cssVarObject . replacement )
89
+ ) {
130
90
const fixedString = rawText . replace ( regex , `var(${ cssVarObject . replacement } , var(${ cssVar } ))` )
131
91
if ( ! rawText . includes ( fixedString ) ) {
132
92
context . report ( {
0 commit comments