Hygiene
Whitespace hygiene: no trailing spaces, no tabs, no invented blank lines, no stray indentation.
Each pair below is a real, passing case from dfmt's test corpus (suites/dfmt-jinja/cases/hygiene/): the template as written, then the same template after dfmt — every Jinja tag reproduced exactly, the SQL laid out around it. 5 examples.
Declining returns the input untouched
Left unchanged — already in dfmt's shape:
THIS IS NOT SQL @#$%
File ends with a newline
Before
select a
from t
{% if flag %}
where x = 1
{% endif %}
After
select a
from t
{% if flag %}
where x = 1
{% endif %}
No leading blank line
Before
{% set x = 1 %}
select {{ x }} as v
from t
After
{% set x = 1 %}
select {{ x }} as v
from t
No trailing space at eof
Before
select
client_key,
min(session_start_timestamp) as first_seen_timestamp,
sum(sum_event_value_in_usd) as sum_event_value_in_usd,
{% if is_incremental() %}
count(distinct session_key) as count_sessions,
{% endif %}
stream_id
from sessions
After
select
client_key,
min(session_start_timestamp) as first_seen_timestamp,
sum(sum_event_value_in_usd) as sum_event_value_in_usd,
{% if is_incremental() %}
count(distinct session_key) as count_sessions,
{% endif %}
stream_id
from sessions
No trailing whitespace
Before
select
case when a then
b
else c end as v
from t
{% if flag %}
where d = 1
{% endif %}
After
select case when a then b else c end as v
from t
{% if flag %}
where d = 1
{% endif %}