Sitelet https://github.com/darold/pgFormatter/pull/415
Skip to content

Add opt-in matching-parenthesis line breaks - #415

Merged
darold merged 3 commits into
darold:masterfrom
arnodirlam:codex/matching-paren-newline
Sep 20, 2026
Merged

darold merged 3 commits into
darold:masterfrom
arnodirlam:codex/matching-paren-newline

Conversation

@arnodirlam

@arnodirlam arnodirlam commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Proposal: #417.

I’d like to propose --matching-paren-newline to make the end of multiline lists and subqueries easier to spot.

When formatted content starts on a new line after (, the option puts the matching ) on its own line, aligned with the opening line. Each nested pair follows the same rule. It’s disabled by default, since this is a style preference.

INSERT column list (-B in both examples, all other formatting options at their defaults):

Before:

INSERT INTO widgets (
    id,
    label)
SELECT
    1,
    2;

With --matching-paren-newline:

INSERT INTO widgets (
    id,
    label
)
SELECT
    1,
    2;

Subquery (default formatting options):

Before:

SELECT
    id
FROM
    widgets
WHERE
    id IN (
        SELECT
            widget_id
        FROM
            archive);

With --matching-paren-newline:

SELECT
    id
FROM
    widgets
WHERE
    id IN (
        SELECT
            widget_id
        FROM
            archive
    );

Procedural condition with the option enabled:

DO $$
BEGIN
    IF (
        SELECT
            count(*)
        FROM
            widgets
    ) = 0 THEN
        PERFORM
            1;
    ELSE
        PERFORM
            2;
    END IF;
END
$$;

I ran prove -l t/ and the larger SQL corpus with perl t/regress_test.pl; both pass. The existing expected-output files stay unchanged with the option disabled. The new tests also check that repeated formatting is stable.

Would you be open to this option? I’d welcome your thoughts on the name and behavior. Feel free to close this PR if the option isn’t something you’d like to support.

@darold
darold merged commit 0f92cb0 into darold:master Sep 20, 2026
0 of 4 checks passed
darold added a commit that referenced this pull request Sep 20, 2026
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