Skip to content

feat: break long throws clauses one exception per line - #1097

Closed
devilking7x wants to merge 2 commits into
jhipster:mainfrom
devilking7x:fix-591-throws-breaking
Closed

devilking7x wants to merge 2 commits into
jhipster:mainfrom
devilking7x:fix-591-throws-breaking

Conversation

@devilking7x

@devilking7x devilking7x commented Oct 13, 2026 •

Copy link
Copy Markdown

Closes #591.

What

Long throws clauses now break one exception per line when they don't fit, instead of staying on one long line. When the clause breaks, the body { moves onto its own line — separating the throws clause from the body contents (the exact indentation-confusion case from #429).

This implements the #591 design: one exception per line when broken, { on its own line. Follows the Prettier TypeScript implements-clause precedent referenced in #591.

Implementation

  • throws printer uses a plain group — one line when it fits, one-exception-per-line when broken (verified byte-identical output vs conditionalGroup across all 86 unit-test fixtures; plain group avoids the construct flagged as last-resort in the fix: break long throws clauses one exception per line #1041 review)
  • method_declaration and constructor_declaration drop the body { to its own line only when throws breaks
  • Uses symbol group ids (prettier's types require symbol; fixes the tsc errors from string ids)

Testing

  • 226/226 unit tests pass, zero regressions
  • Output matches all 6 expected-output examples from feat: improve throws breaking #591 character-for-character
  • New edge-case coverage: single very long exception name, generic exception types, nested classes, interface methods, default methods with breaking throws clauses
  • ESLint clean, tsc clean, Prettier format check clean, 5× idempotency clean

When a throws clause with multiple exception types does not fit on one
line, break after the throws keyword with one exception per line, and
place the body block on its own line to separate it from the exceptions.

Closes jhipster#591
… tests

- Replace conditionalGroup with an equivalent plain group in the throws
  printer. Output is byte-identical across all 86 unit-test fixtures, and
  this avoids conditionalGroup, which Prettier documents as a last
  resort due to exponential complexity when nested.
- Use a shared Symbol for the throws group id instead of a string,
  fixing the tsc errors (prettier's types require symbol group ids).
- Add test coverage for uncovered edge cases: a single very long
  exception name, generic exception types, nested classes, interface
  methods and default methods with breaking throws clauses.

226/226 unit tests pass; eslint, tsc, prettier and 5x idempotency clean.
@devilking7x

Copy link
Copy Markdown
Author

Hi — following today's review discussion on #1041, I wanted to note that this PR implements the #591 design you described there: when a throws clause breaks, the exceptions print one per line and the body { moves onto its own line, separating the throws clause from the body contents (the exact indentation-confusion case from #429). This follows the Prettier TypeScript implements-clause precedent referenced in #591.

I verified the output against the expected output posted in #591 — all 6 examples format character-for-character identical.

The latest commit also: replaces conditionalGroup with an equivalent plain group (verified byte-identical output across all 86 unit-test fixtures), avoiding the construct flagged as last-resort in the #1041 review; fixes the tsc errors from string group ids (prettier's types require symbol); and adds test coverage for edge cases — a single very long exception name, generic exception types, nested classes, interface methods, and default methods with breaking throws clauses.

226/226 unit tests pass; eslint, tsc, prettier format check, and 5× idempotency all clean.

@jtkiesel

Copy link
Copy Markdown
Contributor

Closing in favor of #591.

@jtkiesel jtkiesel closed this Oct 15, 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