Skip to content

feat: align parentheses closer with Prettier JS/TS, including their removal#944

Merged
jtkiesel merged 1 commit into
jhipster:mainfrom
jtkiesel:feat/parentheses
Jun 22, 2026
Merged

feat: align parentheses closer with Prettier JS/TS, including their removal#944
jtkiesel merged 1 commit into
jhipster:mainfrom
jtkiesel:feat/parentheses

Conversation

@jtkiesel

Copy link
Copy Markdown
Contributor

What changed with this PR:

Printing of parentheses is aligned much more closely with Prettier JS/TS, most notably, parentheses are removed similarly to Prettier JS/TS. Any ParenthesizedExpression nodes not required by their parent node (such as in IfStatement, SwitchExpression, etc.) are omitted from the syntax tree, similar to Prettier JS/TS, and only added if necessary to keep the logic identical, for compilation, or for readability, with rules kept as close to those defined in Prettier JS/TS as possible. Includes a few other random fixes by aligning more closely with Prettier JS/TS, such as the indentation alignment of nested ternaries and the placement of & in cast expressions with multiple bounds.

Example

Input

void f() {
    return (aaaaaaaaaa && bbbbbbbbbb);
}

void f() {
    return (aaaaaaaaaa && bbbbbbbbbb && cccccccccc
        ? dddddddddd
        : eeeeeeeeee
    ).ffffffffff();
}

aaaaaaaaaa
    ? bbbbbbbbbb
    : cccccccccc
        ? dddddddddd
        : eeeeeeeeee
            ? ffffffffff
            : gggggggggg;

(
    Aaaaaaaaaa
    & Bbbbbbbbbb
    & Cccccccccc
    & Dddddddddd
    & Eeeeeeeeee
    & Ffffffffff
) gggggggggg;

Output

void f() {
    return aaaaaaaaaa && bbbbbbbbbb;
}

void f() {
    return (
        aaaaaaaaaa && bbbbbbbbbb && cccccccccc ? dddddddddd : eeeeeeeeee
    ).ffffffffff();
}

aaaaaaaaaa
    ? bbbbbbbbbb
    : cccccccccc
      ? dddddddddd
      : eeeeeeeeee
        ? ffffffffff
        : gggggggggg;

(
    Aaaaaaaaaa &
    Bbbbbbbbbb &
    Cccccccccc &
    Dddddddddd &
    Eeeeeeeeee &
    Ffffffffff
) gggggggggg;

Relative issues or prs:

Closes #770
Closes #921

@jtkiesel jtkiesel merged commit c7fe22d into jhipster:main Jun 22, 2026
6 checks passed
@jtkiesel jtkiesel deleted the feat/parentheses branch June 22, 2026 02:21
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.9.7] Regression formatting return-statement with parentheses Needless parentheses around return

1 participant