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 oxfmtOxfmt works like prettier --write . by default.
Format options are not supported by CLI, use configuration file instead. This will help you use CLI and editor extension with the same settings.
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.
Notable limitations ​
These will (or will not) be implemented in the future.
- Only JS and TS files are supported
- Embedded parts like css-in-js are partially supported, but disabled by default
- Stdin and stdout are not supported
- You need
oxc_language_serverviaoxlintto get editor support for now
- You need
- Configuration NOT supported for:
prettierfield inpackage.json- File formats other than
.json(c) - Nested configs in sub directories
- Respect
.editorconfig - Inline CLI flags like
--no-semi experimentalTernariesoption
- Globs in positional paths are not expanded
- But it works in
!prefixed exclude paths
- But it works in
- Plugins are not supported
- Some of them like sort-imports will be natively supported
Compatibility with Prettier ​
Please see this discussion.
Oxfmtdifferences withPrettier· oxc-project/oxc · Discussion #14669 https://github.com/oxc-project/oxc/discussions/14669