Skip to content

fix: break long throws clauses one exception per line - #1041

Open
JebKJ21 wants to merge 1 commit into
jhipster:mainfrom
JebKJ21:fix/throws-clause-breaking
Open

JebKJ21 wants to merge 1 commit into
jhipster:mainfrom
JebKJ21:fix/throws-clause-breaking

Conversation

@JebKJ21

@JebKJ21 JebKJ21 commented Sep 8, 2026

Copy link
Copy Markdown

What changed with this PR:

Long throws clauses previously could not break and overflowed printWidth
(default 80). The throws printer now uses a conditionalGroup:

  1. the whole exception list stays inline when it fits — no change to any
    currently-fitting output (full suite passes with only the overflowing
    cases regenerated), otherwise
  2. exceptions print one per line, with throws kept attached to the
    parameter list — matching the formatting sketched in
    Improve formatting of method will lot of parameters and with exception #286 (comment)

Example

Input

class T {
  public void test() throws ExceptionOne, ExceptionTwo, ExceptionThree, ExceptionFour, ExceptionFive, ExceptionSix {}
}

Output

class T {
  public void test() throws
    ExceptionOne,
    ExceptionTwo,
    ExceptionThree,
    ExceptionFour,
    ExceptionFive,
    ExceptionSix {}
}

Relative issues or prs:

Fixes #286, closes #429. Supersedes #591, which targets the pre-tree-sitter
codebase and can no longer merge.

Verification

  • All 226 unit tests pass; eslint, tsc, the self-format check, and a 5×
    idempotency run (update-test-output.js -times 5) are clean.
  • Two-pass idempotency holds on the java-design-patterns corpus pinned by
    the e2e suite (tag 1.25.0, 1508 files) under both the previous and the
    new build; exactly 2 of those files change, both the intended fix
    (overflowing 97/84-char throws lines → one exception per line).

Note for maintainers: the $100 / $$ bug-bounty $$ labels currently sit on
#591 rather than on #286/#429 — could you confirm bounty eligibility for this
fix per https://www.jhipster.tech/bug-bounties/?

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.

Continuation Indent Improve formatting of method will lot of parameters and with exception

1 participant