Skip to content

feat(oxfmt): Support oxfmt --migrate [prettier] (Rust side)#16771

Merged
graphite-app[bot] merged 1 commit intomainfrom
12-12-feat_oxfmt_support_oxfmt_--migrate_rust_side_
Dec 15, 2025
Merged

feat(oxfmt): Support oxfmt --migrate [prettier] (Rust side)#16771
graphite-app[bot] merged 1 commit intomainfrom
12-12-feat_oxfmt_support_oxfmt_--migrate_rust_side_

Conversation

@leaysgur
Copy link
Copy Markdown
Member

@leaysgur leaysgur commented Dec 12, 2025

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.

Copilot AI review requested due to automatic review settings December 12, 2025 06:58
@github-actions github-actions bot added A-cli Area - CLI A-formatter Area - Formatter C-enhancement Category - New feature or request labels Dec 12, 2025
Copy link
Copy Markdown
Member Author

leaysgur commented Dec 12, 2025


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.

@leaysgur leaysgur changed the title feat(oxfmt): Support oxfmt --migrate (Rust side) feat(oxfmt): Support oxfmt --migrate [prettier] (Rust side) Dec 12, 2025
Copy link
Copy Markdown

@charliecreates charliecreates bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--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 --migrate option 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: prettier while help uses Available 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=SOURCE option and parses SOURCE (currently supports prettier).
    • Adds MigrateSource enum.
  • Public exports (apps/oxfmt/src/cli/mod.rs)
    • Re-exports MigrateSource under cfg(feature = "napi").
  • NAPI entrypoint behavior (apps/oxfmt/src/main_napi.rs)
    • Routes Mode::Migrate(_) to a command string currently hardcoded as "migrate:prettier".
  • Docs/snapshots
    • Updates CLI help snapshots to include --migrate and its description.

Copy link
Copy Markdown
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 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=SOURCE CLI flag that accepts migration sources (currently only "prettier" is supported)
  • Introduces MigrateSource enum 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.

@leaysgur leaysgur force-pushed the 12-12-feat_oxfmt_support_oxfmt_--migrate_rust_side_ branch from d775393 to 0171ccf Compare December 12, 2025 09:13
@leaysgur leaysgur marked this pull request as draft December 12, 2025 09:43
@leaysgur leaysgur force-pushed the 12-12-feat_oxfmt_support_oxfmt_--migrate_rust_side_ branch from 0171ccf to 93019f7 Compare December 15, 2025 01:16
@leaysgur leaysgur marked this pull request as ready for review December 15, 2025 01:38
@leaysgur leaysgur requested a review from Dunqing December 15, 2025 02:26
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Dec 15, 2025
@graphite-app
Copy link
Copy Markdown
Contributor

graphite-app bot commented Dec 15, 2025

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.
@graphite-app graphite-app bot force-pushed the 12-12-feat_oxfmt_support_oxfmt_--migrate_rust_side_ branch from 93019f7 to 2b9c3fe Compare December 15, 2025 02:49
@graphite-app graphite-app bot merged commit 2b9c3fe into main Dec 15, 2025
18 checks passed
@graphite-app graphite-app bot deleted the 12-12-feat_oxfmt_support_oxfmt_--migrate_rust_side_ branch December 15, 2025 02:55
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Dec 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - CLI A-formatter Area - Formatter C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants