Formatter
Oxfmt (/oh-eks-for-mat/) is a Prettier-compatible code formatter.
INFO
Oxfmt is currently working in progress.
Please join the discussion!
RFC: Formatter · oxc-project/oxc · Discussion #13608
https://github.com/oxc-project/oxc/discussions/13608
For now, you may use @prettier/plugin-oxc in prettier to gain some parsing speed.
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 works like prettier --write . by default.
Format options like --no-semi are not supported by CLI, we recommend to use configuration file instead. This will help you use CLI and editor extension with the same settings.
Globs in positional paths are not expanded. (Still you can rely on your shell.) But it works in ! prefixed exclude paths.
See more details in CLI reference.
Configuration file
By default, oxfmt automatically tries to find the nearest .oxfmtrc.json or .oxfmtrc.jsonc file from current working directory. If not found, default configuration is used.
Also you can specify your config file by -c yourconfig.jsonc flag.
Almost all format options are compatible with Prettier's options. So you may finish your setup by just renaming .prettierrc.json to .oxfmtrc.jsonc.
Config file follows this schema.
https://github.com/oxc-project/oxc/blob/main/npm/oxfmt/configuration_schema.json
You can start with this template if your editor is supporting JSON Schema.
{
"$schema": "./node_modules/oxfmt/configuration_schema.json"
}Ignore file
By default, oxfmt automatically finds the .gitignore and .prettierignore file from current working directory.
Also you can specify your ignore file by --ignore-path your.ignore flag.
VCS directories like .git and .svn are always ignored. Also global and nested ignores are not respected.
In addition, .oxfmtrc.json(c) also supports ignorePatterns field.
FAQs
What kinds of files are supported?
Currently, only JS and TS files are supported. JSX is always available in JS files, but for TS files, the .tsx extension is required to use JSX.
Embedded parts like CSS-in-JS have experimental partial support. By specifying embeddedLanguageFormatting: auto, non-substitution templates will be formatted.
What is the compatibility with Prettier?
We're following the main branch of Prettier, not the latest release.
For other 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
overridefield- Respect
.editorconfig experimentalTernariesandexperimentalOperatorPositionoption
Also, if printWidth is not specified, its default value is 100. This differs from Prettier's default.
Are Prettier plugins supported?
Currently, they are not supported.
For import sorting functionality, we provide experimental behavior based on eslint-plugin-perfectionist/sort-imports through the experimentalSortImports configuration option.
How does editor integration work?
For VS Code, the Oxc extension is available from the Visual Studio Marketplace and Open VSX Registry.
For other editors, by running oxfmt --lsp you can start a language server that responds to standard textDocument/formatting requests.
Formatting via stdin and stdout are not supported, but we have confirmed that some editors and extensions can work with the CLI by configuring them to use temporary files.
However, these methods have some limitations, such as not supporting formatting of embedded parts.