@@ -110,8 +110,41 @@ ruleTester.run('no-color-css-vars', rule, {
110
110
message : 'Replace var(--color-canvas-default) with canvas.default'
111
111
}
112
112
]
113
+ } ,
114
+ {
115
+ name : 'variable in scope' ,
116
+ code : `
117
+ const baseStyles = { color: 'var(--color-fg-muted)' }
118
+ export const Fixture = <Button sx={baseStyles}>Test</Button>
119
+ ` ,
120
+ output : `
121
+ const baseStyles = { color: 'fg.muted' }
122
+ export const Fixture = <Button sx={baseStyles}>Test</Button>
123
+ ` ,
124
+ errors : [
125
+ {
126
+ message : 'Replace var(--color-fg-muted) with fg.muted'
127
+ }
128
+ ]
129
+ } ,
130
+ {
131
+ name : 'merge in sx' ,
132
+ code : `
133
+ import {merge} from '@primer/react'
134
+ export const Fixture = props => <Button sx={merge({color: 'var(--color-fg-muted)'}, props.sx)}>Test</Button>
135
+ ` ,
136
+ output : `
137
+ import {merge} from '@primer/react'
138
+ export const Fixture = props => <Button sx={merge({color: 'fg.muted'}, props.sx)}>Test</Button>
139
+ ` ,
140
+ errors : [
141
+ {
142
+ message : 'Replace var(--color-fg-muted) with fg.muted'
143
+ }
144
+ ]
113
145
}
114
146
// {
147
+ // name: 'variable in styled.component',
115
148
// code: `
116
149
// import {sx, SxProp} from '@primer/react'
117
150
// export const HighlightToken = styled.span<SxProp>\`
@@ -138,15 +171,31 @@ ruleTester.run('no-color-css-vars', rule, {
138
171
// }
139
172
// ]
140
173
// },
141
-
142
174
// {
175
+ // name: 'MemberExpression in sx: not handled',
176
+ // code: `
177
+ // const colors = { muted: 'var(--color-fg-muted)' }
178
+ // export const Fixture = <Button sx={colors.muted}>Test</Button>
179
+ // `,
180
+ // output: `
181
+ // const colors = { muted: 'fg.muted' }
182
+ // export const Fixture = <Button sx={colors.muted}>Test</Button>
183
+ // `,
184
+ // errors: [
185
+ // {
186
+ // message: 'Replace var(--color-fg-muted) with fg.muted'
187
+ // }
188
+ // ]
189
+ // },
190
+ // {
191
+ // name: 'CallExpression in sx: not handled',
143
192
// code: `
144
- // const styles = { color: 'var(--color-fg-muted)' }
145
- // export const Fixture = <Button sx={styles }>Test</Button>
193
+ // const getColors = () => 'var(--color-fg-muted)'
194
+ // export const Fixture = <Button sx={getColors() }>Test</Button>
146
195
// `,
147
196
// output: `
148
- // const styles = { color: 'fg.muted' }
149
- // export const Fixture = <Button sx={styles }>Test</Button>
197
+ // const getColors = () => 'fg.muted'
198
+ // export const Fixture = <Button sx={getColors() }>Test</Button>
150
199
// `,
151
200
// errors: [
152
201
// {
0 commit comments