feat(oxfmt): Support oxfmt --migrate [prettier] (Rust side)#16771
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
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. |
oxfmt --migrate [prettier] (Rust side)
There was a problem hiding this comment.
--migrate is wired through parsing correctly, but the NAPI dispatch currently ignores the parsed MigrateSource and always returns "migrate:prettier", which is a maintainability trap as sources expand. The supported-source list is duplicated between help text and parse error, making it easy to drift. Minor readability concern: separator comments (// ---) add noise without clear value.
Additional notes (1)
-
Maintainability |
apps/oxfmt/src/cli/command.rs:76-83
The--migrateoption is implemented as.argument::<String>("SOURCE")with a custom.parse(...)that lowercases and validates. This works, but the error message and help text can be tightened to match CLI conventions and reduce future duplication: -
The help string includes a newline and an inline list of supported sources; if sources grow, this becomes easy to forget to update alongside the parser.
-
The error string uses
Supported: prettierwhile help usesAvailable sources: prettier(minor inconsistency).
Consider centralizing the supported sources list in one place (e.g., via MigrateSource::VARIANTS/Display) and using it for both help and parse errors.
Summary of changes
Summary
This PR adds Rust-side CLI plumbing for oxfmt --migrate (behind the napi feature) and updates help snapshots.
Key changes
- CLI parsing (
apps/oxfmt/src/cli/command.rs)- Introduces a new
Mode::Migrate(MigrateSource)variant (napi-only). - Adds
--migrate=SOURCEoption and parsesSOURCE(currently supportsprettier). - Adds
MigrateSourceenum.
- Introduces a new
- Public exports (
apps/oxfmt/src/cli/mod.rs)- Re-exports
MigrateSourceundercfg(feature = "napi").
- Re-exports
- NAPI entrypoint behavior (
apps/oxfmt/src/main_napi.rs)- Routes
Mode::Migrate(_)to a command string currently hardcoded as"migrate:prettier".
- Routes
- Docs/snapshots
- Updates CLI help snapshots to include
--migrateand its description.
- Updates CLI help snapshots to include
There was a problem hiding this comment.
Pull request overview
This PR adds Rust-side support for the --migrate CLI flag to oxfmt, which will enable migrating Prettier configurations to oxfmt's .oxfmtrc.json format. The implementation follows the existing pattern used by the --init flag, where Rust handles command-line parsing and mode detection while the actual migration logic is implemented on the JavaScript/NAPI side.
Key Changes
- Adds
--migrate=SOURCECLI flag that accepts migration sources (currently only "prettier" is supported) - Introduces
MigrateSourceenum to represent different configuration sources - Updates the Mode enum to include a
Migrate(MigrateSource)variant - Returns "migrate:prettier" mode string to the JS side for actual migration implementation
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
tasks/website_formatter/src/snapshots/cli_terminal.snap |
Updates CLI help text snapshot to include the new --migrate option with its description |
tasks/website_formatter/src/snapshots/cli.snap |
Updates markdown CLI documentation snapshot to include the new --migrate option |
apps/oxfmt/src/main_napi.rs |
Adds pattern match case for Mode::Migrate(_) to return "migrate:prettier" mode string to JS side |
apps/oxfmt/src/cli/mod.rs |
Exports MigrateSource enum for NAPI feature builds |
apps/oxfmt/src/cli/command.rs |
Implements the core functionality: defines MigrateSource enum, adds Migrate variant to Mode enum, and implements command-line parsing with validation for migration sources |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
d775393 to
0171ccf
Compare
0171ccf to
93019f7
Compare
Merge activity
|
Part of #15849 ``` Usage: [-c=PATH] [PATH]... Mode Options: --init Initialize `.oxfmtrc.json` with default values --lsp Start language server protocol (LSP) server --migrate=SOURCE Migrate configuration to `.oxfmtrc.json` from specified source Available sources: prettier ... ``` At this point, do nothing and just exit. The JS side will be in the next PR.
93019f7 to
2b9c3fe
Compare

Part of #15849
At this point, do nothing and just exit. The JS side will be in the next PR.