Skip to content

feat(fmt): use lax-sql for SQL formatting#35161

Merged
bartlomieju merged 5 commits into
mainfrom
feat/lax-sql-formatter
Jun 13, 2026
Merged

feat(fmt): use lax-sql for SQL formatting#35161
bartlomieju merged 5 commits into
mainfrom
feat/lax-sql-formatter

Conversation

@bartlomieju

@bartlomieju bartlomieju commented Jun 11, 2026

Copy link
Copy Markdown
Member

Replaces sqlformat with lax-sql (https://github.com/bartlomieju/lax) for
deno fmt --unstable-sql and for SQL embedded in tagged templates.

lax-sql never interprets the SQL beyond splitting it into statements and
clauses, and it never rewrites a token. That makes it dialect agnostic by
construction: PostgreSQL dollar quoting and E'...' strings, MySQL
backticks, T-SQL bracket identifiers and #temp tables, and every
placeholder style (?, $1, :name, @var) pass through untouched.
Strings, quoted identifiers, numbers, and comments are never modified.

The output is canonical: each clause goes on its own line and the clause
body packs and wraps at the configured width, so the same query formats
the same way regardless of how it was typed. Keyword uppercasing is kept
to match the previous sqlformat output. Because the formatter is
canonical rather than preserving the input layout, SQL files reformat on
the first run; this is gated behind the unstable flag.

lax-sql is validated against the sqlfluff dialect fixture corpus, about
2150 files across 30 dialects, and carries regression tests for the
formatting bugs reported against sqlformat-rs, most of which cannot occur
here by construction. Statements that sqlformat mangled, such as
ON DELETE SET NULL constraints or :: casts, now keep their shape.

@bartlomieju
bartlomieju marked this pull request as ready for review June 12, 2026 06:42
lax-sql 0.2.1 produces canonical output (author line breaks are no
longer consulted) with the default fill clause style. Adds the required
clause_style field to the config and regenerates the SQL fixtures:
clauses sit on their own lines and bodies pack until the line width, so
for example INSERT INTO and its column list stay on one line instead of
being split across many.
@bartlomieju bartlomieju added this to the 2.9.0 milestone Jun 13, 2026
@bartlomieju
bartlomieju enabled auto-merge (squash) June 13, 2026 11:52
@bartlomieju
bartlomieju merged commit 0759a1a into main Jun 13, 2026
269 of 271 checks passed
@bartlomieju
bartlomieju deleted the feat/lax-sql-formatter branch June 13, 2026 11:59
bartlomieju added a commit that referenced this pull request Jun 14, 2026
Resolves conflicts after #35160 (lax-css) and #35161 (lax-sql) landed on main:
- deps: keep lax-css + lax-markup + lax-sql; drop malva and markup_fmt
- fmt.rs: format_html uses lax-markup; format_markup_embedded routes CSS to
  lax-css instead of the removed malva; format_embedded_html uses lax-markup
- Cargo.lock reconciled (lax-markup 0.2.4 added, markup_fmt/malva removed)
- bump lax-markup to 0.2.4 ({{ }} interpolation formatting)
- regenerate vue fixture interpolations ({{a+b}} -> {{ a + b }})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant