Skip to content

Commit b62bcb8

Browse files
authored
docs(oxfmt): Follow recent updates (#716)
1 parent 2847610 commit b62bcb8

File tree

5 files changed

+163
-73
lines changed

5 files changed

+163
-73
lines changed

.vitepress/config/en.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ export const enConfig = defineLocaleConfig("root", {
9393
link: "/docs/guide/usage/formatter",
9494
collapsed: true,
9595
items: [
96+
{
97+
text: "Configuration",
98+
link: "/docs/guide/usage/formatter/config",
99+
},
100+
{
101+
text: "Integration",
102+
link: "/docs/guide/usage/formatter/integration",
103+
},
96104
{
97105
text: "CLI reference",
98106
link: "/docs/guide/usage/formatter/cli",

src/docs/guide/usage/formatter.md

Lines changed: 59 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,36 @@ Please join the discussion!
1010
> RFC: Formatter · oxc-project/oxc · Discussion #13608\
1111
> https://github.com/oxc-project/oxc/discussions/13608
1212
13-
Waiting on oxfmt to implement additional features? Consider using [@prettier/plugin-oxc](https://github.com/prettier/prettier/tree/main/packages/plugin-oxc) in Prettier to gain some parsing speed in the meantime.
13+
Waiting on Oxfmt to implement additional features? Consider using [@prettier/plugin-oxc](https://github.com/prettier/prettier/tree/main/packages/plugin-oxc) in Prettier to gain some parsing speed in the meantime.
14+
:::
15+
16+
## Features
17+
18+
- Support many kinds of file types
19+
- JS/TS(X): Supported by `oxc_formatter`
20+
- All file types supported by Prettier by default
21+
- Faster alternative of Prettier CLI
22+
- Over [30×](/blog/2025-12-01-oxfmt-alpha.html#performance) faster than Prettier’s experimental CLI without cache
23+
- Experimental but usable features
24+
- Native sort-imports
25+
- Native sort-packagejson
26+
27+
## Supported languages
28+
29+
- JS, JSX
30+
- TS, TSX
31+
- JSON, JSONC, JSON5
32+
- YAML
33+
- HTML, Angular, Vue, MJML
34+
- Ember, Handlebars
35+
- CSS, SCSS, Less
36+
- GraphQL
37+
- Markdown, MDX
38+
39+
:::warning
40+
41+
Note that the `embeddedLanguageFormatting` option is not fully supported in JS/TS files. And for now, it is disabled by default.
42+
1443
:::
1544

1645
## Installation
@@ -65,78 +94,44 @@ $ bun add -D oxfmt
6594

6695
## Command-line Interface
6796

68-
`oxfmt` works like `prettier --write .` by default.
97+
`oxfmt` CLI works like `prettier --write .` by default.
6998

70-
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.
99+
Formatting config options like `--no-semi` are not supported via CLI flags.
100+
We recommend setting these via the configuration file instead. This will ensure that the CLI and editor integrations always use the same settings.
71101

72102
Globs in positional paths are not expanded. (You can rely on your shell.) But `!`-prefixed exclude paths do support glob expansion.
73103

74104
See more details in the [CLI reference](./formatter/cli).
75105

76-
## Configuration file
77-
78-
By default, `oxfmt` automatically tries to find the nearest `.oxfmtrc.json` or `.oxfmtrc.jsonc` file from the current working directory. If not found, the default configuration options are used.
106+
## Node.js API
79107

80-
You can also specify your config file with the `-c yourconfig.jsonc` flag.
108+
`oxfmt` is also available via Node.js API: `format()` function.
81109

82-
Almost all formatting options are compatible with Prettier's [options](https://prettier.io/docs/options).
83-
So you can migrate from Prettier by simply renaming `.prettierrc.json` to `.oxfmtrc.jsonc`.
110+
```ts
111+
import { format } from "oxfmt";
112+
import type { FormatOptions } from "oxfmt";
84113

85-
We also recommend adding the `$schema` to the config file after copying it:
114+
const INPUT = `let a=42;`;
115+
const options: FormatOptions = {
116+
semi: false,
117+
};
86118

87-
```json
88-
{
89-
"$schema": "./node_modules/oxfmt/configuration_schema.json"
90-
}
119+
const { code, errors } = await format("a.js", INPUT, options);
120+
console.log(code); // "let a = 42"
91121
```
92122

93-
You can see the full JSON schema for the config file here:
94-
95-
> https://github.com/oxc-project/oxc/blob/main/npm/oxfmt/configuration_schema.json
96-
97-
See also [Configuration File](./formatter/config-file-reference).
98-
99-
## Ignore file
100-
101-
By default, `oxfmt` automatically finds the `.gitignore` and `.prettierignore` files from the current working directory.
123+
## System Requirements
102124

103-
Also you can specify your ignore file by `--ignore-path your.ignore` flag.
104-
105-
VCS directories like `.git` and `.svn` are always ignored. Also global and nested ignores are not respected.
106-
107-
In addition, `.oxfmtrc.json(c)` supports an `ignorePatterns` field.
108-
109-
## Pre-commit hook
110-
111-
If you want to auto-format staged files with oxfmt in a git pre-commit hook, you can use `oxfmt --no-error-on-unmatched-pattern`.
112-
113-
This command is equivalent to `prettier --no-error-on-unmatched-pattern --write`, and will format all matched files that are supported by oxfmt. The `--no-error-on-unmatched-pattern` flag ensures that oxfmt will not raise errors if there are no supported files passed into the command by your pre-commit hook tool (e.g. only Ruby files are staged).
114-
115-
You can also pass `--check` to only _check_ the formatting of files, and bail if any files are incorrectly formatted.
116-
117-
If you are using a pre-commit hook via husky/lint-staged, you can run oxfmt with it by updating your package.json like so:
118-
119-
```json
120-
"lint-staged": {
121-
"*": "oxfmt --no-error-on-unmatched-pattern"
122-
},
123-
```
125+
- **Node.js**: >= 20.19.0 or >= 22.12.0
126+
- **Platforms**: darwin-arm64, darwin-x64, linux-arm64, linux-x64, win32-arm64, and win32-x64
124127

125128
## FAQs
126129

127-
### What kinds of files are supported?
128-
129-
Currently, only JavaScript and TypeScript files are supported (using all common JS/TS extensions and filenames, including `.js`, `.jsx`, `.ts`, `.mjs`, etc.).
130-
JSX is always available in JS files, but for TypeScript, the `.tsx` extension is required to use JSX syntax.
131-
132-
Embedded parts like CSS-in-JS have experimental partial support.
133-
By specifying `embeddedLanguageFormatting: auto`, non-substitution templates will be formatted.
134-
135130
### What is the compatibility with Prettier?
136131

137-
We're following the `main` branch of Prettier, not the `latest` release.
132+
For JS/TS files, we're tested against the `v3.7.3` of Prettier.
138133

139-
For other differences, please see this discussion.
134+
For known differences, please see this discussion.
140135

141136
> `Oxfmt` differences with `Prettier` · oxc-project/oxc · Discussion #14669\
142137
> https://github.com/oxc-project/oxc/discussions/14669
@@ -148,24 +143,23 @@ The following are NOT currently supported:
148143
- `prettier` field in `package.json`
149144
- File formats other than `.json(c)`
150145
- Nested configs in sub directories
151-
- `override` field
152-
- Respect `.editorconfig`
146+
- `overrides` field
147+
- Nested `.editorconfig` in sub directories
153148
- `experimentalTernaries` and `experimentalOperatorPosition` option
154149

155-
Also, if `printWidth` is not specified, its default value is `100`. This differs from Prettier's default.
150+
Also, if `printWidth` is not specified, its default value is `100`. This differs from Prettier's default `80`.
156151

157152
### Are Prettier plugins supported?
158153

159-
Currently, they are not supported.
160-
161-
For import sorting functionality, we provide experimental behavior based on `eslint-plugin-perfectionist/sort-imports` through the `experimentalSortImports` configuration option.
154+
Currently, NOT supported.
162155

163-
### How does editor integration work?
156+
However, for import sorting functionality, we provide experimental behavior based on `eslint-plugin-perfectionist/sort-imports` through the `experimentalSortImports` option.
164157

165-
For VS Code, the Oxc extension is available from the [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=oxc.oxc-vscode) and [Open VSX Registry](https://open-vsx.org/extension/oxc/oxc-vscode).
158+
And for `prettier-plugin-packagejson`, we have the `experimentalSortPackageJson` option, which is enabled by default.
166159

167-
For other editors, by running `oxfmt --lsp` you can start a language server that responds to standard `textDocument/formatting` requests.
160+
See more details in the [Configuration file reference](./formatter/config-file-reference).
168161

169-
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.
162+
### Why are nested scripts and code blocks not formatted?
170163

171-
However, these methods have some limitations, such as not supporting formatting of embedded parts.
164+
Currently, the `embeddedLanguageFormatting` option is `off` by default.
165+
Please set it to `auto` in your config file.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Configuration
2+
3+
## `.oxfmtrc.json(c)`
4+
5+
We support `.json` or `.jsonc` config file.
6+
7+
Almost all formatting options are compatible with Prettier's [options](https://prettier.io/docs/options).
8+
9+
We also recommend adding the `$schema` to the config file:
10+
11+
```json
12+
{
13+
"$schema": "./node_modules/oxfmt/configuration_schema.json"
14+
}
15+
```
16+
17+
For full reference, see also [Configuration file reference](./config-file-reference).
18+
19+
By default, `oxfmt` automatically tries to find the nearest `.oxfmtrc.json` or `.oxfmtrc.jsonc` file from the current working directory. If not found, the default configuration options are used.
20+
21+
You can also specify your config file with the `-c yourconfig.jsonc` flag.
22+
23+
## `.editorconfig`
24+
25+
`.editorconfig` file is also supported by Oxfmt.
26+
27+
And these fields will override default options.
28+
29+
- `end_of_line`: `endOfLine`
30+
- `indent_style`: `useTabs`
31+
- `indent_size`: `tabWidth`
32+
- `max_line_length`: `printWidth`
33+
34+
If both `.editorconfig` and `.oxfmtrc.json` has the same field, `.oxfmtrc` will win.
35+
36+
By default, `oxfmt` automatically tries to find the nearest `.editorconfig` file from the current working directory.
37+
38+
Unlike Prettier, Oxfmt does not respect `root = true` and does not merge nested `.editorconfig` files.
39+
40+
## Ignore files
41+
42+
By default, `oxfmt` automatically finds the `.gitignore` and `.prettierignore` files from the current working directory.
43+
44+
Also you can specify your ignore file by `--ignore-path your.ignore` flag.
45+
In addition, `.oxfmtrc.json(c)` supports an `ignorePatterns` field.
46+
47+
Global and nested ignores are not respected.
48+
49+
VCS directories like `.git` and `.svn` are always ignored, also popular lock files are also ignored.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Integration
2+
3+
## Editor
4+
5+
For VS Code, the Oxc extension is available from the [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=oxc.oxc-vscode) and [Open VSX Registry](https://open-vsx.org/extension/oxc/oxc-vscode).
6+
7+
For other editors, by running `oxfmt --lsp` you can start a language server that responds to standard `textDocument/formatting` requests.
8+
9+
:::warning
10+
11+
Currently, LSP support has some limitations, such as not supporting formatting of embedded parts in JS/TS files, non-JS files support.
12+
13+
:::
14+
15+
Formatting via stdin and stdout are also supported.
16+
17+
```sh
18+
cat foo/bar.js | oxfmt --stdin-filepath f.js --config ./path/to/config.json
19+
```
20+
21+
In addition, we have confirmed that some editors and extensions can work with the CLI by configuring them to use temporary files.
22+
23+
## Pre-commit hook
24+
25+
If you want to auto-format staged files with Oxfmt in a git pre-commit hook, you can use `oxfmt --no-error-on-unmatched-pattern`.
26+
27+
This command is equivalent to `prettier --no-error-on-unmatched-pattern --write`, and will format all matched files that are supported by oxfmt. The `--no-error-on-unmatched-pattern` flag ensures that Oxfmt will not raise errors if there are no supported files passed into the command by your pre-commit hook tool (e.g. only Ruby files are staged).
28+
29+
You can also pass `--check` to only _check_ the formatting of files, and bail if any files are incorrectly formatted.
30+
31+
If you are using a pre-commit hook via husky/lint-staged, you can run Oxfmt with it by updating your package.json like so:
32+
33+
```json
34+
"lint-staged": {
35+
"*": "oxfmt --no-error-on-unmatched-pattern"
36+
},
37+
```

src/docs/guide/usage/formatter/migrate-from-prettier.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,12 @@
33
If you currently use Prettier as your code formatter, you can follow this guide to migrate to Oxfmt.
44

55
Note that Oxfmt is in alpha, and may not be suitable for production use in complex setups.
6-
For the beta milestone, we may provide migration commands.
7-
8-
> oxfmt: `--migrate prettier` · Issue #15849 · oxc-project/oxc\
9-
> https://github.com/oxc-project/oxc/issues/15849
106

117
## Caveats for migrating to Oxfmt
128

13-
Before migrating, ensure that the current release of the Oxfmt alpha meets your project's needs. It is almost entirely compatible with Prettier v3.7 already for basic configurations, but less-common config options and other features are not yet implemented.
14-
15-
<!-- TODO: Remove this note when oxfmt 0.17.0 ships with many of the missing languages. -->
9+
Before migrating, ensure that the current release of the Oxfmt alpha meets your project's needs.
1610

17-
The Oxfmt alpha only supports formatting JavaScript and TypeScript files (including those with JSX syntax). If you need support for non-JSX frameworks like Vue or Ember, or other languages like JSON, YAML, or Markdown, you will likely want to wait.
11+
It is almost entirely compatible with Prettier v3.7 already for basic configurations, but less-common config options and other features are not yet implemented.
1812

1913
Other important considerations when migrating from Prettier to Oxfmt:
2014

@@ -79,6 +73,14 @@ If you have a basic `.prettierrc` file, you can simply rename the file with `mv
7973

8074
If you are using something other than JSON to configure Prettier, you will need to convert the configuration to JSON.
8175

76+
In either case, you can use the migrate command in your project root directory.
77+
78+
```sh
79+
oxfmt --migrate prettier
80+
```
81+
82+
This command automatically finds your configuration file and converts it to `.oxfmtrc.json` if possible.
83+
8284
### `prettierrc.js`
8385

8486
Here's an example of migrating a `prettierrc.js` file.

0 commit comments

Comments
 (0)