File tree Expand file tree Collapse file tree 1 file changed +24
-2
lines changed
packages/eslint/src/rules/define-style Expand file tree Collapse file tree 1 file changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -49,11 +49,33 @@ const rule: RuleModule<MessageIds, RuleOptions> = {
49
49
const arg = node . arguments [ 0 ]
50
50
51
51
if ( arg ?. type === 'TemplateLiteral' ) {
52
- const cssRaw = arg . quasis [ 0 ] . value . raw
52
+ let index = 0
53
+ const cssRaw = context . sourceCode . text . slice (
54
+ arg . range [ 0 ] + 1 ,
55
+ arg . range [ 1 ] - 1 ,
56
+ )
57
+ // .replaceAll('${', '--')
58
+ // arg.quasis[0].value.raw.replaceAll('${', '-')
53
59
54
60
let formattedCss = ''
55
61
try {
56
- formattedCss = prettier . format ( cssRaw , { parser, tabWidth } )
62
+ formattedCss = prettier
63
+ . format (
64
+ arg . quasis
65
+ . map (
66
+ ( i ) =>
67
+ i . value . raw +
68
+ ( arg . expressions [ index ]
69
+ ? `-MACROS_START-${ context . sourceCode . text . slice (
70
+ ...arg . expressions [ index ++ ] . range ,
71
+ ) } -MACROS_END-`
72
+ : '' ) ,
73
+ )
74
+ . join ( '' ) ,
75
+ { parser, tabWidth } ,
76
+ )
77
+ . replaceAll ( '-MACROS_START-' , '${' )
78
+ . replaceAll ( '-MACROS_END-' , '}' )
57
79
} catch {
58
80
return context . report ( {
59
81
node : arg ,
You can’t perform that action at this time.
0 commit comments