Skip to content

Commit 5f3cc4c

Browse files
committed
chore: add paramTypes custom regex for {{variable}} sql-formatter compatibility
1 parent 0294dea commit 5f3cc4c

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

.sql-formatter.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
"language": "trino",
33
"keywordCase": "upper",
44
"functionCase": "upper",
5-
"dataTypeCase": "upper"
5+
"dataTypeCase": "upper",
6+
"paramTypes": {
7+
"custom": [{ "regex": "\\{\\{[a-zA-Z_][a-zA-Z0-9_]*\\}\\}" }]
8+
}
69
}

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@
66
"SQL-Formatter-VSCode.dialect": "trino",
77
"SQL-Formatter-VSCode.keywordCase": "upper",
88
"SQL-Formatter-VSCode.functionCase": "upper",
9-
"SQL-Formatter-VSCode.dataTypeCase": "upper"
9+
"SQL-Formatter-VSCode.dataTypeCase": "upper",
10+
"SQL-Formatter-VSCode.paramTypes": {
11+
"custom": [{ "regex": "\\{\\{[a-zA-Z_][a-zA-Z0-9_]*\\}\\}" }]
12+
}
1013
}

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ The built-in denylist does not guarantee 100% protection against all SQL injecti
172172

173173
## sql-formatter Compatibility
174174

175-
The `{{variable}}` syntax is fully compatible with [sql-formatter](https://github.com/sql-formatter-org/sql-formatter). The Trino dialect natively supports `{{double brace}}` parameters, so no custom regex is needed.
175+
The `{{variable}}` syntax is fully compatible with [sql-formatter](https://github.com/sql-formatter-org/sql-formatter). A `paramTypes` custom regex is required so that `{{variables}}` containing SQL keywords (e.g. `{{limit}}`) are treated as parameters instead of being parsed as SQL.
176176

177177
### VS Code
178178

@@ -187,7 +187,10 @@ Install the [SQL Formatter VSCode](https://marketplace.visualstudio.com/items?it
187187
"SQL-Formatter-VSCode.dialect": "trino",
188188
"SQL-Formatter-VSCode.keywordCase": "upper",
189189
"SQL-Formatter-VSCode.functionCase": "upper",
190-
"SQL-Formatter-VSCode.dataTypeCase": "upper"
190+
"SQL-Formatter-VSCode.dataTypeCase": "upper",
191+
"SQL-Formatter-VSCode.paramTypes": {
192+
"custom": [{ "regex": "\\{\\{[a-zA-Z_][a-zA-Z0-9_]*\\}\\}" }]
193+
}
191194
}
192195
```
193196

0 commit comments

Comments
 (0)