Quickstart
Recommended setup and common workflows.
Install
Install oxfmt as a dev dependency:
$ npm add -D oxfmt$ pnpm add -D oxfmt$ yarn add -D oxfmt$ bun add -D oxfmtAdd scripts to package.json:
{
"scripts": {
"fmt": "oxfmt",
"fmt:check": "oxfmt --check"
}
}Format files:
pnpm run fmtCheck formatting without writing files:
pnpm run fmt:checkUsage
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.
Globs in positional paths are not expanded (rely on your shell). However, !-prefixed exclude paths support glob expansion.
For the complete list of options, see the CLI reference.
Common workflows
Pre-commit with lint-staged
{
"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:
oxfmt --initMigrate from Prettier
oxfmt --migrate prettierSee migrate from prettier for details.
List files that differ
oxfmt --list-differentThis is useful for configuring files to ignore.
Piping file contents
echo 'const x = 1' | oxfmt --stdin-filepath test.tsPrints const x = 1;
Node.js API
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
- Change configuration
- Setup editors
- Setup CI
- Learn advanced features: sorting, embedded formatting
- Check CLI reference
