Skip to content

fix(formatter): handle same-line comment after pipe in single-member union types#21824

Closed
babu-ch wants to merge 2 commits into
oxc-project:mainfrom
babu-ch:fix/21792-union-comment-after-pipe-same-line
Closed

fix(formatter): handle same-line comment after pipe in single-member union types#21824
babu-ch wants to merge 2 commits into
oxc-project:mainfrom
babu-ch:fix/21792-union-comment-after-pipe-same-line

Conversation

@babu-ch

@babu-ch babu-ch commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Closes #21792

@codspeed-hq

codspeed-hq Bot commented Apr 27, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 44 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing babu-ch:fix/21792-union-comment-after-pipe-same-line (0d060c8) with main (5fa4774)

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@babu-ch babu-ch force-pushed the fix/21792-union-comment-after-pipe-same-line branch from e795087 to 89f750e Compare April 27, 2026 06:58
@babu-ch babu-ch marked this pull request as ready for review April 27, 2026 07:12
@leaysgur

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

@Dunqing

Dunqing commented Apr 27, 2026

Copy link
Copy Markdown
Member

That is a suspicious issue that may be a bug in Prettier rather than in us, even though the output matched Prettier. Need to double-check in #18717

@babu-ch

babu-ch commented Apr 27, 2026

Copy link
Copy Markdown
Contributor Author

@Dunqing
It might be confusing, so shall we close it?

@Dunqing

Dunqing commented Apr 27, 2026

Copy link
Copy Markdown
Member

@Dunqing It might be confusing, so shall we close it?

Can you try to double-check first? I forgot half the issues I listed in that and just remembered that the union with comments case in Prettier is very buggy. 😅

@babu-ch

babu-ch commented Apr 27, 2026

Copy link
Copy Markdown
Contributor Author

Double-checked the union-related issues in #18717. This case doesn't appear to match any of them.

leaysgur added a commit that referenced this pull request Jun 22, 2026
…rmatting (#21915)

Fixes #21914, Fixes #21792, Supersedes #21824.

Tests for union type are taken from #21824.

### Comment printing

Changes to comment printing for single member union/intersection types
try to mimic:


https://github.com/prettier/prettier/blob/f5e3980c3085f6fb2b166c8e3f91e8db317d6eb2/src/main/comments/attach.js#L183-L190

Where own-line comments are leading, and:


https://github.com/prettier/prettier/blob/f5e3980c3085f6fb2b166c8e3f91e8db317d6eb2/src/main/comments/attach.js#L200-L206

Where end-of-line comments are trailing (note that this doesn't apply to
block comments, see
https://github.com/prettier/prettier/blob/870b6df76058cc6c1c23418524d0272141c50677/src/language-js/comments/handle-comments.js#L764),
and:


https://github.com/prettier/prettier/blob/f5e3980c3085f6fb2b166c8e3f91e8db317d6eb2/src/main/comments/attach.js#L324-L328

Where inline comments are leading if they're separated only by
whitespace, open parentheses or other comments from the node after them.
Because of that, current behavior is to consider inline comments
trailing if they're before the `&` or `|` symbol (as they can't be
leading, because `&` and `|` aren't whitespace).

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Yuji Sugiura <6259812+leaysgur@users.noreply.github.com>
@leaysgur

leaysgur commented Jun 22, 2026

Copy link
Copy Markdown
Member

Fixed by #21915 (Anyway, thank you for your assistance~!)

@leaysgur leaysgur closed this Jun 22, 2026
camc314 pushed a commit that referenced this pull request Jul 3, 2026
…rmatting (#21915)

Fixes #21914, Fixes #21792, Supersedes #21824.

Tests for union type are taken from #21824.

### Comment printing

Changes to comment printing for single member union/intersection types
try to mimic:


https://github.com/prettier/prettier/blob/f5e3980c3085f6fb2b166c8e3f91e8db317d6eb2/src/main/comments/attach.js#L183-L190

Where own-line comments are leading, and:


https://github.com/prettier/prettier/blob/f5e3980c3085f6fb2b166c8e3f91e8db317d6eb2/src/main/comments/attach.js#L200-L206

Where end-of-line comments are trailing (note that this doesn't apply to
block comments, see
https://github.com/prettier/prettier/blob/870b6df76058cc6c1c23418524d0272141c50677/src/language-js/comments/handle-comments.js#L764),
and:


https://github.com/prettier/prettier/blob/f5e3980c3085f6fb2b166c8e3f91e8db317d6eb2/src/main/comments/attach.js#L324-L328

Where inline comments are leading if they're separated only by
whitespace, open parentheses or other comments from the node after them.
Because of that, current behavior is to consider inline comments
trailing if they're before the `&` or `|` symbol (as they can't be
leading, because `&` and `|` aren't whitespace).

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Yuji Sugiura <6259812+leaysgur@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-formatter Area - Formatter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

formatter: Diff with Prettier on single member union type with comment after pipe on the same line

4 participants