feat(format): default output to dist/examples house style
Align the formatter defaults and layout with the hand-formatted reference procedures in dist/examples so a clean `pgtidy fmt` produces the house style. config.Default(): - align_param_types: false (no type-column alignment in param lists) - plpgsql_declare_align_type / plpgsql_declare_align_eq: true Formatter: - routine header: leading-comma params at column 0, first param at one indent, RETURNS/LANGUAGE/volatility/SECURITY each indented one level - %type / %rowtype printed tight (isPctTypeBoundary) - DECLARE = / := / DEFAULT column padded only to the widest declaration that carries an assignment - WHERE continuations in body UPDATE/DELETE: AND/OR aligned with WHERE - EXCEPTION aligned to its enclosing BEGIN; column-0 comment continuations kept flush-left Safety gate: - SemanticallyEqual tolerates CRLF vs LF inside string literals (normNL); the formatter re-emits all layout with st.Newline, so a \r\n inside a multi-line string literal is normalisation, not a code change. This was why action_init and event_exec_func previously refused to format. Corpus: - add the four CRLF reference files as idempotence/safety fixtures - regenerate test_a and test_mm_proc goldens FOR...LOOP body indentation keeps the existing +1 convention (LOOP aligned with FOR); the dist/examples use +2, so loop-body regions differ by whitespace only.
This commit is contained in:
@@ -47,14 +47,14 @@ insert_collapse_values: true # Fold multiple VALUES rows onto fewer lines
|
||||
|
||||
# --- Routines (functions / procedures) ---
|
||||
|
||||
align_param_types: true # Pad param names so type column aligns across all params
|
||||
align_param_types: false # Pad param names so type column aligns across all params
|
||||
routine_as_wrap: true # Newline before AS $$ (false = keep AS on same line)
|
||||
|
||||
# --- PL/pgSQL body ---
|
||||
|
||||
plpgsql_max_blank_lines: 1 # Max consecutive blank lines in body
|
||||
plpgsql_declare_align_type: false # Align type column in DECLARE block
|
||||
plpgsql_declare_align_eq: false # Align := / = in DECLARE block
|
||||
plpgsql_max_blank_lines: 1 # Max consecutive blank lines in body
|
||||
plpgsql_declare_align_type: true # Align type column in DECLARE block
|
||||
plpgsql_declare_align_eq: true # Align := / = in DECLARE block (padded to the widest assigned declaration)
|
||||
plpgsql_if_then_newline: true # THEN on its own line (false = same line as condition)
|
||||
plpgsql_loop_collapse: true # Collapse empty loop bodies to one line
|
||||
|
||||
|
||||
+3
-3
@@ -128,7 +128,7 @@ DataGrip enum conventions used below:
|
||||
| DataGrip key | PgTidy key | Default | Notes |
|
||||
|---|---|---|---|
|
||||
| `ROUTINE_ARG_COMMA` | uses `commas` | `leading` | same setting as query lists |
|
||||
| `ROUTINE_ARG_ALIGN_TYPES` | `align_param_types` | `true` | align type column in param list |
|
||||
| `ROUTINE_ARG_ALIGN_TYPES` | `align_param_types` | `false` | align type column in param list |
|
||||
| `ROUTINE_AS_WRAP` | `routine_as_wrap` | `true` | newline before `AS $$` |
|
||||
|
||||
### PL/pgSQL body
|
||||
@@ -136,8 +136,8 @@ DataGrip enum conventions used below:
|
||||
| DataGrip key | PgTidy key | Default | Notes |
|
||||
|---|---|---|---|
|
||||
| `IMP_COMMON_KEEP_BLANK_LINES_IN_CODE` | `plpgsql_max_blank_lines` | `1` | max consecutive blank lines in body |
|
||||
| `IMP_DECLARE_ALIGN_TYPE` | `plpgsql_declare_align_type` | `false` | align type column in DECLARE block |
|
||||
| `IMP_DECLARE_ALIGN_EQ` | `plpgsql_declare_align_eq` | `false` | align `:=` / `=` in DECLARE block |
|
||||
| `IMP_DECLARE_ALIGN_TYPE` | `plpgsql_declare_align_type` | `true` | align type column in DECLARE block |
|
||||
| `IMP_DECLARE_ALIGN_EQ` | `plpgsql_declare_align_eq` | `true` | align `:=` / `=` in DECLARE block |
|
||||
| `IMP_IF_THEN_WRAP_THEN` | `plpgsql_if_then_newline` | `true` | THEN on its own line |
|
||||
| `IMP_LOOP_COLLAPSE` | `plpgsql_loop_collapse` | `true` | collapse empty loop bodies |
|
||||
|
||||
|
||||
+4
-2
@@ -213,7 +213,7 @@ as a proxy (new_line for content, inline for single-arg subexpressions).
|
||||
|
||||
### ✅ Formatter — routine param alignment (`pkg/format/format.go`)
|
||||
|
||||
- `align_param_types`: `alignParamTypes()` pads param names so type columns align; default `true`.
|
||||
- `align_param_types`: `alignParamTypes()` pads param names so type columns align; default `false` (house style: no type-column alignment in param lists).
|
||||
- `routine_as_wrap`: when `false`, AS stays on the same line as the last option clause.
|
||||
- Golden file `testdata/corpus/test_a.pgsql` updated to reflect aligned params.
|
||||
|
||||
@@ -221,7 +221,9 @@ as a proxy (new_line for content, inline for single-arg subexpressions).
|
||||
|
||||
- `plpgsql_max_blank_lines`: blank-line runs capped at the configured limit; default `1`.
|
||||
- `plpgsql_declare_align_type` + `plpgsql_declare_align_eq`: two-pass declare formatter
|
||||
measures name/type widths then pads for alignment; `writeDeclareAligned` helper.
|
||||
measures name/type widths then pads for alignment; `writeDeclareAligned` helper. Both
|
||||
default `true` (house style). The `=` column is padded only to the widest type among
|
||||
declarations that actually carry an assignment, so a lone `x text = '…';` stays tight.
|
||||
- `plpgsql_if_then_newline`: when `false`, `joinThenToCondition` merges THEN onto the
|
||||
preceding condition line.
|
||||
- `plpgsql_loop_collapse`: `tryCollapseLoop` detects empty FOR/WHILE loop bodies and
|
||||
|
||||
Reference in New Issue
Block a user