Migrate from oxfmt to bun fmt

bun fmt reads your .oxfmtrc.json and prints what oxfmt 0.72 prints. In most projects you only change the command.

Start with --doctor. It shows what Bun will do with your config, and it doesn't format or write anything.

terminal
bun fmt --doctor
Using .oxfmtrc.json (oxfmt config)

    3 files are formatted natively

Still needed:   oxfmt (the "format" script runs it)

Change the scripts.

package.json
{
  "scripts": {
    "format": "oxfmt", 
    "format:check": "oxfmt --check", 
    "format": "bun fmt", 
    "format:check": "bun fmt --check" 
  }
}

Flags and arguments stay the same. Change CI and Git hooks too.

If your script is called fmt, don't skip this: bun fmt runs a fmt script when package.json has one, so you'd still get oxfmt.


Check that nothing changes. With an oxfmt config, a run prints what oxfmt prints.

terminal
bun fmt --check
$ bun fmt --check
Checking formatting...

All matched files use the correct format.
Finished in 4ms on 3 files using 64 threads.

If you're on a version of oxfmt before 0.72, a few files change once, like when you upgrade oxfmt.


Run --doctor again. No script runs oxfmt anymore, so you can uninstall it.

You can remove: oxfmt
Not checked:    other tools' configs, CI files, Git hooks
terminal
bun remove oxfmt

No .oxfmtrc.json? Add one with {} in it first. Without a config file, the oxfmt dependency is how Bun knows to format like oxfmt and not like Prettier.


Bun reads everything oxfmt reads:

  • .oxfmtrc.json, .oxfmtrc.jsonc, and oxfmt.config.ts, with overrides and ignorePatterns
  • The fmt key of vite.config.ts, if you use vite-plus
  • Every option, including sortImports, sortPackageJson, sortTailwindcss, and jsdoc
  • // oxfmt-ignore and // prettier-ignore comments
  • Every flag of oxfmt 0.72 except --lsp and --migrate

It also follows oxfmt's defaults: lines wrap at 100 columns, every .gitignore in the repository counts, TOML files are formatted, and .prettierrc is ignored.


Still have a .prettierrc next to .oxfmtrc.json? Bun uses .oxfmtrc.json and tells you so. Delete the one you no longer use, or pick one with --config.

note: Using .oxfmtrc.json. .prettierrc is ignored. Use --config to pick it.

Keep oxfmt if your editor's oxc extension uses it. bun fmt has no language server.


Differences from oxfmt#

If bun fmt and oxfmt 0.72 print different code, that's a bug. Open an issue. These differences are intentional:

  • The output is oxfmt 0.72's, whatever version you had installed.
  • No --lsp or --migrate.
  • No Svelte. With svelte in the config, Bun skips .svelte files and exits with code 2. --allow-unsupported makes that a warning.
  • Errors and warnings are worded differently.
  • An invalid TOML file is left alone, with a warning. oxfmt rewrites the parts it can read.
  • A file that isn't valid UTF-8 is still formatted, and the invalid bytes are kept. oxfmt exits with code 2.
  • Where oxfmt's output changes what a file means, Bun's differs. That's rare. In TOML oxfmt joins the lines of an inline table with a comment, which comments out the rest of the table. Bun keeps one entry per line.

See also: