Skip to content

fix(prettier): lay out JSDoc-cast operands, comments after =, and import() arguments like Prettier (#580, #582, #581, #553, #591, #597) - #605

Merged
leonidaz merged 6 commits into
mainfrom
fix/prettier-layout-casts-580
Sep 25, 2026
Merged

leonidaz merged 6 commits into
mainfrom
fix/prettier-layout-casts-580

Conversation

@leonidaz

@leonidaz leonidaz commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Closes #580
Closes #582
Closes #581
Closes #553
Closes #591
Closes #597

Summary

Logical and assigned values with JSDoc casts, comments after an =, and the arguments of import() now format like Prettier 3.9.6. Prettier's babel parser keeps a JSDoc cast's parentheses as a ParenthesizedExpression, so several layout checks that look at an operand's type now treat a cast operand as a node of its own. A block comment that ends the = line now takes Prettier's break-after-operator layout, and import() lays out its source and options with printCallArguments.

⏎ is a line break. Outputs use Prettier's default options; … shortens long names.

Input Before Now
x = aaa && /** @type {X} */ ({ aaa: 1, bbb: 2 }); (too long) x = aaa && /** @type {X} */ ({⏎ aaa: 1,⏎ bbb: 2,⏎}); x =⏎ aaa &&⏎ /** @type {X} */ ({ aaa: 1, bbb: 2 }); (Prettier)
const f = /** @type {…} */ (items || foo) ? foo : bar; const f =⏎ /** @type {…} */ (items || foo)⏎ ? foo⏎ : bar; const f = /** @type {…} */ (⏎ items || foo⏎)⏎ ? foo⏎ : bar; (Prettier)
x = /** @type {X} */ (aaa && bbb) && { aaa: 1, bbb: 2 }; the object's body indented one level too many … && {⏎ aaa: 1,⏎ bbb: 2,⏎}; (Prettier)
foo(/** @type {X} */ (aaa && bbb) && c); (the cast breaks) ) &&⏎ c, ) && c, (Prettier)
const test = /* note */⏎ goog.partial(…); (doesn't fit after the comment) const test = /* note */⏎ goog.partial(…); const test =⏎ /* note */⏎ goog.partial(…); (Prettier)
a = b = c = /* note */⏎ compute(…); c = /* note */ compute(…);, then c =⏎ /* note */ compute(…); on the next format c =⏎ /* note */⏎ compute(…); (Prettier)
await import("./long/…/module.js", options); runs past the print width await import(⏎ "./long/…/module.js",⏎ options⏎); (Prettier)
const p = import(⏎ // comment⏎ "./foo"⏎); const p = import(// comment⏎"./foo"); unchanged (Prettier)

Changes

Output differences from Prettier that remain

Verification

Related findings

Fixed here:

Filed separately:

🤖 Generated with Claude Code


Note

Low Risk
Changes are limited to print-layout docs in the Prettier plugin with broad new regression tests; no runtime or security behavior is affected, though formatted output will shift for the covered edge cases.

Overview
Formatting parity with Prettier 3.9.6 for JSDoc type casts, values after =/:, and dynamic import().

JSDoc cast parentheses are now treated like Prettier’s separate ParenthesizedExpression nodes in layout logic. hasTypeCastParens and an updated shouldInlineLogicalExpression (path-aware) stop inlining object/array/JSX on the right of &&/||/?? when they sit inside a cast, fix flattening/grouping for cast operands that share the parent operator, and make assigned conditionals with a cast binary/logical test break inside the cast instead of after =. printValueAfterLeadingComment follows Prettier’s break-after-operator rules (block comments on the operator line only when the value fits; otherwise comment and value move down) and defers to assignment chain layouts so chained = comments stay stable across re-formats.

ImportExpression printing now routes source/options through printCallArguments (like ordinary calls, no trailing comma), extends getCallArguments, isSimpleModuleImport, and keepsArgumentsOnCallLine for single-string import() / import.defer(), and preserves own-line comments before the module string.

Reviewed by Cursor Bugbot for commit 6889b56. Bugbot is set up for automated code reviews on this repo. Configure here.

leonidaz and others added 2 commits September 25, 2026 15:13
…ort() arguments like Prettier (#580, #582, #581, #553)

- shouldInlineLogicalExpression, the ConditionalExpression case of
  shouldBreakAfterOperator, and the JSX, same-precedence, and lone-operator
  checks of the binaryish printers treat an operand in JSDoc-cast parentheses
  as Prettier's ParenthesizedExpression (#580, #582, #597).
- printValueAfterLeadingComment prints a block comment that ends the `=`
  line in the break-after-operator layout, and leaves an assignment chain's
  value to the chain layouts (#581, #591).
- ImportExpression prints its source and options through printCallArguments,
  without a trailing comma, and a lone string source stays on the line
  (#553).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
leonidaz and others added 4 commits September 25, 2026 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment