Repository navigation
fix(prettier): break parameter lists, type arguments, patterns, tuples, objects, and import attributes like Prettier (#324, #351, #315, #314, #311, #341, #276) - #367
Merged
Conversation
Closed
1 task done
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.
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.
leonidaz
marked this pull request as ready for review
September 25, 2026 00:16
…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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…attern layout (#315) 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]>
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
force-pushed
the
fix/prettier-brackets-324
branch
from
September 25, 2026 00:52
ac8f36c to
bdff943
Compare
This was referenced Sep 25, 2026
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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.
method(aaa…: string, bbb…: number): void {}in a class, past the print widthconstructor(private readonly a: string, public b: number) {}interface I { m(aaa…, bbb…): void; (aaa…): void; new (aaa…): I },let fn: (aaa…, bbb…) => voida as unknown as Aaa…<Bbb>past the print width<,Bbb,>on three lines<Bbb>stays on the lineconst [aaa…, bbb…, ccc…] = useThing();,let t: [Aaa…, Bbb…, Ccc…]const o = { a: 1,+b: 2 };const o = { a: 1, b: 2 };objectWrap: "collapse"const { a, b } = obj;withbracketSpacing: false{ a, b }{a, b}(also type literals and mapped types)type P = { +readonly [K in keyof T]+?: T[K] };+droppedlet c: {+// note+[K in keyof T]: T[K];+} = x;const a = [/* pending */];const a = []; /* pending */const a = [+// pending+];const a = [];+// pendingimport a from "./a.json" assert { type: "json" };withimport b from "./b" with {};import b from "./b";import d from "./d" with { type: "json", integrity: "sha384-…" };past the print widthconst { aaaa, bbbb: cccc, dddd = 1 } = getOptions(aaa…, bbb…, ccc);past the print width<div title="…" alt="…">xxxxx yyyyy zzz… {"x"}</div>past the print widthChanges
printMethodValue,TSMethodSignaturethrough a port ofprintMethodSignature, and call signatures, construct signatures, function types, and constructor types through a port ofprintFunctionType. All of them now useprintFunctionParametersandshouldGroupFunctionParameters. TypeScript signatures keep their parameters inparametersand their return type intypeAnnotation, sogetFunctionParameters,iterateFunctionParametersPath, andhasRestParameterreadparameterstoo, andshouldGroupFunctionParametersreads the return type from either key (Prettier'sgetReturnTypeNode). A class method's type parameters live on the method, not its value, so they're passed in.shouldBreakFunctionParametersbreaks a constructor with more than one parameter and a parameter property.shouldHugTheOnlyFunctionParameteralso hugs({ a, b } = {}), as Prettier does. The six hand-written', 'loops are gone.printTSTypeParameterInstantiationports theshouldInlinerule of Prettier'sprintTypeParameters: a lone type thatshouldHugTypeaccepts (a keyword type, a type name without type arguments, an object type, or a hugged union) prints inline with no group, except in the type of an arrow function variable or next to a line comment. Other lists break without a trailing comma.printTSUnionTypenow prints a hugged union ({ … } | null,Foo | void) inline, likeprintUnionType.printArrayExpressionbecameprintArrayand also printsArrayPatternandTSTupleType, as Prettier'sprintArraydoes. A rest element at the end of a pattern gets no trailing comma, and a pattern's?and type annotation print after the brackets.printArrayPatternandprintTSTupleTypeare gone.printObjectExpressionandprintObjectPatternbecame one port of Prettier'sprintObject. UnderobjectWrap: "preserve"an object stays expanded only when the source has a line break between{and its first property, and"collapse"is honored. A pattern breaks when it destructures a nested pattern, except in a parameter list, and a hugged only parameter's pattern prints without its own group. A blank line after a property is kept (isNextLineEmpty), and patterns followbracketSpacing.printTSTypeLiteraltakes the sameobjectWraprule from Prettier'sprintClassBody, followsbracketSpacing, and leaves the type of a hugged only parameter ungrouped, so({ a, b }: { a: A; b: B })breaks both braces together. The source-based "originally multi-line" rule is also gone fromprintTSUnionType: only a member whose doc must break breaks the union. Without that, a type literal that now collapses left its union broken on the first pass and joined on the second.printTSMappedTypeportsprintTypeScriptMappedType: it breaks, followsbracketSpacingandobjectWrap, keeps+readonlyand+?, and prints a comment after{, which the parser attaches to the type parameter and which used to be deleted.packages/tsrx/src/parse/index.js, an emptyArrayExpression,ArrayPattern,ObjectExpression, orObjectPatternkeeps the comments between its brackets asinnerComments, like an empty block. Only comments that start inside the literal count: a comment before it that's still queued belongs to an enclosing element's attribute, which the walker visits after the children ([Bug]: A comment in a JSX attribute sends later child comments to the closing tag #301). The printers use a port ofprintDanglingCommentsInList: block comments stay inline, a line comment breaks the literal.with { … }that ignores bracketSpacing #341).printImportAttributesports Prettier's function of the same name. The keyword (withorassert) comes from the source text after the module source, an emptywith {}is kept, and the attributes print throughprintObject(withproperty = 'attributes'), sobracketSpacing,objectWrap, breaking, and the trailing comma apply. A lonetypeattribute goes throughremoveLines(isSingleTypeImportAttributes).printJsxElementInternal, it now chooses between the one-line layout and the multi-line layout withconditionalGroup, so the first pass prints the multi-line layout. The multi-line layout moved intoprintMultilineJSXChildren.printObject, an object pattern in a variable declarator or assignment prints without its own group unless it must break, so the assignment printer (printAssignment, fix(prettier): lay out assignments, arrow functions, and call arguments like Prettier (#340, #332, #316, #337, #335, #336, #325, #326, #298) #383) decides: thebreak-lhslayout of a complex destructuring breaks the pattern first, and the other layouts group it.printFunctionParameterstakes Prettier's argument order,(path, options, print, shouldExpandParameters, shouldPrintTypeParameters): fix(prettier): lay out assignments, arrow functions, and call arguments like Prettier (#340, #332, #316, #337, #335, #336, #325, #326, #298) #383's hugged-argument branch (removeLinesForHug,ArgExpansionBailout) also covers the type parameters, and its test-call branch prints them. Members of a type literal print their own;(fix(prettier): lay out blank lines, switch cases, member lists, empty bodies, and for headers like Prettier (#344, #328, #330, #304, #318, #317, #329, #331, #281, #321) #370'sprintTypeMemberSemicolon);printTSTypeLiteraljoins them withlinethrough fix(prettier): lay out blank lines, switch cases, member lists, empty bodies, and for headers like Prettier (#344, #328, #330, #304, #318, #317, #329, #331, #281, #321) #370'sprintTypeMembers, which gained an optional separator (hardlineby default, as interfaces use).isSimpleType,shouldHugUnionType, andprintCommentTextcome from fix(prettier): lay out assignments, arrow functions, and call arguments like Prettier (#340, #332, #316, #337, #335, #336, #325, #326, #298) #383 and fix(prettier): lay out blank lines, switch cases, member lists, empty bodies, and for headers like Prettier (#344, #328, #330, #304, #318, #317, #329, #331, #281, #321) #370; this PR addsshouldHugType. A call or construct signature prints throughprintFunctionTypefollowed byprintTypeMemberSemicolon.website-tsrx/src/components/compiler-demo.tsrxhad a long array destructuring pattern; it now breaks one element per line, as Prettier prints it.Output differences from Prettier that remain
breaks long logical arrow bodies after multiline type-literal paramstest keeps its extra indentation: [Bug]: Formatter indents the continuation line of a broken binary or logical expression where Prettier doesn't #334.lib.es2017.object.d.ts'sgetOwnPropertyDescriptors): its second pass keeps the literal expanded underobjectWrap: "preserve"and rejoins the parameters. This branch prints the same two passes as Prettier. No test covers it.printTSTypeParameterInstantiationdoesn't port the test-call case of Prettier'sshouldInline(type arguments ofit<T>(…)inline whatever their shape).Verification
Rebased on
mainafter #370 and #383 merged (24df857).pnpm vitest run --project prettier-plugin --project tsrx-utils: 1815 pass, including 45 new tests. 37 of them fail withmain's printer and parser; the other 8 pin layouts that already matched or that Prettier also prints (short signatures, type argument lists Prettier also breaks, a lone array type argument, a blank line after an object property, an element with mixed children that fits, a comment kept for a template attribute). Three existing tests changed to Prettier's output: a constructor with parameter properties now breaks,+readonly/+?keep their+, and the type of a hugged arrow parameter collapses. The plugin'sformathelper also checks that a second pass changes nothing.tsrx-react,tsrx-preact,tsrx-solid,tsrx-vue,tsrx-hono,tsrx-analyze,eslint-parser,eslint-plugin,typescript-plugin,language-server,tsrx-mcp, andwebsite(3477 pass; atypescript-plugintest that spawnstsccan hit its 5-second timeout under load and passes when run alone).tsgopasses forpackages/prettier-pluginandpackages/tsrx(with its tests), as dopnpm format:check(including all tracked.tsrxfiles) andpnpm changeset:check..tsand.d.tsfiles innode_modules, chosen because they contain a method, signature, or function type (1495), type arguments (1459), an array pattern or tuple (1470), or an object, pattern, type literal, or mapped type (1489), withmain's plugin (after fix(prettier): lay out blank lines, switch cases, member lists, empty bodies, and for headers like Prettier (#344, #328, #330, #304, #318, #317, #329, #331, #281, #321) #370 and fix(prettier): lay out assignments, arrow functions, and call arguments like Prettier (#340, #332, #316, #337, #335, #336, #325, #326, #298) #383), this branch's, and Prettier'stypescriptparser. 3356 matched Prettier onmainand 4397 here (1041 fixed, none regressed). WithbracketSpacing: false,objectWrap: "collapse", andtrailingComma: "es5", it's 2755 and 4431 (1676 fixed, none regressed).maineither: nine move JSDoc comments out of a call's type arguments ([Bug]: prettier-plugin: A comment in a call's type arguments attaches to the first call argument #389, filed here), and one has a comment in an unbracediftest ([Bug]: A comment that starts an unbraced if or loop body moves into the condition and drops JSDoc casts #296/[Bug]: Formatter moves comments out of if, while, and switch tests, dropping JSDoc casts and breaking @if #299). The eleventh is thegetOwnPropertyDescriptorscase above, where Prettier isn't idempotent either and this branch prints the same two passes.Related findings
Filed during this work. #361 and #362 are fixed here; the others are left for later:
{ … }, dropped+modifiers, and deleted a comment after{.bracketSpacing.printJsxElementreformats most templates and needs a decision on the parentheses.extendsandimplementsclauses of classes and interfaces never break.🤖 Generated with Claude Code