Skip to content

Conversation

@Dunqing
Copy link
Member

@Dunqing Dunqing commented Oct 21, 2025

Regressed caused by #14816.

Copilot AI review requested due to automatic review settings October 21, 2025 13:38
@github-actions github-actions bot added the A-formatter Area - Formatter label Oct 21, 2025
Copy link
Member Author

Dunqing commented Oct 21, 2025

@github-actions github-actions bot added the C-bug Category - Bug label Oct 21, 2025
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 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-hq
Copy link

codspeed-hq bot commented Oct 21, 2025

CodSpeed Performance Report

Merging #14857 will not alter performance

Comparing 10-21-fix_formatter_correct_printing_trailing_comments_for_if_statement_with_non-block_consequent (c9d4b51) with main (f3b75c3)

Summary

✅ 33 untouched
⏩ 4 skipped1

Footnotes

  1. 4 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.

@graphite-app
Copy link
Contributor

graphite-app bot commented Oct 22, 2025

Merge activity

@graphite-app graphite-app bot force-pushed the 10-21-fix_formatter_correct_printing_trailing_comments_for_if_statement_with_non-block_consequent branch from c9d4b51 to 4a499b5 Compare October 22, 2025 07:34
@graphite-app graphite-app bot merged commit 4a499b5 into main Oct 22, 2025
20 checks passed
@graphite-app graphite-app bot deleted the 10-21-fix_formatter_correct_printing_trailing_comments_for_if_statement_with_non-block_consequent branch October 22, 2025 07:40
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Oct 22, 2025
@Boshen Boshen mentioned this pull request Oct 22, 2025
graphite-app bot pushed a commit that referenced this pull request Oct 22, 2025
## [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)
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.

2 participants