Setting up oxfmt and oxlint
Rust-based formatter and linter for JS/TS projects, drop-in replacements for Prettier and ESLint with near-instant runtimes.
Prerequisites
- Bun (or npm/pnpm) project
Steps
Install
bun add -d oxfmt oxlintConfigure oxfmt
- Config file lives at the project root
// .oxfmtrc.jsonc { "$schema": "./node_modules/oxfmt/configuration_schema.json", "ignorePatterns": ["*.gen.ts"], "proseWrap": "always", "sortImports": true, "sortTailwindcss": { "stylesheet": "./src/styles.css", "functions": ["cn"], }, }ignorePatterns— skip generated files (e.g. TanStack Router'srouteTree.gen.ts)sortTailwindcssis only relevant if the project uses Tailwind — pointstylesheetat the global CSS file and list any class-merging helper functions (e.g.cn) infunctionsso classes inside them get sorted too
Configure oxlint
- Config file lives at the project root
// .oxlintrc.jsonc { "$schema": "./node_modules/oxlint/configuration_schema.json", "plugins": ["eslint", "typescript", "oxc", "jsdoc", "react", "react-perf", "unicorn"], "categories": { "correctness": "error", "suspicious": "error", }, "rules": { // Prefer undefined over null "unicorn/no-null": "error", // Not needed for React 17+ "react/react-in-jsx-scope": "off", }, }pluginsmust be listed explicitly — onlyeslint,typescriptandoxcare on by default- Drop
reactandreact-perffor non-React projects - Add rule overrides under
rules, with a one-line comment explaining any non-obvious one
Add scripts to
package.json{ "scripts": { "fmt": "oxfmt .", "fmt:check": "oxfmt --check .", "build": "bun --bun vite build && tsc --noEmit && oxlint .", }, }- Run
oxlintas part ofbuild(or CI) rather than a separate script, so a lint failure blocks the build the same way a type error would
- Run
Wire into VS Code
- Install the oxc extension and set it as the default formatter
// .vscode/extensions.json { "recommendations": ["oxc.oxc-vscode"], }// .vscode/settings.json { "editor.defaultFormatter": "oxc.oxc-vscode", "editor.formatOnSave": true, }
Verification
-
bun fmt:checkexits 0 on a freshly formatted repo -
bun run buildfails when acorrectness-category lint error is introduced - Saving a file in VS Code auto-formats it via the oxc extension
Gotchas
- oxlint plugins are opt-in — forgetting to list
reactinpluginssilently disables all React rules instead of erroring sortTailwindcss.stylesheetmust point to a real CSS file with@import "tailwindcss"(or equivalent) in it, or class sorting silently no-ops