Skip to content

Fix unstable trailing comment on a parenthesized arrow chain - #19930

Merged
fisker merged 6 commits into
prettier:mainfrom
Kjubikstronk:registry-next
Aug 30, 2026
Merged

fisker merged 6 commits into
prettier:mainfrom
Kjubikstronk:registry-next

Conversation

@Kjubikstronk

Copy link
Copy Markdown
Contributor

Description

js/arrows/arrow-chain-with-trailing-comments.js is listed in failed-format-tests.js as unstable. This fixes it and removes the entry.

// Input
x2 = (a) => ((b) => {
  c();
} /* ! */ // K
)

// Prettier stable (first format)
x2 = (a) => (b) => {
  c();
} /* ! */; // K

// Prettier stable (second format)
x2 = (a) => (b) => {
  c();
}; /* ! */ // K

// Prettier main
x2 = (a) => (b) => {
  c();
}; /* ! */ // K

The parentheses around the inner arrow are redundant, so they are dropped. That leaves the comment sitting between } and the statement's semicolon, and the next format attaches it to the ExpressionStatement rather than to the arrow it was written against, so it prints on the other side of the semicolon.

handleParenthesizedExpressionTrailingComment already handles the same situation for a nested assignment (a = (b = c /* comment */)) by attaching the comment to the statement immediately instead of leaving it for the next format to move. This extends that to a chain that passes through arrow bodies, so the first format produces what the second one would.

Checklist

  • I’ve added tests to confirm my change works.
  • (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory).
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.
  • I did not use AI to generate this PR.
  • (If the above is not checked) I have reviewed the AI-generated content before submitting.

No new test is added because the fixture already exists; it was listed as unstable rather than passing, and that entry is now removed. Verified with the full tests/format/js, typescript, jsx and flow suites: the set of failing tests is identical to main on my machine, with the arrows snapshot updated to the second-pass output. I used AI assistance and reviewed everything before submitting.

`x = (a) => ((b) => {} /* comment */)` printed the comment before the
semicolon on the first pass and after it on the second, so the file never
settled.

The parentheses are redundant, so they are dropped. That moves the comment
next to the statement's semicolon, where the next format attaches it to the
ExpressionStatement instead of to the arrow it was written against. The same
thing happens with a nested assignment, which is already handled by attaching
the comment to the statement up front; this extends that to a chain that
passes through arrow bodies.
@netlify

netlify Bot commented Aug 28, 2026

Copy link
Copy Markdown

✅ Deploy Preview for prettier ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 7018480
🔍 Latest deploy log https://app.netlify.com/projects/prettier/deploys/6a9186fb86ab9a00088eea4d
😎 Deploy Preview https://deploy-preview-19930--prettier.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@pkg-pr-new

pkg-pr-new Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

yarn add https://pkg.pr.new/@prettier/[email protected]
yarn add https://pkg.pr.new/@prettier/[email protected]
yarn add https://pkg.pr.new/@prettier/[email protected]
yarn add https://pkg.pr.new/[email protected]

commit: 6475ed0

@netlify

netlify Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for prettier ready!

Name Link
🔨 Latest commit 6475ed0
🔍 Latest deploy log https://app.netlify.com/projects/prettier/deploys/6a9436959c53a60008b407a4
😎 Deploy Preview https://deploy-preview-19930--prettier.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Comment on lines 1258 to 1260
// `a = (b = c /* comment */);` drops the parentheses, so the comment ends
// up trailing the whole statement anyway. Attach it there right away
// instead of leaving it on `c` for the next format to move.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

reviewed everything before submitting.

Did you actually review the changes? The comment is obviously not in the right place.

@Kjubikstronk

Copy link
Copy Markdown
Contributor Author

You're right, I missed it. That comment explains the assignment case and I left it sitting above the arrow check. It's now above the if it actually describes, and says both shapes.

@fisker
fisker merged commit 5a0fdd9 into prettier:main Aug 30, 2026
35 checks passed
kkennethlau12393 pushed a commit to kkennethlau12393/prettier__prettier that referenced this pull request Aug 31, 2026
kkennethlau12393 pushed a commit to kkennethlau12393/prettier__prettier that referenced this pull request Sep 1, 2026
kkennethlau12393 pushed a commit to kkennethlau12393/prettier__prettier that referenced this pull request Sep 2, 2026
kkennethlau12393 pushed a commit to kkennethlau12393/prettier__prettier that referenced this pull request Sep 3, 2026
kkennethlau12393 pushed a commit to kkennethlau12393/prettier__prettier that referenced this pull request Sep 3, 2026
kkennethlau12393 pushed a commit to kkennethlau12393/prettier__prettier that referenced this pull request Sep 5, 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