Preserve-Breaks × Other Features
Scenarios exercising preserveBreaks together with other formatter features. Every
scenario runs under the declared-config check AND the prod-path idempotency matrix.
With leading commas
Leading-comma rendering interacts with per-gap NEW_LINE: the comma lands at the start of the next line.
select a,
b,
c from t
select
a
, b
, c
from t
shortStatementsOneLine: user breaks beat one-line collapse
shortStatementsOneLine tries to keep short statements on one line — but only if the
user didn't write breaks.
select a,
b from t where c = 1
select
a,
b
from t
where c = 1
shortStatementsOneLine: no user breaks → collapse allowed
select a, b from t where c = 1
select a, b from t where c = 1
Narrow width + user breaks (both signals agree)
select a, b, c, d, e, f, g, h, i, j from some_really_long_table_name
select a, b, c, d, e, f, g, h, i, j
from some_really_long_table_name
UPDATE SET with user vertical assignments
update t set a = 1,
b = 2,
c = 3 where id = 1
update
t
set
a = 1,
b = 2,
c = 3
where id = 1
INSERT VALUES multi-row vertical
insert into t (a, b, c) values
(1, 2, 3),
(4, 5, 6),
(7, 8, 9)
insert into
t (a, b, c)
values
(1, 2, 3),
(4, 5, 6),
(7, 8, 9)
CTE chain with user breaks in one body (D5 propagation)
with a as (select x,
y from t), b as (select z from a) select * from b
with a as (
select
x,
y
from t
), b as (select z from a)
select *
from b
AND/OR is exempt
User breaks between AND conditions do NOT force the WHERE clause to break — AND/OR
layout is governed by andOrPosition, not preserveBreaks.
select a from t where x > 1 and
y < 2 and
z = 3
select a
from t
where x > 1 and y < 2 and z = 3
Blank-line section break in SELECT list
select a,
b,
c,
d from t
select
a,
b,
c,
d
from t
GROUP BY vertical + HAVING compact
select dept, count(*) from t group by dept,
region having count(*) > 5
select dept, count(*)
from t
group by
dept,
region
having count(*) > 5
UNION branches — consistent siblings
When any branch carries user breaks or overflows width, all branches break together. This mirrors the SeparatedList consistentSiblings rule: once one operand has to break, rendering the other operand inline would look asymmetric and break idempotency (pass 2 would read the emitted newlines in the broken branch and force the inline branch to break too).
select a,
b from t1 union all select x, y from t2
(
select
a,
b
from t1
) union all (
select x, y
from t2
)
File-mode: multi-statement with user breaks
Two statements separated by a blank line, each with user-authored breaks inside.
Both should preserve their vertical layout independently; the inter-statement
blank line is governed by linesBetweenStatements, not preserveBreaks.
select a,
b from t1;
select x,
y,
z from t2 where id = 1
select
a,
b
from t1;
select
x,
y,
z
from t2
where id = 1
CASE WHEN with subquery carrying user breaks (D5)
select case when a > 1 then (select b,
c from t2) else null end from t
select case
when
a > 1
then (
select
b,
c
from t2
)
else null
end
from t