-
-
Notifications
You must be signed in to change notification settings - Fork 715
fix(formatter): correct printing trailing comments for if statement with non-block consequent #14857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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 the formatting of trailing comments for if statements with non-block consequents. The formatter previously incorrectly handled trailing comments when they followed certain punctuation characters, causing issues with if statements that have simple expressions or empty statements as their consequent.
Key changes:
- Modified comment position detection logic to handle
=and:characters - Added test cases for if statements with trailing comments
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/oxc_formatter/src/formatter/comments.rs | Updated byte-matching logic to include = and : characters when detecting comment positions |
| crates/oxc_formatter/tests/fixtures/js/comments/if.js | Added test input with if statements containing trailing comments |
| crates/oxc_formatter/tests/fixtures/js/comments/if.js.snap | Added expected output snapshot for the test cases |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
CodSpeed Performance ReportMerging #14857 will not alter performanceComparing Summary
Footnotes
|
Merge activity
|
c9d4b51 to
4a499b5
Compare
## [0.8.0] - 2025-10-22 ### 🚀 Features - 381e08c oxfmt: More friendly JSON schema (#14879) (leaysgur) - 006708d oxfmt: Support `ignorePatterns` in oxfmtrc (#14875) (leaysgur) ### 🐛 Bug Fixes - 64b8226 formatter: Corrct printing leading own line comments before method body (#14886) (Dunqing) - 6ce1162 formatter: Remove a redundant space for TSMappedType (#14885) (Dunqing) - 5b962a7 formatter: Remove redundant leading space when only the rest part of the array exists (#14884) (Dunqing) - 8301d8f formatter: No need to wrap parenthesis for ObjectExpression when it is an expression of a template literal (#14883) (Dunqing) - 9397472 formatter: Should not wrap parenthesis for ComputedMemberExpression when it is not an option or it doesn't contain a call expression (#14882) (Dunqing) - 3e62277 formatter: Should not add a soft line for the arrow function inside ExpressionContainer with a trailing comment (#14878) (Dunqing) - 990916a formatter: Correct handling of leading own line before arrow function body (#14877) (Dunqing) - 4a499b5 formatter: Correct printing trailing comments for if statement with non-block consequent (#14857) (Dunqing) ### 🧪 Testing - 868ff99 formatter: Fix tests using TS syntax with `.js` (#14880) (leaysgur)

Regressed caused by #14816.