Repository navigation
Conversation
…rinting an array `has_comment_inside_unary` consumed the first comment after the element it was checking, so a comment inside a later signed number (`-(/* c */ 3)`) was already gone when that element was checked, and the array was fill-printed. Peek at the comment instead of consuming it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Merging this PR will not alter performance
Comparing Footnotes
|
Member
|
Thanks, this will also be fixed by #28169. |
graphite-app Bot
pushed a commit
that referenced
this pull request
Oct 26, 2026
…28169) Closes #28104. `can_concisely_print_array_list` shared one cursor-based comments iterator across elements. Checking an element consumed the comments of later ones, so a comment inside a later signed number was missed and the array fill-printed on the second pass. - Check each element with the position-based `has_any_comment_in_range`, and the trailing line comment check with `all_comments_in_range` over the array - Layout decisions use the position-based queries, see `crates/oxc_formatter/AGENTS.md` - `js/arrays/numbers-negative-comment-after-minus.js` is now idempotent
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.
js/arrays/numbers-negative-comment-after-minus.jsis in the "Not idempotent" list of the Prettier conformance report. Pass 1 prints one element per line, and pass 2 fill-prints the array, because a comment inside a signed number is missed unless that number is the first one checked.can_concisely_print_array_listshares one comments iterator across the elements.has_comment_inside_unarytakes comments from it until the first one that starts after the current unary, then returns whether that comment is inside it. When it is not, the comment is already consumed, so the later element that does contain it sees the next comment instead:In the conformance file, pass 1 is saved by the separate "line comment on the same line" check (
-// comment1). Pass 1 moves that comment onto its own line inside-(...), so on pass 2 onlyhas_comment_inside_unarycould catch it.The iterator is now
Peekable: comments that start before the current unary are skipped, and the next one is only peeked at.Tests:
js/arrays/concise-unary-comment.js; it fails onmain, and its output is identical to Prettier 3.9.10 (the pinned version) at both option sets and stable on a second pass.numbers-negative-comment-after-minus.jsdrops out of the "Not idempotent" list inconformance__prettier-js.snap; no other conformance change.cargo test -p oxc_formatter --all-features,cargo fmt --check,just lint -p oxc_formatter(clippy with warnings denied) andtypospass.AI disclosure: this PR (code, tests and description) was written with Claude Code (Claude Opus 5.5); the verification above is what was run.