Oxfmt Setup Guide
Zero-Config Start (30 seconds)
# Run without installing
npx oxfmt .
# Or install as devDependency
npm install -D oxfmt
No config file needed. Oxfmt formats JS/TS files with sensible Prettier-compatible defaults (2-space indent, double quotes, semicolons, 100-char line width).
Add to package.json
{
"scripts": {
"format": "oxfmt src/",
"format:check": "oxfmt --check src/"
}
}
Use --check in CI to verify formatting without modifying files.
Output Example
$ npx oxfmt src/utils.ts
src/utils.ts
# With --check mode (exit code 1 if unformatted)
$ npx oxfmt --check src/
src/utils.ts (needs formatting)
Found 1 file that needs formatting.
Config File
Create .oxfmtrc.json when you want to customize:
{
"$schema": "https://raw.githubusercontent.com/oxc-project/oxc/main/npm/oxfmt/configuration_schema.json",
"indentStyle": "space",
"indentWidth": 2,
"lineWidth": 80,
"semicolons": "as-needed",
"quoteStyle": "single",
"trailingCommas": "all",
"arrowParentheses": "always",
"bracketSpacing": true
}
The $schema gives IDE autocomplete for all options. You can also use oxfmtrc.jsonc for comments.
Running Alongside Prettier (Migration Path)
For projects currently using Prettier, run both in parallel during migration:
{
"scripts": {
"format": "oxfmt src/",
"format:prettier": "prettier --write src/",
"format:check": "oxfmt --check src/"
}
}
Compare output on a few files first. Oxfmt aims for Prettier compatibility but may differ on edge cases while approaching full parity.
CI Integration
# GitHub Actions
- name: Check formatting
run: npx oxfmt --check src/
Fast enough that no caching is needed. Adds negligible time to CI.
IDE Integration
Oxfmt integrates through the Oxc language server and VS Code extension:
- Install the Oxc extension from the VS Code marketplace
- The extension provides format-on-save via the Oxc language server
- The language server uses the same
.oxfmtrc.jsonconfig
Ignore Patterns
Oxfmt respects .gitignore by default. For additional ignores, add to your config:
{
"ignorePatterns": ["dist/", "generated/", "**/*.min.js"]
}
Or use inline comments:
// oxfmt-ignore
const matrix = [
1, 0, 0,
0, 1, 0,
0, 0, 1,
];
Note on Stability
Oxfmt is newer than oxlint and still approaching full Prettier parity. Expect rapid changes between releases. Pin your version in package.json and review formatting changes when upgrading.
Next Steps
- Oxfmt Overview - architecture and options reference
- Oxlint Setup - pair with the linter
- Oxc Architecture - how the toolchain fits together