eslint-plugin-slonik 1.10.0 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -2
- package/dist/index.cjs +9 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +9 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -79,7 +79,7 @@ export default [
|
|
|
79
79
|
| `sql.interval({...})` | ✅ Full | Extracts type → `$1::interval` |
|
|
80
80
|
| `sql.json(value)` | ✅ Full | Extracts type → `$1::json` |
|
|
81
81
|
| `sql.jsonb(value)` | ✅ Full | Extracts type → `$1::jsonb` |
|
|
82
|
-
| `sql.literalValue(value)` | ✅ Full |
|
|
82
|
+
| `sql.literalValue(value)` | ✅ Full | Embeds as literal → `''` |
|
|
83
83
|
| `sql.uuid(str)` | ✅ Full | Extracts type → `$1::uuid` |
|
|
84
84
|
| `sql.binary(buffer)` | ✅ Full | Extracts type → `$1::bytea` |
|
|
85
85
|
| `sql.join([...], glue)` | ✅ Skip | Skipped (runtime content) |
|
|
@@ -136,7 +136,7 @@ sql.type(z.object({ id: z.number() }))`
|
|
|
136
136
|
sql.type(z.object({ result: z.string() }))`
|
|
137
137
|
SELECT ${sql.literalValue('hello')} AS result
|
|
138
138
|
`;
|
|
139
|
-
// → Validates: SELECT
|
|
139
|
+
// → Validates: SELECT '' AS result
|
|
140
140
|
|
|
141
141
|
// sql.uuid for UUID values
|
|
142
142
|
sql.type(z.object({ id: z.number() }))`
|
|
@@ -302,6 +302,48 @@ const typo = await pool.many(
|
|
|
302
302
|
);
|
|
303
303
|
```
|
|
304
304
|
|
|
305
|
+
## Disabling Validation for Specific Queries
|
|
306
|
+
|
|
307
|
+
You can disable `check-sql` validation for individual queries by adding a `@check-sql-disable` comment inside the SQL template literal:
|
|
308
|
+
|
|
309
|
+
### Block Comment Style
|
|
310
|
+
|
|
311
|
+
```ts
|
|
312
|
+
sql`/* @check-sql-disable */ SELECT * FROM ${sql.identifier([dynamicTable])}`
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### Line Comment Style
|
|
316
|
+
|
|
317
|
+
```ts
|
|
318
|
+
sql`
|
|
319
|
+
-- @check-sql-disable
|
|
320
|
+
SELECT * FROM ${sql.identifier([dynamicTable])}
|
|
321
|
+
`
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### When to Use
|
|
325
|
+
|
|
326
|
+
This is useful when you have:
|
|
327
|
+
|
|
328
|
+
1. **Dynamic SQL that cannot be validated statically** — Complex dynamic queries where even Slonik tokens aren't enough
|
|
329
|
+
2. **Queries with edge cases** — SQL syntax that the plugin doesn't support yet
|
|
330
|
+
3. **Intentional invalid SQL for testing** — When you need to test error handling
|
|
331
|
+
4. **Temporary workarounds** — While waiting for a plugin fix or improvement
|
|
332
|
+
|
|
333
|
+
```ts
|
|
334
|
+
// Example: Complex dynamic query that can't be validated
|
|
335
|
+
function buildDynamicReport(columns: string[], table: string) {
|
|
336
|
+
return sql`
|
|
337
|
+
/* @check-sql-disable */
|
|
338
|
+
SELECT ${sql.join(columns.map(c => sql.identifier([c])), sql.fragment`, `)}
|
|
339
|
+
FROM ${sql.identifier([table])}
|
|
340
|
+
`;
|
|
341
|
+
}
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
> [!NOTE]
|
|
345
|
+
> The comment must be placed inside the template literal, not outside of it. ESLint's standard `eslint-disable` comments work on the JavaScript/TypeScript level, while `@check-sql-disable` works on the SQL level.
|
|
346
|
+
|
|
305
347
|
## Differences from @ts-safeql/eslint-plugin
|
|
306
348
|
|
|
307
349
|
This plugin is specifically designed for Slonik and includes:
|
package/dist/index.cjs
CHANGED
|
@@ -246,6 +246,10 @@ function isOneOf(values, value) {
|
|
|
246
246
|
return values.includes(value);
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
+
const CHECK_SQL_DISABLE_PATTERN = /\/\*\s*@check-sql-disable\s*\*\/|--\s*@check-sql-disable\b/;
|
|
250
|
+
function hasCheckSqlDisableComment(queryText) {
|
|
251
|
+
return CHECK_SQL_DISABLE_PATTERN.test(queryText);
|
|
252
|
+
}
|
|
249
253
|
const SLONIK_SQL_TOKEN_TYPES = /* @__PURE__ */ new Set([
|
|
250
254
|
// Core SQL tokens from Slonik
|
|
251
255
|
"SqlToken",
|
|
@@ -551,6 +555,10 @@ function extractSlonikUnnestTypes(expression) {
|
|
|
551
555
|
return null;
|
|
552
556
|
}
|
|
553
557
|
function mapTemplateLiteralToQueryText(quasi, parser, checker, options, sourceCode) {
|
|
558
|
+
const rawQueryText = quasi.quasis.map((q) => q.value.raw).join("");
|
|
559
|
+
if (hasCheckSqlDisableComment(rawQueryText)) {
|
|
560
|
+
return E__namespace.right(null);
|
|
561
|
+
}
|
|
554
562
|
let $idx = 0;
|
|
555
563
|
let $queryText = "";
|
|
556
564
|
const sourcemaps = [];
|
|
@@ -703,7 +711,7 @@ function mapTemplateLiteralToQueryText(quasi, parser, checker, options, sourceCo
|
|
|
703
711
|
continue;
|
|
704
712
|
}
|
|
705
713
|
if (isSlonikLiteralValueCall(expression)) {
|
|
706
|
-
const placeholder2 =
|
|
714
|
+
const placeholder2 = `''`;
|
|
707
715
|
$queryText += placeholder2;
|
|
708
716
|
sourcemaps.push({
|
|
709
717
|
original: {
|