Skip to content

fix(format): make sqb format safe and idempotent - #791

Merged
kvlonge merged 5 commits into
mainfrom
fix/format-correctness
Sep 23, 2026
Merged

kvlonge merged 5 commits into
mainfrom
fix/format-correctness

Conversation

@kvlonge

@kvlonge kvlonge commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Why

sqb format could not back a pre-commit fixer plus a --check CI gate:

  • An uppercase SCHEMA (type ...) column inside MODEL(... columns (...)) was detected as a second SCHEMA() header. Format spliced in a duplicated header and the file stopped compiling.
  • Snowflake FROM VALUES (...) was rewritten to FROM (VALUES ...), which SQBRSQL039 rejects, so compile failed.
  • --exclude without --select dropped SQL tests from the format scope, and path:tests could not be combined with --exclude.
  • A missing description made format and --check exit 1 even when nothing needed formatting.
  • Some typed-null test fixtures needed two sqb format runs to settle, so format followed by --check failed.

Changes

  • Header scanning ignores candidates inside an accepted header. Authored and rewritten headers are parsed before any write, and a file whose header fails to parse is left untouched with a header-parse fault.
  • The native formatter keeps each VALUES relation's authored form. Wrappers are matched per occurrence.
  • Format selection: the default scope is every formatter-owned SQL file minus exclusions. Path and model selectors combine, and --select <model> still formats only that model.
  • In format, description-present is a warning. Exit status depends on faults and on pending changes for --check. Lint and Rules are unchanged.
  • Formatter declines (unsupported SQL, comment attachments) are silent body skips again, and header formatting still applies.
  • Fixture simplification also runs on the canonical formatted body, so one sqb format reaches a fixed point.

Verification

  • Real-CLI integration tests for each case, with idempotency checks.
  • Rust tests for mixed and nested VALUES, strings and comments.
  • make test (6,940 passed) and make check-ci.
  • Validated privately on a large Snowflake project: one format, then --check exits 0, compile passes, and SQL test results are unchanged.

@kvlonge
kvlonge enabled auto-merge (squash) September 23, 2026 13:16
@kvlonge
kvlonge merged commit 041a264 into main Sep 23, 2026
28 checks passed
@kvlonge
kvlonge deleted the fix/format-correctness branch September 23, 2026 13:54
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