Skip to content

Add --join-on-indent option to indent multi-keyword join ON clauses - #407

Merged
darold merged 2 commits into
darold:masterfrom
edjubert:fix/join-outer-indent
Sep 20, 2026
Merged

darold merged 2 commits into
darold:masterfrom
edjubert:fix/join-outer-indent

Conversation

@edjubert

@edjubert edjubert commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

What

Add a new option --join-on-indent that indents the ON clause continuation lines (AND/OR) of a multi-keyword join (e.g. LEFT OUTER JOIN) one level below the join keyword.

The option is off by default — the existing behavior is fully preserved.

Without the option (default, unchanged)

SELECT
    tyap.tyap_code
FROM
    tyap
    LEFT OUTER JOIN ab_frap appel ON appel.frap_tyap_code = tyap.tyap_code
    AND appel.frap_imme_no = tyap.tyap_imme_no

With --join-on-indent

SELECT
    tyap.tyap_code
FROM
    tyap
    LEFT OUTER JOIN ab_frap appel ON appel.frap_tyap_code = tyap.tyap_code
        AND appel.frap_imme_no = tyap.tyap_imme_no

Why

When a join is spelled with several keywords (LEFT OUTER JOIN, FULL JOIN, …), pgFormatter steps the indentation back once per keyword, so the ON clause continuation lines end up at the same level as the join keyword. Some style guides prefer the AND/OR continuation lines to be indented one level below the join keyword. This option provides that style without changing the default output.

Implementation

  • lib/pgFormatter/Beautify.pm: new join_on_indent option (POD, qw() list, set_defaults), and the join step-back condition now only skips the per-keyword step-back when the option is on.
  • lib/pgFormatter/CLI.pm: --join-on-indent CLI flag, config mapping, and help text.
  • t/test-files/ex85.sql + t/test-files/expected/ex85.sql: regression test covering LEFT OUTER JOIN, INNER/CROSS/NATURAL/RIGHT/FULL JOIN, and plain JOIN/LEFT JOIN, run with --join-on-indent.

Tests

  • prove -lv t/ passes (93 tests). The existing ex1.sql (which contains a LEFT OUTER JOIN … ON … AND …) still passes because the default behavior is unchanged.
  • Output is idempotent with the option enabled.

edjubert and others added 2 commits September 7, 2026 15:05
Add a new option --join-on-indent that indents the ON clause
continuation lines (AND/OR) of a multi-keyword join (e.g. LEFT OUTER
JOIN) one level below the join keyword.

By default the option is off and the existing behavior is preserved.

Without the option (default):
    LEFT OUTER JOIN ab_frap appel ON appel.frap_tyap_code = tyap.tyap_code
    AND appel.frap_imme_no = tyap.tyap_imme_no

With --join-on-indent:
    LEFT OUTER JOIN ab_frap appel ON appel.frap_tyap_code = tyap.tyap_code
        AND appel.frap_imme_no = tyap.tyap_imme_no
@darold
darold merged commit 24413b2 into darold:master Sep 20, 2026
0 of 4 checks passed
darold added a commit that referenced this pull request Sep 20, 2026
@darold

darold commented Sep 20, 2026

Copy link
Copy Markdown
Owner

@edjubert , commit 1b99e6e now apply this formatting as default so the option have been removed from your patch.

@edjubert
edjubert deleted the fix/join-outer-indent branch September 21, 2026 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants