This document defines the stable behavior contract for sqlchisel. It focuses on guarantees and intentionally avoids layout heuristics that may change over time.
The contract covers:
- output stability and repeatability
- statement and semicolon handling
- parser fallback behavior (
Rawvs--strict) - CLI mode exclusivity and check-mode exit semantics
- templated SQL passthrough (Jinja markers)
Heuristics such as select-list thresholds and line-break preferences are documented in style-guide.md and are not part of this contract.
- For a given
sqlchiselversion and the same effective configuration, formatting is deterministic. - Formatting an already-formatted input should produce the same output (idempotent), except when a bug is present.
- This guarantee is per version. Layout details may change across versions when formatter heuristics improve.
- Top-level SQL statements are emitted in input order.
- Consecutive top-level statements are separated by exactly one blank line in formatted output.
sqlchiselpreserves whether each top-level statement fragment had a trailing semicolon.- It does not add semicolons to statements that did not end with one.
- It does not remove semicolons from statements that did end with one.
- Single-quoted string literal contents are preserved as written, including doubled quotes and over-escaped forms.
- Quoted identifier contents are not recased.
JOINstaysJOIN.INNER JOINstaysINNER JOIN.
Default behavior (strict = false / no --strict):
- If a top-level fragment cannot be parsed,
sqlchiselfalls back to a token-level raw formatter for that fragment instead of failing the whole input. - Other fragments in the same input can still be fully formatted.
- The stable guarantee is the fallback behavior (no hard failure by default), not the exact token-level layout chosen for unsupported syntax across versions.
Strict behavior (strict = true or --strict):
- Parse failures are returned as errors.
- Formatting/check/write fails instead of using raw fallback.
- If the input contains Jinja markers (
{{,{%, or{#),sqlchiselcurrently returns the input unchanged. - This passthrough behavior is part of the current stable contract to avoid corrupting templated SQL.
- Only one of
--format,--check, or--writemay be used in a single invocation. --writecannot be combined with--stdin.- File paths and
--stdinare mutually exclusive. - In
--checkmode,sqlchiselexits with status1if any input would be reformatted.
--check mode:
- Exit
0when all inputs are already formatted. - Exit
1when any input differs from formatted output;sqlchiselprints<path> would be reformattedto stderr for changed inputs.
Invalid mode/input combinations (error, non-zero exit):
sqlchisel --format --check file.sql- error:
use only one of --format, --check, or --write
- error:
sqlchisel --write --stdin- error:
--write requires file inputs (not --stdin)
- error:
sqlchisel --stdin file.sql- error:
use either FILES or --stdin, not both
- error:
sqlchisel(with no files and no--stdin)- error:
no input provided; pass FILES or --stdin
- error:
Notes:
- Exact parser/IO error wording outside the cases above is not a stable contract.
--strictchanges parse-failure behavior from raw fallback to an error (non-zero exit).
- Effective configuration is resolved as: defaults -> config file -> CLI overrides.
--config <PATH>overrides the default config file discovery path.
Statement spacing + semicolon preservation:
fixtures/dremio/in/13.sqlcontains three top-level statements that end with semicolons.fixtures/dremio/expected/13.sqlpreserves those semicolons and emits exactly one blank line between each formatted statement.
Raw fallback (default non-strict mode):
fixtures/ansi/in/11.sqlcontains unsupported syntax (unknown_verb ...) that does not parse as a normal SQL statement.fixtures/ansi/expected/11.sqlshowssqlchiselstill returns formatted output for that fragment (keyword casing/spacing applied) instead of failing.
- Select-list layout thresholds and line-break heuristics
- Clause wrapping decisions when multiple layouts are valid
- Best-effort comment placement in ambiguous locations
- Exact raw-fallback formatting details for unsupported syntax