Skip to content

feat(formatter): support ignore ranges#22181

Closed
mmkal wants to merge 2 commits into
oxc-project:mainfrom
mmkal:feat/oxfmt-range-ignore
Closed

feat(formatter): support ignore ranges#22181
mmkal wants to merge 2 commits into
oxc-project:mainfrom
mmkal:feat/oxfmt-range-ignore

Conversation

@mmkal
Copy link
Copy Markdown

@mmkal mmkal commented May 6, 2026

[!] Note - codex wrote the code and the tests here. I've reviewed the tests and they seem right, but I don't know rust so can't vouch for the implementation. It seems a bit while-loopy and duplicative, so I'll keep this as Draft. If the oxc team want to support this feature but don't want to use the code (or even review the code), maybe this PR can be used as a reference point rather than merge directly. CC @oxc-bot in case that bot is good at reviewing oxc code.

Summary

Adds range ignore support to oxc_formatter for JavaScript and TypeScript formatter paths.

Supported markers:

// oxfmt-ignore-start
const keep={  this:"raw"  }
// oxfmt-ignore-end

/* prettier-ignore-start */
type B1 = string;
type B2 = string
/* prettier-ignore-end */

When a range marker appears before a statement or class element, the formatter emits source text through the matching *-ignore-end comment unchanged, marks comments inside the range as printed, skips AST nodes covered by the range, and resumes normal formatting afterward.

This supports both native oxfmt-ignore-start / oxfmt-ignore-end and Prettier-compatible prettier-ignore-start / prettier-ignore-end markers. It implements the range-ignore portion of @BlankParticle's feature request in #22182 and is related to prettier/prettier#5287.

I also merged current upstream main into this branch so the draft PR is no longer based on the stale branch revision.

Tests

  • cargo fmt -p oxc_formatter
  • cargo test -p oxc_formatter
  • cargo check -p oxfmt --no-default-features

AI Assistance

Prepared with AI assistance. The contributor is responsible for reviewing and validating the changes before merge.

@camc314 camc314 added the A-formatter Area - Formatter label May 8, 2026
@mmkal mmkal closed this May 12, 2026
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.

2 participants