Skip to content

Conversation

@leaysgur
Copy link
Member

@leaysgur leaysgur commented Oct 29, 2025

Part of #13720

  • Introduce detect_code_removal feature flag
  • If enabled, Formatter::format() performs extra check
    • Currently, every public API calls format()
  • Code removal detection consists of the following two steps:
    • bf = collect(original_text) and af = collect(formatted_text)
    • diff(bf, af)
  • Basically, this works by counting node.debug_name()
    • Some AST nodes are ignored due to difficulty

NOTE: The feature has been added but is not yet enabled anywhere.


  • Enable feature somewhere
    • tasks/prettier_conformance
    • tasks/coverage
    • tasks/benchmark
    • crates/oxc_formatter
    • crates/oxc_language_server
    • apps/oxfmt
    • napi/playground
    • monitor-oxc
    • oxlint-ecosystem-ci
  • This feature should be enabled by default and should be opt-out, or explicitly enabled?

Copilot AI review requested due to automatic review settings October 29, 2025 07:40
@leaysgur leaysgur requested a review from Dunqing as a code owner October 29, 2025 07:40
@github-actions github-actions bot added A-ast Area - AST A-formatter Area - Formatter C-enhancement Category - New feature or request labels Oct 29, 2025
Copy link
Member Author


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.

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 adds a code removal detection feature to the formatter to help identify cases where formatting might inadvertently remove code. The feature is gated behind a detect_code_removal feature flag and can be used during development to detect potential formatting bugs.

Key changes:

  • Adds a new detect_code_removal module that performs pre- and post-formatting AST analysis
  • Updates the formatter to optionally run code removal detection and report findings via stderr
  • Adds feature flag support for the optional detection mechanism

Reviewed Changes

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

Show a summary per file
File Description
crates/oxc_formatter/src/lib.rs Integrates the code removal detection logic into the formatting pipeline when the feature flag is enabled
crates/oxc_formatter/src/detect_code_removal/mod.rs Implements the complete code removal detection logic including AST node counting, comment tracking, and diff reporting
crates/oxc_formatter/Cargo.toml Adds optional dependencies and feature flag for code removal detection
crates/oxc_ast/src/ast_kind_impl.rs Updates documentation for the debug_name method
Cargo.lock Reflects the addition of new dependencies

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

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 29, 2025

CodSpeed Performance Report

Merging #15059 will not alter performance

Comparing 10-23-feat_formatter_detect_code_removal_feature (a5ac520) with main (59bb65c)1

Summary

✅ 37 untouched

Footnotes

  1. No successful run was found on main (1bf9ef1) during the generation of this report, so 59bb65c was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@leaysgur leaysgur force-pushed the 10-23-feat_formatter_detect_code_removal_feature branch 2 times, most recently from 252be4c to 4927e88 Compare October 29, 2025 08:26
@Boshen
Copy link
Member

Boshen commented Oct 29, 2025

Enable feature somewhere

Let's start from oxlint-ecosystem-ci and oxc-monitor.

I'll change oxlint-ecosystem-ci to oxc-ecosystem-ci at some point.

@leaysgur leaysgur force-pushed the 10-23-feat_formatter_detect_code_removal_feature branch from 4927e88 to a72cf8e Compare October 30, 2025 06:26
@Dunqing
Copy link
Member

Dunqing commented Oct 30, 2025

Leaves oxlint-ecosystem-ci to me, I am making some changes to it.

@leaysgur
Copy link
Member Author

Leaves oxlint-ecosystem-ci to me

Thank you~!
👉🏻 #13720 (comment)

Copy link
Contributor

Copilot AI commented Oct 30, 2025

@Dunqing I've opened a new pull request, #15114, to work on those changes. Once the pull request is ready, I'll request review from you.

@leaysgur leaysgur force-pushed the 10-23-feat_formatter_detect_code_removal_feature branch from a72cf8e to ee017a3 Compare October 30, 2025 08:21
@leaysgur leaysgur force-pushed the 10-23-feat_formatter_detect_code_removal_feature branch from 5c7af27 to a5ac520 Compare October 30, 2025 09:34
@leaysgur leaysgur requested a review from Dunqing October 30, 2025 09:36
@Dunqing Dunqing added the 0-merge Merge with Graphite Merge Queue label Oct 31, 2025
Copy link
Member

Dunqing commented Oct 31, 2025

Merge activity

Part of #13720

- Introduce `detect_code_removal` feature flag
- If enabled, `Formatter::format()` performs extra check
  - Currently, every public API calls `format()`
- Code removal detection consists of the following two steps:
  - `bf = collect(original_text)` and `af = collect(formatted_text)`
  - `diff(bf, af)`
- Basically, this works by counting `node.debug_name()`
  - Some AST nodes are ignored due to difficulty

NOTE: The feature has been added but is not yet enabled anywhere.

---

- Enable feature somewhere
  - tasks/prettier_conformance
  - tasks/coverage
  - tasks/benchmark
  - crates/oxc_formatter
  - crates/oxc_language_server
  - apps/oxfmt
  - napi/playground
  - monitor-oxc
  - oxlint-ecosystem-ci
- This feature should be enabled by default and should be opt-out, or explicitly enabled?
@graphite-app graphite-app bot force-pushed the 10-23-feat_formatter_detect_code_removal_feature branch from a5ac520 to e77a48e Compare October 31, 2025 00:47
@graphite-app graphite-app bot merged commit e77a48e into main Oct 31, 2025
21 checks passed
@graphite-app graphite-app bot deleted the 10-23-feat_formatter_detect_code_removal_feature branch October 31, 2025 00:53
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Oct 31, 2025
@Boshen Boshen mentioned this pull request Nov 4, 2025
leaysgur added a commit that referenced this pull request Nov 4, 2025
## [0.10.0] - 2025-11-04

### 🚀 Features

- 505252c formatter: Wrap parenthesis for AssignmentExpression that is a
key of `PropertyDefinition` (#15243) (Dunqing)
- 880b259 formatter: Align import-like formatting the same as Prettier
(#15238) (Dunqing)
- b77f254 oxfmt,formatter: Support `embeddedLanguageFormatting` option
(#15216) (leaysgur)
- 898d6fe oxfmt: Add embedded language formatting with Prettier
integration (#14820) (Boshen)
- e77a48e formatter: Detect code removal feature (#15059) (leaysgur)

### 🐛 Bug Fixes

- daacf85 oxfmt: Release build fails (#15262) (Dunqing)
- f5d0348 oxfmt: Sync `dependencies` with `npm/oxfmt` and `apps/oxfmt`
(#15261) (leaysgur)
- 46793d7 formatter: Correct printing comments for `LabeledStatement`
(#15260) (Dunqing)
- 831ae99 formatter: Multiple comments in `LogicalExpression` and
`TSIntersectionType` (#15253) (Dunqing)
- 5fa9b1e formatter: Should not indent `BinaryLikeExpression` when it is
an argument of `Boolean` (#15250) (Dunqing)
- 99e520f formatter: Handle chain expression for
`JSXExpressionContainer` (#15242) (Dunqing)
- a600bf5 formatter: Correct printing comments for
`TaggedTemplateExpression` (#15241) (Dunqing)
- a7289e7 formatter: Handle member chain for the call's parent is a
chain expression (#15237) (Dunqing)

### 🚜 Refactor

- 36ae721 formatter: Simplify the use of `indent` with
`soft_line_break_or_space` (#15254) (Dunqing)
- cdd8e2f formatter/sort-imports: Split sort_imports modules (#15189)
(leaysgur)
- 27b4f36 diagnostic: Remove `path` from sender (#15130) (camc314)
- 85fb8e8 formatter/sort-imports: Pass options to is_ignored() (#15181)
(leaysgur)

### 🧪 Testing

- 9d5b34b formatter/sort-imports: Refactor sort_imports tests (#15188)
(leaysgur)

Co-authored-by: leaysgur <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ast Area - AST A-formatter Area - Formatter C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants