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(
8
8
{ } ,
9
9
{
10
10
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
+ } ,
11
43
{
12
44
code : multiline `
13
45
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>({
109
109
templateElement . value . raw ,
110
110
) ;
111
111
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 ) {
113
123
indentAnchorOffset = tabWidth ;
114
124
}
115
125
@@ -137,15 +147,11 @@ export const rule = createRule<Options, MessageIds>({
137
147
return ;
138
148
}
139
149
140
- // console.log('literal', literal);
141
-
142
150
let formatted = format ( literal , {
143
151
...context . options [ 1 ] ,
144
152
tabWidth,
145
153
} ) ;
146
154
147
- // console.log('formatted', formatted);
148
-
149
155
if (
150
156
ignoreStartWithNewLine &&
151
157
literal . startsWith ( '\n' ) &&
You can’t perform that action at this time.
0 commit comments