Skip to content

fix(prettier): break parameter lists, type arguments, patterns, tuples, objects, and import attributes like Prettier (#324, #351, #315, #314, #311, #341, #276) - #367

Merged
leonidaz merged 14 commits into
mainfrom
fix/prettier-brackets-324
Sep 25, 2026

Conversation

@leonidaz

@leonidaz leonidaz commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Closes #324
Closes #351
Closes #315
Closes #314
Closes #311
Closes #341
Closes #276
Closes #361
Closes #362
Closes #382

Summary

Bracketed lists now break the way Prettier breaks them: the parameters of class methods, TypeScript signatures, and function types; type arguments; array patterns and tuple types; objects, type literals, and mapped types; and import attributes. Comments in empty arrays and objects stay inside the brackets, and an element with mixed text and expression children takes its final layout on the first pass.

Input Before Now
method(aaa…: string, bbb…: number): void {} in a class, past the print width one line, however long one parameter per line with a trailing comma
constructor(private readonly a: string, public b: number) {} one line always one parameter per line, as in Prettier
interface I { m(aaa…, bbb…): void; (aaa…): void; new (aaa…): I }, let fn: (aaa…, bbb…) => void one line each parameters broken like a function's
a as unknown as Aaa…<Bbb> past the print width <, Bbb, > on three lines <Bbb> stays on the line
const [aaa…, bbb…, ccc…] = useThing();, let t: [Aaa…, Bbb…, Ccc…] one line one element per line
const o = { a: 1, + b: 2 }; expanded over four lines const o = { a: 1, b: 2 };
any object with objectWrap: "collapse" option ignored collapses when it fits
const { a, b } = obj; with bracketSpacing: false { a, b } {a, b} (also type literals and mapped types)
a mapped type past the print width one line broken like Prettier's
type P = { +readonly [K in keyof T]+?: T[K] }; + dropped unchanged
let c: { + // note + [K in keyof T]: T[K]; + } = x; comment deleted unchanged
const a = [/* pending */]; const a = []; /* pending */ unchanged
const a = [ + // pending + ]; const a = []; + // pending unchanged
import a from "./a.json" assert { type: "json" }; with unchanged
import b from "./b" with {}; import b from "./b"; unchanged
import d from "./d" with { type: "json", integrity: "sha384-…" }; past the print width one line one attribute per line
const { aaaa, bbbb: cccc, dddd = 1 } = getOptions(aaa…, bbb…, ccc); past the print width the call's arguments break, the pattern stays on the line the pattern breaks first, like Prettier
<div title="…" alt="…">xxxxx yyyyy zzz… {"x"}</div> past the print width pass 1 breaks the attributes, pass 2 joins them and moves the children pass 1 prints what pass 2 prints

Changes

Output differences from Prettier that remain

Verification

Rebased on main after #370 and #383 merged (24df857).

Related findings

Filed during this work. #361 and #362 are fixed here; the others are left for later:

🤖 Generated with Claude Code

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

Bugbot Autofix is ON. A cloud agent has been kicked off to fix the reported issues. You can view the agent here.

Reviewed by Cursor Bugbot for commit 5173e7d. Configure here.

Comment thread packages/prettier-plugin/src/index.js Resolved
Comment thread packages/prettier-plugin/src/index.js Resolved
@leonidaz
leonidaz marked this pull request as ready for review September 25, 2026 00:16
leonidaz and others added 14 commits September 24, 2026 20:48
…atures, and function types (#324)

Class and object methods print through a port of Prettier's
printMethodValue, and call, construct, function, and constructor types
through printFunctionType, so every parameter list goes through
printFunctionParameters. A constructor with parameter properties and more
than one parameter always breaks, like Prettier.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…351)

Port the shouldInline rule of Prettier's printTypeParameters to type
arguments: a lone keyword type, type name without type arguments, object
type, or hugged union prints inline with no group, except in the type of
an arrow function variable or next to a line comment. A hugged union
(`{ ... } | null`) prints inline like Prettier's printUnionType.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ls (#315)

ArrayPattern and TSTupleType print through the ported printArray, as in
Prettier, so they break one element per line when they don't fit. A rest
element at the end of a pattern gets no trailing comma, and a pattern's
optional marker and type annotation print after the brackets.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s like Prettier (#314, #361, #362)

Object literals and object patterns print through a port of Prettier's
printObject: under objectWrap "preserve" an object stays expanded only
when a line break follows its {, a pattern breaks when it destructures a
nested pattern outside a parameter list, and bracketSpacing applies to
patterns too. Type literals follow the same objectWrap rule, and the type
of a hugged only parameter breaks with the parameter list. Mapped types
port printTypeScriptMappedType, so they break, follow bracketSpacing and
objectWrap, keep + modifiers, and keep a comment after {. A destructured
parameter with a trivial default hugs its parentheses.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
#311)

Like an empty block, an empty array or object literal (or pattern) keeps
the comments between its brackets as innerComments, instead of letting
them trail the literal. Only comments inside the literal count: a queued
comment before it belongs to an enclosing element's attribute.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…brackets (#311)

Port Prettier's printDanglingCommentsInList for empty arrays, objects,
and their patterns: a block comment stays inline between the brackets,
and a line comment breaks the literal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…keyword (#341)

Port Prettier's printImportAttributes: the keyword (with or assert) comes
from the source, an empty `with {}` is kept, and the attributes print
through printObject, so bracketSpacing, objectWrap, breaking, and the
trailing comma apply. A lone type attribute never breaks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…en the same way on every pass (#276)

An element written on one line with text and simple expression children
now chooses, like Prettier's printJsxElement, between the one-line layout
and the multi-line layout with a conditionalGroup. When it doesn't fit,
the first pass prints the children on their own lines, which is what the
second pass printed, instead of breaking only the attributes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A union used to break whenever a member spanned lines in the source. Now
that type literals collapse like Prettier's, that rule made the first pass
break a union that the second pass joined. Like Prettier, only a member
whose printed doc must break (an object type kept expanded by objectWrap)
breaks the union.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…#382)

Like Prettier's printObject, an object pattern on the left of a variable
declarator or assignment prints without its own group unless it must
break, so printAssignment decides: the break-lhs layout of a complex
destructuring breaks the pattern first, and the other layouts group it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… array type arguments

Prettier 3.9.6 expands an object pattern that destructures a nested
pattern among the parameters of a function type, declared function, or
signature, because printObject only skips the break for functions with a
body. It also breaks the brackets around a lone array type argument, which
isSimpleType doesn't accept. Pin both layouts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@leonidaz
leonidaz force-pushed the fix/prettier-brackets-324 branch from ac8f36c to bdff943 Compare September 25, 2026 00:52
@leonidaz
leonidaz merged commit e404adf into main Sep 25, 2026
8 checks passed
@leonidaz
leonidaz deleted the fix/prettier-brackets-324 branch September 25, 2026 00:59
leonidaz added a commit that referenced this pull request Sep 25, 2026
…al test

#367 collapsed the parameter type in this test's expected output but kept the
old indented operands; Prettier 3.9.6 lines them up under the first one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
leonidaz added a commit that referenced this pull request Sep 25, 2026
…plate expressions and member chains like Prettier (#352, #347, #334, #348, #349, #346, #280, #297, #350) (#387)

* fix(prettier): lay out binary, logical, conditional, sequence and template expressions like Prettier (#352, #347, #334, #348, #349, #346, #280, #297)

- Parenthesize a logical operand of a different logical operator (#352).
- Port printBinaryishExpression(s): flatten same-precedence chains so every
  operator of a level breaks together (#347), and decide the continuation
  indent from the parent like Prettier, including the break after `(` under
  a unary operator, a member object and a callee (#334).
- Wrap a broken binary or logical return/throw argument in parentheses
  (#348) and lay out while / do-while conditions like if, keeping a negated
  logical condition on the keyword line (#349).
- Port printSequenceExpression's three layouts (#346).
- Port Prettier's ternary printer so a nested chain prints in one group
  (#280).
- Keep a template literal expression written on one line on one line, and
  align expressions from the template line they start on (#297).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(prettier): break method-call chains at the dots like Prettier (#350)

Port Prettier's printMemberChain: a call on a member lookup prints as a
chain of `.name(arguments)` groups, on one line when it is short or fits
with simple arguments, and otherwise with one group per indented line,
keeping a factory, `this` or short statement head on the first line. Port
printMemberExpression's softline before a lookup in a long chain of
property accesses, and printUnaryExpression's parentheses around an operand
with comments, which the binaryish port relies on.

Reformats three runtime test files whose `.map(…).join(…)` chains now break
like Prettier.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(prettier): keep Prettier's exact negated-condition rule (#349)

Only a comment on the condition itself keeps a negated logical condition
off the keyword line, as in Prettier's shouldInlineCondition.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* chore: add changeset for the expression layouts

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(prettier): keep each line comment of a member chain after its call (#379)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(prettier): finish the binary indent and member chains on the assignment layouts (#334, #350)

With printAssignment in place, an assignment expression, class field and
object property break after `=` or `:` before a binary or logical value, so
the value's operands line up there as in Prettier's shouldIndentIfInlining.

Calls go through printCallExpression, which keeps a test call, a require of
one module, an AMD definition and a lone template argument out of the
member chain, as Prettier's printCallExpression does, sharing that check
with printCallArguments (keepsArgumentsOnCallLine).
isPoorlyBreakableMemberOrCallChain reads the member chain's `memberChain`
label, as Prettier does, instead of a second copy of the chain grouping.
Drop the helpers both ports added (isBinaryish, shouldInlineLogicalExpression,
isLongCurriedCallExpression, isSimpleCallArgument, stripChainElementWrappers).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(prettier): pin Prettier's commented unary operands and non-null chains

Cursor Bugbot flagged both as bugs; Prettier 3.9.6 prints them the same way.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(prettier): line up a logical arrow body in the hugged type-literal test

#367 collapsed the parameter type in this test's expected output but kept the
old indented operands; Prettier 3.9.6 lines them up under the first one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment