Oxfmt
Oxfmt (/oʊ-ɛks-fɔːr-mæt/) is a Prettier-compatible code formatter.
INFO
Oxfmt is currently in alpha.
Please join the discussion!
RFC: Formatter · oxc-project/oxc · Discussion #13608
https://github.com/oxc-project/oxc/discussions/13608
Waiting on Oxfmt to implement additional features? Consider using @prettier/plugin-oxc in Prettier to gain some parsing speed in the meantime.
Features
- Support many kinds of file types
- JS/TS(X): Supported by
oxc_formatter - All file types supported by Prettier by default
- JS/TS(X): Supported by
- Faster alternative of Prettier CLI
- Over 30× faster than Prettier’s experimental CLI without cache
- Experimental but usable features
- Native sort-imports
- Native sort-packagejson
Supported languages
- JS, JSX
- TS, TSX
- TOML
- JSON, JSONC, JSON5
- YAML
- HTML, Angular, Vue, MJML
- Ember, Handlebars
- CSS, SCSS, Less
- GraphQL
- Markdown, MDX
Quickstart
Run oxfmt directly at the root of your repository:
$ npx oxfmt@latest$ pnpm dlx oxfmt@latest$ yarn dlx oxfmt@latest$ bunx oxfmt@latest$ deno run npm:oxfmt@latestOr save it to your package.json:
$ npm add -D oxfmt$ pnpm add -D oxfmt$ yarn add -D oxfmt$ bun add -D oxfmtAdd the following scripts to your package.json:
{
"scripts": {
"format": "oxfmt",
"format:check": "oxfmt --check"
}
}Apply formatting:
pnpm run formatCheck formatting without modifying files:
pnpm run format:checkCommand-line Interface
oxfmt CLI works like prettier --write . by default.
Formatting config options like --no-semi are not supported via CLI flags. We recommend setting these via the configuration file instead. This will ensure that the CLI and editor integrations always use the same settings.
Globs in positional paths are not expanded. (You can rely on your shell.) But !-prefixed exclude paths do support glob expansion.
See more details in the CLI reference.
Node.js API
oxfmt is also available via Node.js API: format() function.
import { format } from "oxfmt";
import type { FormatOptions } from "oxfmt";
const INPUT = `let a=42;`;
const options: FormatOptions = {
semi: false,
};
const { code, errors } = await format("a.js", INPUT, options);
console.log(code); // "let a = 42"System Requirements
- Node.js: >= 20.19.0 or >= 22.12.0
- Platforms: darwin-arm64, darwin-x64, linux-arm64, linux-x64, win32-arm64, and win32-x64
FAQs
Are there any formatting differences with Prettier?
For JS/TS files, we're tested against the v3.7.3 of Prettier.
For known differences, please see this discussion.
Oxfmtdifferences withPrettier· oxc-project/oxc · Discussion #14669
https://github.com/oxc-project/oxc/discussions/14669
Are there any limitations for configuration with Prettier?
The following are NOT currently supported:
prettierfield inpackage.json- Config file format other than
.jsonand.jsonc overridesfield- Nested configs in sub directories
- Nested
.editorconfigin sub directories experimentalTernariesandexperimentalOperatorPositionoption
Also, if printWidth is not specified, its default value is 100. This differs from Prettier's default 80.
Are Prettier plugins supported?
Currently, NOT supported.
However, we have some experimental sorting options:
experimentalSortImports- Based on
eslint-plugin-perfectionist/sort-imports - Disabled by default
- Based on
experimentalSortPackageJson- Based on
prettier-plugin-packagejson - Enabled by default
- Based on
experimentalTailwindcss- Based on
prettier-plugin-tailwindcss - Disabled by default
- Based on
See more details in the Configuration file reference.
Why are embedded template literals not formatted?
Currently, not fully implemented.
For known differences, please see this discussion.
oxfmt: embedded formatting full support (aka xxx-in-js) · Issue #15180 · oxc-project/oxc
https://github.com/oxc-project/oxc/issues/15180