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> = {
4949 const arg = node . arguments [ 0 ]
5050
5151 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('${', '-')
5359
5460 let formattedCss = ''
5561 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-' , '}' )
5779 } catch {
5880 return context . report ( {
5981 node : arg ,
You can’t perform that action at this time.
0 commit comments