Formatter (oxfmt)
Oxfmt (/oh-eks-for-mat/) 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
- JSON, JSONC, JSON5
- YAML
- HTML, Angular, Vue, MJML
- Ember, Handlebars
- CSS, SCSS, Less
- GraphQL
- Markdown, MDX
WARNING
Note that the embeddedLanguageFormatting option is not fully supported in JS/TS files. And for now, it is disabled by default.
Installation
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 oxfmtCommand-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
What is the compatibility 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?
The following are NOT currently supported:
prettierfield inpackage.json- File formats other than
.json(c) - Nested configs in sub directories
overridesfield- 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, for import sorting functionality, we provide experimental behavior based on eslint-plugin-perfectionist/sort-imports through the experimentalSortImports option.
And for prettier-plugin-packagejson, we have the experimentalSortPackageJson option, which is enabled by default.
See more details in the Configuration file reference.
Why are nested scripts and code blocks not formatted?
Currently, the embeddedLanguageFormatting option is off by default. Please set it to auto in your config file.