The OXC tools¶
OXC is a collection of JavaScript/TypeScript tooling written in Rust. The OXC formatter is a fast, configurable code formatter for JavaScript, TypeScript, JSX, and JSON. It represents a new generation of high-performance tools for the JavaScript ecosystem.
How The OXC Formatter Works¶
OXC formatter parses your JavaScript/TypeScript source code into an Abstract Syntax Tree (AST), then applies formatting rules to generate consistently styled output. Because it's written in Rust, it avoids the overhead of Node.js and achieves near-native performance.
Use Cases¶
- Large Codebases: Format thousands of files in seconds during CI/CD pipelines
- Monorepos: Handle multiple packages with different configurations efficiently
- Pre-commit Hooks: Instant formatting without waiting for slower alternatives
- IDE Integration: Real-time formatting as you type with minimal latency
- Migration Projects: Drop-in replacement for Prettier with compatible output
Why OXC Formatter?¶
Performance
OXC formatter is written in Rust and is significantly faster than other JavaScript formatters. It can format large codebases in milliseconds.
Compatibility
OXC aims to be compatible with Prettier's formatting rules, making migration easy.
Installation¶
Or using other package managers:
Standalone Formatter (oxcfmt)¶
You can also install the standalone formatter package oxcfmt directly:
Basic Usage¶
CLI Commands¶
# Format all files
npx oxc format .
# Format specific files
npx oxc format src/**/*.ts
# Check formatting without writing
npx oxc format . --check
Configuration¶
Create an oxc.config.json file in your project root:
{
"formatter": {
"enabled": true,
"indentStyle": "tab",
"indentWidth": 2,
"lineEnding": "lf",
"printWidth": 80,
"quoteStyle": "double"
}
}
Configuration Options¶
| Option | Type | Default | Description |
|---|---|---|---|
enabled |
boolean | true |
Enable/disable formatter |
indentStyle |
"tab" \| "space" |
"tab" |
Indentation style |
indentWidth |
number | 2 |
Number of spaces per indentation level |
lineEnding |
"lf" \| "crlf" \| "cr" |
"lf" |
Line ending character |
printWidth |
number | 80 |
Maximum line length |
quoteStyle |
"single" \| "double" |
"double" |
Quote style for strings |
Formatting Examples¶
Before Formatting¶
function greet(name, age) {
const message = "Hello, " + name + "! You are " + age + " years old.";
console.log(message);
return { message: message, timestamp: Date.now() };
}
After Formatting¶
function greet(name, age) {
const message = "Hello, " + name + "! You are " + age + " years old.";
console.log(message);
return { message: message, timestamp: Date.now() };
}
Supported Languages¶
JavaScript (
.js,.mjs,.cjs)TypeScript (
.ts,.mts,.cts)JSX (
.jsx)TSX (
.tsx)JSON (
.json)JSONC (
.jsonc)
Integration¶
With VS Code¶
Install the OXC VS Code extension:
VS Code Extension¶
The OXC VS Code extension provides first-class integration with your editor.
Features¶
- Format on Save: Automatically format files when you save them
- Format on Type: Format code as you type (configurable)
- Format Selection: Format only the selected code block
- Error Reporting: Shows parsing errors and formatting issues inline
- Configuration Support: Reads your
oxc.config.jsonautomatically
Extension installation¶
- Open VS Code
- Go to Extensions (Ctrl+Shift+X / Cmd+Shift+X)
- Search for "OXC"
- Click Install on the OXC extension
Or install via CLI:
Recommended Settings¶
{
"editor.defaultFormatter": "oxc.oxc-vscode",
"editor.formatOnSave": true,
"editor.formatOnType": false,
"[javascript]": {
"editor.defaultFormatter": "oxc.oxc-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "oxc.oxc-vscode"
},
"[json]": {
"editor.defaultFormatter": "oxc.oxc-vscode"
}
}
With LazyVim¶
LazyVim includes OXC support as an extra. Enable it in your configuration:
-- In your LazyVim config (e.g., lua/plugins/oxc.lua)
{ import = "lazyvim.plugins.extras.lang.typescript.oxc" }
For more details, see the LazyVim OXC documentation.
With Pre-commit Hooks¶
Add to your .pre-commit-config.yaml:
repos:
- repo: local
hooks:
- id: oxc-format
name: OXC Format
entry: npx oxc format
language: system
files: \.(js|ts|jsx|tsx|json)$
Migration from Prettier¶
Check your config
Before migrating, review your Prettier configuration and map the equivalent options in OXC.
Migration steps:
- Install OXC:
npm install --save-dev oxc - Create
oxc.config.jsonwith your preferred settings - Run formatter:
npx oxc format . - Compare output with your Prettier-formatted code
- Update CI/CD pipelines to use OXC
- Remove Prettier (optional)
Performance Comparison¶
Resources¶
-
Performance metrics are approximate and depend on hardware and codebase size. ↩