Skip to content

feat(oxfmt): Support oxfmt --migrate prettier (JS side)#16773

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

feat(oxfmt): Support oxfmt --migrate prettier (JS side)#16773
graphite-app[bot] merged 1 commit intomainfrom
12-12-feat_oxfmt_support_oxfmt_--migrate_js_side_

Conversation

@leaysgur
Copy link
Copy Markdown
Member

@leaysgur leaysgur commented Dec 12, 2025

Fixes #15849 , closes #16736

Tests and cosmetic changes are planned in next PR.

@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 marked this pull request as draft December 12, 2025 09:20
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.

The migration flow has a correctness issue where resolveConfigFile() and resolveConfig() resolve against different targets, which can migrate a different config than the one detected. The Prettier-to-oxfmt mapping currently copies arbitrary Prettier keys into .oxfmtrc.json, which risks generating misleading/unsupported configuration. Finally, .prettierignore parsing swallows all errors, making migration failures hard to diagnose.

Summary of changes

Summary

This PR adds JS-side support for oxfmt --migrate prettier and refactors migration helpers.

  • CLI routing: apps/oxfmt/src-js/cli.ts now dispatches both --init and --migrate prettier modes via ./migration/index.js.
  • Migration entrypoint: new barrel file apps/oxfmt/src-js/migration/index.ts re-exports runInit and runMigratePrettier.
  • Shared migration utilities: new apps/oxfmt/src-js/migration/shared.ts centralizes:
    • .oxfmtrc existence checks (hasOxfmtrcFile)
    • schema discovery (hasSchemaFile)
    • blank config creation (createBlankOxfmtrcFile)
    • config persistence (saveOxfmtrcFile)
    • consistent error exit behavior (exitWithError)
  • --init refactor: apps/oxfmt/src-js/migration/init.ts now uses shared helpers instead of inline FS logic.
  • Prettier migration: new apps/oxfmt/src-js/migration/migrate-prettier.ts resolves a Prettier config (and .prettierignore) and writes an .oxfmtrc.json, warning on unsupported/partial options.

@charliecreates charliecreates bot removed the request for review from CharlieHelps December 12, 2025 09:22
@leaysgur leaysgur force-pushed the 12-12-feat_oxfmt_support_oxfmt_--migrate_js_side_ branch 2 times, most recently from 76109c0 to 5127f76 Compare December 12, 2025 09:33
@leaysgur leaysgur marked this pull request as ready for review December 12, 2025 09:35
@leaysgur leaysgur changed the title feat(oxfmt): Support oxfmt --migrate (JS side) feat(oxfmt): Support oxfmt --migrate (JS side) Dec 12, 2025
@charliecreates
Copy link
Copy Markdown

Review for PR #16773

Overall impressions

Solid foundation for oxfmt --migrate prettier with good attention to CLI entrypoints and shared utilities. The implementation is clear and concise, but there are a few correctness and safety issues in the migration logic that are worth addressing to make migrations robust, predictable, and user-informative.


Major Feedback

  1. Mismatched Prettier config resolution
    In migrate-prettier.ts, resolveConfigFile() operates on dummy.js, but resolveConfig() is called with cwd (the directory), not the file path, so different configs (including overrides) might be resolved. Align both calls to use the same target (dummy.js) to ensure correct config migration.

  2. Over-broad Prettier option mapping
    All Prettier config keys are copied to .oxfmtrc.json, including unsupported/unknown options. This makes for future migration headaches and could mislead users. Prefer an explicit allowlist of supported options, and warn on unknowns to keep the migrated config clean and future-proof.

  3. Error swallowing in .prettierignore migration
    All errors while reading .prettierignore—not just file not found—are ignored without feedback, which could make ignore-related issues much harder to debug. Only quietly ignore "not found"; warn for anything else.

  4. Inconsistent exit behavior
    exitWithError sets process.exitCode but continues program flow. This risks accidental execution after a blocking error, especially with mixed return exitWithError(...) and just exitWithError(...) patterns. Prefer making this function either consistently control-flow breaking (e.g., throw) or explicit (e.g., always return and require a top-level return).


Minor suggestions

  • Consider logging, tabling, or exporting the list of skipped config keys for users who want to manually check what wasn't migrated.
  • Add unit tests for option translation and error edge cases in the next refactor, as stated in your PR notes.

Summary

Great progress and well-factored utilities with just a few migration correctness/safety changes advised before releasing widely. Please reference detailed suggestions in the inline bots' comments for practical code-level examples.


Inline feedback (see PR for context and details):

  1. Align Prettier config resolution to always use the same filename target.
  2. Replace blanket option copying with an allowlist, warning on unsupported keys.
  3. Log reading errors from .prettierignore except for ENOENT.
  4. Make exitWithError always halt control flow (e.g., throw).

Would recommend addressing the above for more predictable and robust migrations.

@leaysgur leaysgur changed the title feat(oxfmt): Support oxfmt --migrate (JS side) feat(oxfmt): Support oxfmt --migrate prettier (JS side) Dec 12, 2025
@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 force-pushed the 12-12-feat_oxfmt_support_oxfmt_--migrate_js_side_ branch from 5127f76 to 270f454 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

Fixes #15849 , closes #16736

Tests and cosmetic changes are planned in 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 force-pushed the 12-12-feat_oxfmt_support_oxfmt_--migrate_js_side_ branch from 270f454 to d4c0bb7 Compare December 15, 2025 02:50
Base automatically changed from 12-12-feat_oxfmt_support_oxfmt_--migrate_rust_side_ to main December 15, 2025 02:55
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Dec 15, 2025
@graphite-app graphite-app bot merged commit d4c0bb7 into main Dec 15, 2025
19 checks passed
@graphite-app graphite-app bot deleted the 12-12-feat_oxfmt_support_oxfmt_--migrate_js_side_ branch December 15, 2025 02:56
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.

oxfmt: --migrate prettier

2 participants