@@ -105,122 +105,169 @@ The first option is an object with the following configuration.
105
105
106
106
| configuration| format| default| description|
107
107
| ---| ---| ---| ---|
108
- | ` ignoreBaseIndent ` | boolean| ` false ` | Does not leave base indent before linting.|
109
108
| ` ignoreExpressions ` | boolean| ` false ` | Does not format template literals that contain expressions.|
110
109
| ` ignoreInline ` | boolean| ` true ` | Does not format queries that are written on a single line.|
111
110
| ` ignoreStartWithNewLine ` | boolean| ` true ` | Does not remove ` \n ` at the beginning of queries.|
112
111
| ` ignoreTagless ` | boolean| ` true ` | Does not format queries that are written without using ` sql ` tag.|
112
+ | ` retainBaseIndent ` | boolean| ` true ` | Uses the first line of the query as the base indent.|
113
113
| ` sqlTag ` | string| ` sql ` | Template tag name for SQL.|
114
114
115
115
The second option is an object with the [ ` pg-formatter ` configuration] ( https://github.com/gajus/pg-formatter#configuration ) .
116
116
117
117
The following patterns are considered problems:
118
118
119
119
``` js
120
+ sql `
121
+ SELECT
122
+ 1
123
+ `
124
+ // Options: [{},{"spaces":4}]
125
+ // Message: undefined
126
+ // Fixed code:
127
+ // sql`
128
+ // SELECT
129
+ // 1
130
+ // `
131
+
132
+ sql .type ({ id: z .number () })`
133
+ SELECT
134
+ 1
135
+ `
136
+ // Options: [{},{"spaces":4}]
137
+ // Message: undefined
138
+ // Fixed code:
139
+ // sql.type({ id: z.number() })`
140
+ // SELECT
141
+ // 1
142
+ // `
143
+
144
+ sql .typeAlias (' void' )`
145
+ SELECT
146
+ 1
147
+ `
148
+ // Options: [{},{"spaces":4}]
149
+ // Message: undefined
150
+ // Fixed code:
151
+ // sql.typeAlias('void')`
152
+ // SELECT
153
+ // 1
154
+ // `
155
+
120
156
` SELECT 1`
121
- // Options: [{"ignoreInline":false,"ignoreTagless":false}]
122
- // Message: Format the query
157
+ // Options: [{"ignoreInline":false,"ignoreTagless":false},{} ]
158
+ // Message: undefined
123
159
// Fixed code:
124
160
// `
125
- // SELECT
161
+ // SELECT
126
162
// 1
127
163
// `
128
164
129
165
` SELECT 2`
130
166
// Options: [{"ignoreInline":false,"ignoreTagless":false},{"spaces":2}]
131
- // Message: Format the query
167
+ // Message: undefined
132
168
// Fixed code:
133
169
// `
134
- // SELECT
135
- // 2
170
+ // SELECT
171
+ // 2
136
172
// `
137
173
138
174
sql .unsafe ` SELECT 3`
139
- // Options: [{"ignoreInline":false}]
140
- // Message: Format the query
175
+ // Options: [{"ignoreInline":false},{} ]
176
+ // Message: undefined
141
177
// Fixed code:
142
178
// sql.unsafe`
143
- // SELECT
179
+ // SELECT
144
180
// 3
145
181
// `
146
182
147
183
sql .type ()` SELECT 3`
148
- // Options: [{"ignoreInline":false}]
149
- // Message: Format the query
184
+ // Options: [{"ignoreInline":false},{} ]
185
+ // Message: undefined
150
186
// Fixed code:
151
187
// sql.type()`
152
- // SELECT
188
+ // SELECT
153
189
// 3
154
190
// `
155
191
156
192
` SELECT ${ ' foo' } FROM ${ ' bar' } `
157
- // Options: [{"ignoreInline":false,"ignoreTagless":false}]
158
- // Message: Format the query
193
+ // Options: [{"ignoreInline":false,"ignoreTagless":false},{} ]
194
+ // Message: undefined
159
195
// Fixed code:
160
196
// `
161
- // SELECT
197
+ // SELECT
162
198
// ${'foo'}
163
- // FROM
199
+ // FROM
164
200
// ${'bar'}
165
201
// `
166
202
167
- const code = sql `
168
- SELECT
169
- ${ ' foo' }
170
- FROM
171
- ${ ' bar' }
203
+ const code = sql `
204
+ SELECT
205
+ foo
206
+ FROM
207
+ bar
172
208
`
173
- // Options: [{"ignoreBaseIndent":false }]
174
- // Message: Format the query
209
+ // Options: [{},{ }]
210
+ // Message: undefined
175
211
// Fixed code:
176
- // const code = sql`
177
- // SELECT
178
- // ${' foo'}
179
- // FROM
180
- // ${' bar'}
212
+ // const code = sql`
213
+ // SELECT
214
+ // foo
215
+ // FROM
216
+ // bar
181
217
// `
182
218
183
219
SQL ` SELECT 1 `
184
- // Options: [{"ignoreInline":false,"sqlTag":"SQL"}]
185
- // Message: Format the query
220
+ // Options: [{"ignoreInline":false,"sqlTag":"SQL"},{} ]
221
+ // Message: undefined
186
222
// Fixed code:
187
223
// SQL`
188
- // SELECT
224
+ // SELECT
189
225
// 1
190
226
// `
191
227
```
192
228
193
229
The following patterns are not considered problems:
194
230
195
231
``` js
232
+ `
233
+ # A
234
+ ## B
235
+ ### C
236
+ `
237
+
196
238
sql ` SELECT 1 `
197
- // Options: [{"ignoreInline":true}]
239
+ // Options: [{"ignoreInline":true},{} ]
198
240
199
241
` SELECT 2`
200
- // Options: [{"ignoreTagless":true}]
242
+ // Options: [{"ignoreTagless":true},{} ]
201
243
202
- ` SELECT ${ ' foo' } FROM ${ ' bar' } `
203
- // Options: [{"ignoreExpressions":true,"ignoreInline":false,"ignoreTagless":false}]
204
-
205
- const code = sql `
206
- SELECT
207
- ${ ' foo' }
208
- FROM
209
- ${ ' bar' }
210
- `
211
- // Options: [{"ignoreBaseIndent":true}]
212
-
213
- const code = sql `
214
- DROP TABLE foo
215
- ` ;
216
- // Options: [{"ignoreBaseIndent":true}]
217
-
218
- const code = sql `
219
- DROP TABLE foo;
220
-
221
- DROP TABLE foo;
222
- ` ;
223
- // Options: [{"ignoreBaseIndent":true}]
244
+ const code = sql `
245
+ SELECT
246
+ ${ ' foo' }
247
+ FROM
248
+ ${ ' bar' }
249
+ `
250
+ // Options: [{"ignoreExpressions":true,"ignoreInline":false,"ignoreTagless":false},{}]
251
+
252
+ const code = sql `
253
+ SELECT
254
+ ${ ' foo' }
255
+ FROM
256
+ ${ ' bar' }
257
+ `
258
+ // Options: [{},{}]
259
+
260
+ const code = sql `
261
+ DROP TABLE foo
262
+ `
263
+ // Options: [{},{}]
264
+
265
+ const code = sql `
266
+ DROP TABLE foo;
267
+
268
+ DROP TABLE foo;
269
+ `
270
+ // Options: [{},{}]
224
271
```
225
272
226
273
@@ -251,20 +298,20 @@ The following patterns are considered problems:
251
298
252
299
``` js
253
300
` SELECT 1`
254
- // Message: Use "sql" tag
301
+ // Message: undefined
255
302
256
303
` SELECT ${ ' foo' } `
257
- // Message: Use "sql" tag
304
+ // Message: undefined
258
305
259
306
foo` SELECT ${ ' bar' } `
260
- // Message: Use "sql" tag
307
+ // Message: undefined
261
308
262
309
` SELECT ?`
263
- // Message: Use "sql" tag
310
+ // Message: undefined
264
311
265
312
foo` SELECT ${ ' bar' } `
266
313
// Options: [{"sqlTag":"SQL"}]
267
- // Message: Use "SQL" tag
314
+ // Message: undefined
268
315
```
269
316
270
317
The following patterns are not considered problems:
0 commit comments