Skip to content

Comments

fix(formatter): Fix line comment after : inside ternary JSX#16315

Merged
graphite-app[bot] merged 1 commit intomainfrom
12-01-fix_formatter_fix_jsx_ternary_line_comment_after_
Dec 1, 2025
Merged

fix(formatter): Fix line comment after : inside ternary JSX#16315
graphite-app[bot] merged 1 commit intomainfrom
12-01-fix_formatter_fix_jsx_ternary_line_comment_after_

Conversation

@leaysgur
Copy link
Member

@leaysgur leaysgur commented Dec 1, 2025

Fixes #16258

@leaysgur leaysgur requested a review from Dunqing as a code owner December 1, 2025 02:15
@github-actions github-actions bot added A-formatter Area - Formatter C-bug Category - Bug labels Dec 1, 2025
Copy link
Member Author

leaysgur commented Dec 1, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 1, 2025

CodSpeed Performance Report

Merging #16315 will not alter performance

Comparing 12-01-fix_formatter_fix_jsx_ternary_line_comment_after_ (5931c84) with main (decf2ad)

Summary

✅ 38 untouched
⏩ 7 skipped1

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.

@leaysgur leaysgur changed the title fix(formatter): Fix jsx ternary line comment after : fix(formatter): Fix line comment after : inside ternary JSX Dec 1, 2025
@Dunqing
Copy link
Member

Dunqing commented Dec 1, 2025

Handling comments is complicated, so I will take a careful look.

@graphite-app graphite-app bot changed the base branch from 12-01-fix_formatter_add_parens_for_new_private_field_expr to graphite-base/16315 December 1, 2025 03:20
@graphite-app graphite-app bot force-pushed the 12-01-fix_formatter_fix_jsx_ternary_line_comment_after_ branch from 6223678 to cffca8c Compare December 1, 2025 03:27
@graphite-app graphite-app bot force-pushed the graphite-base/16315 branch from a1f7bec to ac8fcaf Compare December 1, 2025 03:27
@graphite-app graphite-app bot changed the base branch from graphite-base/16315 to main December 1, 2025 03:27
@graphite-app graphite-app bot force-pushed the 12-01-fix_formatter_fix_jsx_ternary_line_comment_after_ branch from cffca8c to a0624a8 Compare December 1, 2025 03:27
@leaysgur
Copy link
Member Author

leaysgur commented Dec 1, 2025

Yes, I just appreciate. 🙏🏻

Copilot AI review requested due to automatic review settings December 1, 2025 10:01
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes formatting of line comments appearing after the : operator in ternary expressions within JSX elements. The fix addresses issue #16258 where such comments were not being handled correctly by the formatter.

Key changes:

  • Unified comment handling logic for JSX elements and fragments
  • Refactored conditional expression formatting to improve code clarity

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
crates/oxc_formatter/src/write/jsx/element.rs Simplified format_trailing_comments to use end_of_line_comments_after uniformly for non-arrow function cases
crates/oxc_formatter/src/utils/conditional.rs Refactored format_test to compute span values outside the formatting closure for better readability
crates/oxc_formatter/tests/fixtures/js/jsx/ternary-with-comment.jsx Added test case for nested ternary with comment after : operator
crates/oxc_formatter/tests/fixtures/js/jsx/ternary-with-comment.jsx.snap Updated snapshot with expected formatting output for new test case

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Dunqing
Copy link
Member

Dunqing commented Dec 1, 2025

I found out that this should be fixed on the JSX side, and I re-implemented it. Please take a look!

@leaysgur leaysgur added the 0-merge Merge with Graphite Merge Queue label Dec 1, 2025
Copy link
Member Author

leaysgur commented Dec 1, 2025

Merge activity

@graphite-app graphite-app bot force-pushed the 12-01-fix_formatter_fix_jsx_ternary_line_comment_after_ branch from 5931c84 to 7b7acef Compare December 1, 2025 12:26
@leaysgur
Copy link
Member Author

leaysgur commented Dec 1, 2025

Thank you so much...! (I never thought of that. 🤯)

@graphite-app graphite-app bot force-pushed the 12-01-fix_formatter_fix_jsx_ternary_line_comment_after_ branch from 7b7acef to 5ad5435 Compare December 1, 2025 12:29
@graphite-app graphite-app bot merged commit 5ad5435 into main Dec 1, 2025
20 checks passed
@graphite-app graphite-app bot deleted the 12-01-fix_formatter_fix_jsx_ternary_line_comment_after_ branch December 1, 2025 12:35
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Dec 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-formatter Area - Formatter C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

formatter: Diff with Prettier on comment after : ternary operator with jsx

2 participants