feat(format): select_wrap and join_wrap with when_long via Doc-IR

This commit is contained in:
Hein
2026-10-06 14:51:24 +02:00
parent ab9fe8893b
commit c51e8e2da4
6 changed files with 110 additions and 2 deletions
+20
View File
@@ -70,6 +70,8 @@ type Style struct {
JoinIndentSize int // extra indent levels for JOINs (default 1)
WhereWrap WrapMode // always|when_long|never — each AND/OR on its own line
LineWidth int // target width for when_long wrapping (0 = unlimited)
SelectWrap WrapMode // always|when_long|never — one SELECT/RETURNING column per line
JoinWrap WrapMode // always|when_long|never — break JOIN … ON onto its own lines
WhereAndOrIndent bool // AND/OR indented one level under WHERE
// --- Subqueries ---
@@ -122,6 +124,8 @@ func Default() Style {
IndentJoin: false,
JoinIndentSize: 1,
LineWidth: 120,
SelectWrap: WrapAlways,
JoinWrap: WrapNever,
WhereWrap: WrapAlways,
WhereAndOrIndent: true,
@@ -172,6 +176,8 @@ type yamlFile struct {
JoinIndentSize *int `yaml:"join_indent_size"`
WhereWrap *string `yaml:"where_wrap"`
LineWidth *int `yaml:"line_width"`
SelectWrap *string `yaml:"select_wrap"`
JoinWrap *string `yaml:"join_wrap"`
WhereAndOrIndent *bool `yaml:"where_and_or_indent"`
SubqueryOpening *string `yaml:"subquery_opening"`
@@ -267,6 +273,20 @@ func Load(startDir string) (Style, error) {
}
st.LineWidth = *yf.LineWidth
}
if yf.SelectWrap != nil {
wm := WrapMode(*yf.SelectWrap)
if err := validWrap(wm); err != nil {
return st, fmt.Errorf("pgtidy: %s: select_wrap: %w", path, err)
}
st.SelectWrap = wm
}
if yf.JoinWrap != nil {
wm := WrapMode(*yf.JoinWrap)
if err := validWrap(wm); err != nil {
return st, fmt.Errorf("pgtidy: %s: join_wrap: %w", path, err)
}
st.JoinWrap = wm
}
if yf.WhereWrap != nil {
wm := WrapMode(*yf.WhereWrap)
if err := validWrap(wm); err != nil {