Skip to content

fix: print attributes on anonymous classes one per line - #2526

Open
benjaminkincses wants to merge 1 commit into
prettier:mainfrom
benjaminkincses:fix/2437-anonymous-class-attributes
Open

benjaminkincses wants to merge 1 commit into
prettier:mainfrom
benjaminkincses:fix/2437-anonymous-class-attributes

Conversation

@benjaminkincses

Copy link
Copy Markdown
Contributor

Attributes on new anonymous classes were being collapsed onto a single line:

new #[Lazy] #[Computed] #[Title("Staff")] class extends Component {

This change prints each attribute group on its own line, matching how attributes on named classes are formatted, with new on its own line:

new
#[Lazy]
#[Computed]
#[Title("Staff")]
class extends Component {

The fix is in the anonymous-class path of the new printer in src/printer.mjs: it now uses the regular (non-inline) attribute printing instead of the inline variant. Attribute-less new class output is unchanged.

Test evidence: added a regression case to tests/attributes/attributes.php (the issue repro plus a single-attribute anonymous class); updated snapshot. Full jest suite passes: 101 suites, 595 tests, 579 snapshots.

Fixes #2437

Attributes on `new` anonymous classes were collapsed onto a single line
(`new #[Lazy] #[Computed] #[Title("Staff")] class ...`). Print each
attribute group on its own line, like named classes, with `new` on its
own line.

Fixes prettier#2437
@benjaminkincses
benjaminkincses marked this pull request as ready for review October 19, 2026 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant