File tree Expand file tree Collapse file tree 2 files changed +43
-5
lines changed Expand file tree Collapse file tree 2 files changed +43
-5
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,38 @@ export default createRuleTester(
88 { } ,
99 {
1010 invalid : [
11+ {
12+ code : multiline `
13+ sql.fragment\`
14+ \${null}
15+ UPDATE assistant_response
16+ SET
17+ messages = \${sql.jsonb(pickedMessages as unknown as SerializableValue[])}
18+ WHERE id = \${assistantResponse.id}
19+ \`;
20+ ` ,
21+ errors : [
22+ {
23+ messageId : 'format' ,
24+ } ,
25+ ] ,
26+ options : [
27+ { } ,
28+ {
29+ tabWidth : 4 ,
30+ } ,
31+ ] ,
32+ output : multiline `
33+ sql.fragment\`
34+ \${null}
35+ UPDATE assistant_response
36+ SET
37+ messages = \${sql.jsonb(pickedMessages as unknown as SerializableValue[])}
38+ WHERE
39+ id = \${assistantResponse.id}
40+ \`;
41+ ` ,
42+ } ,
1143 {
1244 code : multiline `
1345 await pool.query(sql.typeAlias('void')\`
Original file line number Diff line number Diff line change @@ -109,7 +109,17 @@ export const rule = createRule<Options, MessageIds>({
109109 templateElement . value . raw ,
110110 ) ;
111111
112- if ( templateElement . value . raw . search ( / \S / u) === 0 ) {
112+ if ( templateElement . value . raw . search ( / \S / u) === - 1 ) {
113+ const lines = templateElement . value . raw . split ( '\n' ) ;
114+
115+ const lastLine = lines [ lines . length - 1 ] ;
116+
117+ if ( ! lastLine ) {
118+ throw new Error ( 'Unexpected' ) ;
119+ }
120+
121+ indentAnchorOffset = lastLine . length ;
122+ } else if ( templateElement . value . raw . search ( / \S / u) === 0 ) {
113123 indentAnchorOffset = tabWidth ;
114124 }
115125
@@ -137,15 +147,11 @@ export const rule = createRule<Options, MessageIds>({
137147 return ;
138148 }
139149
140- // console.log('literal', literal);
141-
142150 let formatted = format ( literal , {
143151 ...context . options [ 1 ] ,
144152 tabWidth,
145153 } ) ;
146154
147- // console.log('formatted', formatted);
148-
149155 if (
150156 ignoreStartWithNewLine &&
151157 literal . startsWith ( '\n' ) &&
You can’t perform that action at this time.
0 commit comments