Skip to content

Commit 256a560

Browse files
authored
oxfmt alpha (#603)
1 parent 05be73f commit 256a560

File tree

5 files changed

+188
-4
lines changed

5 files changed

+188
-4
lines changed

.vitepress/config/en.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const enConfig = defineLocaleConfig("root", {
2323
{
2424
text: "Resources",
2525
items: [
26-
{ text: "Blog", link: "/blog/2025-10-09-oxlint-js-plugins" },
26+
{ text: "Blog", link: "/blog/2025-12-01-oxfmt-alpha" },
2727
{ text: "Team", link: "/team" },
2828
{ text: "Release Notes", link: "https://github.com/oxc-project/oxc/releases" },
2929
{ text: "Branding", link: "/branding" },

.vitepress/config/inlined-scripts/banner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
}
77
};
88

9-
window.__OXC_BANNER_ID__ = "/blog/2025-10-09-oxlint-js-plugins";
9+
window.__OXC_BANNER_ID__ = "/blog/2025-12-01-oxfmt-alpha";
1010
restore(`oxc-banner-dismissed-${__OXC_BANNER_ID__}`, "banner-dismissed");
1111
})();

.vitepress/sidebar.blog.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
[
2+
{
3+
"text": "Oxfmt Alpha",
4+
"link": "/blog/2025-12-01-oxfmt-alpha"
5+
},
26
{
37
"text": "Oxlint JS Plugins Preview",
48
"link": "/blog/2025-10-09-oxlint-js-plugins"

.vitepress/theme/components/Banner.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const hide = () => {
1717
};
1818
1919
// Sync with inlined-scripts/banner.js
20-
const slug = "/blog/2025-10-09-oxlint-js-plugins";
20+
const slug = "/blog/2025-12-01-oxfmt-alpha";
2121
2222
const bannerDismissed = useLocalStorage<boolean>(`oxc-banner-dismissed-${slug}`, false);
2323
@@ -46,7 +46,7 @@ const dismiss = () => {
4646

4747
<template>
4848
<div ref="el" class="banner banner-dismissed">
49-
<div class="text"><a :href="slug">Announcing Oxlint JS Plugins Preview</a> 🎉</div>
49+
<div class="text"><a :href="slug">Oxfmt: Announcing Oxc Formatter Alpha</a> 🎉</div>
5050

5151
<button type="button" @click="dismiss">
5252
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">

src/blog/2025-12-01-oxfmt-alpha.md

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
---
2+
title: "Oxfmt: Oxc Formatter Alpha"
3+
outline: deep
4+
authors:
5+
- boshen
6+
- Dunqing
7+
- leaysgur
8+
---
9+
10+
<AppBlogPostHeader />
11+
12+
We’re excited to announce the alpha release of **Oxfmt**, a Rust-powered, Prettier-compatible code formatter. This first release focuses on JavaScript and TypeScript, with support for additional languages coming soon.
13+
14+
Oxfmt is designed with these goals in mind:
15+
16+
- **Performance:** More than 30× faster than Prettier and more than 3× faster than Biome on an initial run without a cache ([**benchmark**](https://github.com/oxc-project/bench-formatter)).
17+
- **Compatibility:** Prettier-compatible, so you can adopt Oxfmt in existing projects easily.
18+
- **Developer Experience:** Upcoming features include import sorting, expanded formatting options, and support for Prettier plugins.
19+
20+
## **Quick Start**
21+
22+
Add `oxfmt` to your project:
23+
24+
::: code-group
25+
26+
```npm
27+
$ npm add -D oxfmt@latest
28+
```
29+
30+
```pnpm
31+
$ pnpm add -D oxfmt@latest
32+
```
33+
34+
```yarn
35+
$ yarn add -D oxfmt@latest
36+
```
37+
38+
```bun
39+
$ bun add -D oxfmt@latest
40+
```
41+
42+
```deno
43+
$ deno add -D npm:oxfmt@latest
44+
```
45+
46+
:::
47+
48+
Oxfmt follows Prettier’s configuration format. If you are using Prettier with a JSON configuration file, you can rename it to `.oxfmtrc.jsonc`:
49+
50+
```jsx
51+
cp .prettierrc.json .oxfmtrc.jsonc
52+
```
53+
54+
You can also start from this `.oxfmtrc.jsonc` configuration example:
55+
56+
```jsx
57+
{
58+
"$schema": "./node_modules/oxfmt/configuration_schema.json",
59+
// Use 80 if migrating from Prettier; 100 is the Oxfmt default!
60+
"printWidth": 80,
61+
"ignorePatterns": [] // Same as `.prettierignore`
62+
}
63+
```
64+
65+
Next, add `oxfmt` to your package.json scripts:
66+
67+
```jsx
68+
"scripts": {
69+
"format": "oxfmt"
70+
}
71+
```
72+
73+
Alternatively, refer to the [installation guide](/docs/guide/usage/formatter.html) for detailed instructions.
74+
75+
## Performance
76+
77+
Oxfmt is incredibly fast. Our benchmark results on the [Outline](https://github.com/outline/outline) repository show:
78+
79+
- Over 30× faster than Prettier’s experimental CLI without cache
80+
- Over 20× faster than Prettier using Oxc’s parser through `@prettier/plugin-oxc`
81+
- Over 3× faster than Biome, another Rust-based formatter
82+
83+
For detailed benchmark setup, please refer to the following repository:
84+
85+
> oxc-project/bench-formatter\
86+
> https://github.com/oxc-project/bench-formatter
87+
88+
## Design
89+
90+
The Oxc team prioritizes compatibility with existing ecosystems, making migrations straightforward, even for large codebases.
91+
92+
### Code formatting results
93+
94+
Oxfmt matches Prettier’s JavaScript formatting. If you are migrating to Oxfmt today, you shouldn’t see any formatting differences compared to Prettier.
95+
96+
You might see minor differences when migrating from older versions of Prettier ([See an example migration](https://github.com/SBoudrias/Inquirer.js/pull/1912)) because we identified areas in which Prettier’s formatting could be improved. We have been actively collaborating with the Prettier team by submitting bug reports and pull requests directly to Prettier. Many of these improvements landed in the recent [Prettier 3.7](https://prettier.io/blog/2025/11/27/3.7.0) release.
97+
98+
Oxfmt currently passes around [95%](https://github.com/oxc-project/oxc/tree/main/tasks/prettier_conformance/snapshots) of Prettier’s JavaScript and TypeScript tests, and we hope to work with the Prettier team to converge on formatting over time.
99+
100+
### `printWidth: 100` by default
101+
102+
We chose `printWidth: 100` as the default line length instead of Prettier's `80`. Our reasons include:
103+
104+
- TypeScript code tends to be longer than JavaScript due to type annotations.
105+
- Import statements often contain many items.
106+
- Larger screens provide more horizontal space.
107+
- Results in slightly fewer LLM tokens.
108+
109+
While Oxfmt remains compatible with Prettier, it uses a different default print width of 100 characters. If you want to avoid large diffs when migrating from Prettier, explicitly set the print width to 80.
110+
111+
### `ignorePatterns`
112+
113+
While Oxfmt supports `.prettierignore`, it also supports an `ignorePatterns` configuration option to consolidate all configuration into a single file.
114+
115+
### Configuration
116+
117+
Prettier JSON configuration files are compatible with Oxfmt. In the simplest case, migrating your config looks like this:
118+
119+
```bash
120+
cp .prettierrc.json .oxfmtrc.jsonc
121+
```
122+
123+
If your editor supports the JSON language server, you can start with this minimal template after adding `oxfmt` to your `devDependencies`:
124+
125+
```json
126+
{
127+
"$schema": "./node_modules/oxfmt/configuration_schema.json",
128+
"ignorePatterns": []
129+
}
130+
```
131+
132+
While we don’t yet support all of Prettier’s configuration options in this alpha release, we do support the following major options: `printWidth`, `tabWidth`, `useTabs`, `semi`, `singleQuote`, `quoteProps`, `jsxSingleQuote`, `trailingComma`, `bracketSpacing`, `objectWrap`, `bracketSameLine`, `arrowParens`, `endOfLine`, and`singleAttributePerLine`.
133+
134+
Check out all of the options in our [documentation](https://oxc.rs/docs/guide/usage/formatter.html#configuration-file).
135+
136+
### Terminal Output
137+
138+
Oxfmt's default behavior is equivalent to `prettier . --write`, providing the same UX as `cargo fmt` and producing no output. You can use `--check` to display formatting differences and enforce oxfmt usage in CI pipelines.
139+
140+
## Beta Release Plans
141+
142+
Here are our plans for the beta release:
143+
144+
- [Support more file formats](https://github.com/oxc-project/oxc/issues/15899) - like `.json` files
145+
- [Add support for embedded language formatting](https://github.com/oxc-project/oxc/issues/15180) - css in js or graphql in js
146+
- [Built-in sorting and aesthetics features](https://github.com/oxc-project/oxc/issues/13610), such as [sort imports](https://github.com/oxc-project/oxc/issues/14253)
147+
- [Prettier plugins](https://github.com/oxc-project/oxc/issues/15665)
148+
- [Node.js API for Oxfmt](https://github.com/oxc-project/oxc/issues/15913)
149+
- [Disable newline at the end of file](https://github.com/oxc-project/oxc/issues/15066)
150+
- [`--migrate prettier`](https://github.com/oxc-project/oxc/issues/15849)
151+
- _… and your feature requests_
152+
153+
You can track our progress towards the beta release here:
154+
155+
> Formatter Beta · Milestone #15 · oxc-project/oxc\
156+
> https://github.com/oxc-project/oxc/milestone/15
157+
158+
We also plan to relax some of the formatting opinions in future versions.
159+
160+
## Next Steps
161+
162+
See the full installation guide in the [Oxfmt docs](https://oxc.rs/docs/guide/usage/formatter.html).
163+
164+
### Reporting Issues
165+
166+
For formatting differences, please refer to [https://github.com/oxc-project/oxc/discussions/14669](https://github.com/oxc-project/oxc/discussions/14669).
167+
Additionally, known issues are distinguished by [labels](https://github.com/oxc-project/oxc/issues?q=sort%3Aupdated-desc%20is%3Aissue%20label%3AA-formatter-prettier-diff).
168+
169+
If you find any other issues, please create an issue with [dedicated template](https://github.com/oxc-project/oxc/issues/new?template=formatter_diff_report.yaml) on GitHub.
170+
171+
### Join the Community
172+
173+
> RFC: Formatter · oxc-project/oxc · Discussion #13608\
174+
> https://github.com/oxc-project/oxc/discussions/13608
175+
176+
We welcome your feedback to help make Oxfmt even better!
177+
178+
## Acknowledgements
179+
180+
Oxfmt builds on a fork of the [`biome_formatter`](https://github.com/biomejs/biome/tree/main/crates/biome_formatter) infrastructure, and we’d like to thank the Biome team, especially [@ematipico](https://github.com/ematipico) and [@MichaReiser](https://github.com/MichaReiser). We’d also like to thank the Prettier team and [@fisker](https://github.com/fisker) for collaborating with us on formatting compatibility.

0 commit comments

Comments
 (0)