Skip to content

Quickstart ​

Recommended setup and common workflows.

Install ​

Install oxfmt as a dev dependency:

sh
$ npm add -D oxfmt
sh
$ pnpm add -D oxfmt
sh
$ yarn add -D oxfmt
sh
$ bun add -D oxfmt

Standalone binary

Oxfmt is also available as a standalone binary. It works as a pure CLI without Node.js, but does not support Prettier-backed formats (these files are skipped), dynamic config files (oxfmt.config.ts), Tailwind CSS class sorting, LSP mode, etc.

The npm package is the recommended way to install Oxfmt and supports all features for now.

Add scripts to package.json:

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

Format files:

sh
npm run fmt
sh
pnpm run fmt
sh
yarn run fmt
sh
bun run fmt

Check formatting without writing files:

sh
npm run fmt:check
sh
pnpm run fmt:check
sh
yarn run fmt:check
sh
bun run fmt:check

Usage ​

sh
oxfmt [OPTIONS] [PATH]...

Running oxfmt without arguments formats the current directory (equivalent to prettier --write .).

CLI options like --no-semi are not supported. Use the configuration file instead to ensure consistent settings across CLI and editor integrations.

To use glob patterns in positional paths, be sure to quote them. Otherwise, they may or may not be expanded depending on your environment.

For the complete list of options, see the CLI reference.

Common workflows ​

Pre-commit with lint-staged ​

package.json
json
{
  "lint-staged": {
    "*": "oxfmt --no-error-on-unmatched-pattern"
  }
}

--no-error-on-unmatched-pattern prevents errors when no files match the pattern.

Create a config file ​

Initialize .oxfmtrc.json with defaults:

sh
oxfmt --init

Migrate from Prettier ​

sh
oxfmt --migrate prettier

See migrate from prettier for details.

List files that differ ​

sh
oxfmt --list-different

This is useful for configuring files to ignore.

Piping file contents ​

sh
echo 'const   x   =   1' | oxfmt --stdin-filepath test.ts

Prints const x = 1;

Node.js API ​

ts
import { format, type FormatOptions } from "oxfmt";

const input = `let a=42;`;
const options: FormatOptions = {
  semi: false,
};

const { code } = await format("a.js", input, options);
console.log(code); // "let a = 42"

Next steps ​