oxlint
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOxlint — High-Performance JS/TS Linter
Oxlint — 高性能JS/TS代码检查工具
Oxlint is 50-100x faster than ESLint. It ships with 690+ rules covering ESLint core, TypeScript, React, Jest, Unicorn, jsx-a11y, and more. It prioritizes high-signal correctness checks by default — things that are incorrect, unsafe, or useless — so teams can adopt it without drowning in false positives.
Oxlint的速度比ESLint快50-100倍。它内置690+条规则,涵盖ESLint核心、TypeScript、React、Jest、Unicorn、jsx-a11y等内容。默认情况下,它优先进行高信号的正确性检查——即检查错误、不安全或无用的代码——因此团队采用它时不会被大量误报困扰。
Detection
检测
Before linting, confirm the project uses oxlint by checking for any of:
- in
oxlintdevDependencies/dependenciespackage.json - An file in the project root
.oxlintrc.json - An file in the project root
oxlint.config.ts - An or
oxlintscript inlintthat referencespackage.jsonoxlint
If none of these exist, the project doesn't use oxlint — don't run it.
在进行代码检查前,通过以下任一方式确认项目是否使用oxlint:
- 的devDependencies/dependencies中存在
package.jsonoxlint - 项目根目录下存在文件
.oxlintrc.json - 项目根目录下存在文件
oxlint.config.ts - 中的
package.json或oxlint脚本引用了lintoxlint
如果以上都不存在,则该项目未使用oxlint——请勿运行它。
Running Oxlint
运行Oxlint
After code changes
代码修改后
Run oxlint to check your work. Prefer the project's npm script if one exists:
bash
undefined运行oxlint检查你的代码。如果项目有对应的npm脚本,优先使用:
bash
undefinedIf package.json has a lint script using oxlint
若package.json中有使用oxlint的lint脚本
npm run lint
npm run lint
Otherwise, run directly
否则直接运行
npx oxlint
undefinednpx oxlint
undefinedFixing issues automatically
自动修复问题
bash
npx oxlint --fixUse for safe automatic fixes. Avoid unless the user explicitly asks for it — it can apply unsafe transformations.
--fix--fix-dangerouslybash
npx oxlint --fix使用进行安全的自动修复。除非用户明确要求,否则避免使用——它会应用不安全的代码转换。
--fix--fix-dangerouslyLinting specific files
检查特定文件
After editing only a few files, you can lint just those:
bash
npx oxlint src/components/Button.tsx src/utils/helpers.ts当仅修改了少量文件时,你可以只检查这些文件:
bash
npx oxlint src/components/Button.tsx src/utils/helpers.tsInterpreting output
解读输出结果
Oxlint prints diagnostics with rule names in parentheses, e.g. . When fixing:
(no-unused-vars)- Read the diagnostic message carefully — oxlint gives precise, actionable information
- Fix the underlying code issue rather than suppressing the rule
- Only add comments as a last resort when the diagnostic is a genuine false positive
// oxlint-ignore
Oxlint会输出带有规则名称(括号内)的诊断信息,例如。修复时:
(no-unused-vars)- 仔细阅读诊断信息——oxlint会提供精准、可操作的内容
- 修复代码的根本问题,而非禁用规则
- 只有当诊断信息确实是误报时,才作为最后手段添加注释
// oxlint-ignore
Output formats
输出格式
For CI or tooling integration:
bash
npx oxlint --format json # Machine-readable JSON
npx oxlint --format github # GitHub Actions annotations
npx oxlint --format unix # Simple one-line-per-error format用于CI或工具集成:
bash
npx oxlint --format json # 机器可读的JSON格式
npx oxlint --format github # GitHub Actions注释格式
npx oxlint --format unix # 每行一个错误的简单格式Configuration
配置
Creating a config
创建配置文件
bash
npx oxlint --initThis generates an starter config.
.oxlintrc.jsonbash
npx oxlint --init这会生成一个初始配置文件。
.oxlintrc.jsonConfig file format (.oxlintrc.json)
配置文件格式(.oxlintrc.json)
The config uses JSONC (JSON with comments). Key sections:
jsonc
{
// Enable/disable individual rules with severity levels
"rules": {
"no-unused-vars": "error",
"no-console": "warn",
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }]
},
// Enable groups of related rules by category
"categories": {
"correctness": "error", // Definitely-wrong code
"suspicious": "warn", // Probably-wrong code
"pedantic": "off", // Opinionated style checks
"perf": "warn", // Performance anti-patterns
"style": "off", // Cosmetic preferences
"restriction": "off", // Extra-strict rules (opt-in)
"nursery": "off" // Unstable/experimental rules
},
// Plugins to enable (setting this overwrites defaults, so list all you want)
"plugins": ["typescript", "unicorn", "oxc"],
// File-specific overrides
"overrides": [
{
"files": ["**/*.test.{ts,tsx}"],
"rules": { "no-console": "off" }
},
{
"files": ["scripts/**"],
"rules": { "no-console": "off" }
}
],
// Environment globals
"env": {
"browser": true,
"node": true
},
// Plugin-wide settings
"settings": {
"react": {
"linkComponents": [{ "name": "Link", "linkAttribute": "to" }]
},
"jsx-a11y": {
"components": { "Link": "a", "Button": "button" }
}
},
// Type-aware linting (requires tsconfig)
"options": {
"typeAware": true
}
}配置文件使用JSONC(带注释的JSON)格式。关键部分如下:
jsonc
{
// 启用/禁用单个规则并设置严重级别
"rules": {
"no-unused-vars": "error",
"no-console": "warn",
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }]
},
// 按类别启用相关规则组
"categories": {
"correctness": "error", // 绝对错误的代码
"suspicious": "warn", // 可能错误的代码
"pedantic": "off", // 主观的风格检查
"perf": "warn", // 性能反模式
"style": "off", // 美观偏好
"restriction": "off", // 额外严格的规则(需手动启用)
"nursery": "off" // 不稳定/实验性规则
},
// 要启用的插件(设置此项会覆盖默认值,因此需列出所有需要的插件)
"plugins": ["typescript", "unicorn", "oxc"],
// 针对特定文件的覆盖配置
"overrides": [
{
"files": ["**/*.test.{ts,tsx}"],
"rules": { "no-console": "off" }
},
{
"files": ["scripts/**"],
"rules": { "no-console": "off" }
}
],
// 环境全局变量
"env": {
"browser": true,
"node": true
},
// 插件全局设置
"settings": {
"react": {
"linkComponents": [{ "name": "Link", "linkAttribute": "to" }]
},
"jsx-a11y": {
"components": { "Link": "a", "Button": "button" }
}
},
// 类型感知检查(需要tsconfig)
"options": {
"typeAware": true
}
}Rule severity levels
规则严重级别
- /
"off"— Disable the rule"allow" - — Report but don't fail the build
"warn" - /
"error"— Report and exit non-zero"deny"
Unique rule names can omit plugin prefix: = .
"no-console""eslint/no-console"- /
"off"— 禁用规则"allow" - — 报告问题但不导致构建失败
"warn" - /
"error"— 报告问题并返回非零退出码"deny"
唯一的规则名称可以省略插件前缀: = 。
"no-console""eslint/no-console"Categories
规则类别
Categories group rules by intent. The recommended starting point:
- — Always on. Catches real bugs.
correctness: "error" - — Good signal, occasionally noisy.
suspicious: "warn" - Everything else: enable incrementally as the team is ready.
类别按规则的意图分组。推荐的初始设置:
- — 始终启用,捕获真实的bug。
correctness: "error" - — 信号良好,偶尔会有噪声。
suspicious: "warn" - 其他类别:随着团队准备就绪逐步启用。
Available plugins
可用插件
Enabled by default: , ,
typescriptunicornoxcOpt-in (CLI flags or config):
| Plugin | CLI flag | Purpose |
|---|---|---|
| react | | React-specific rules |
| jsx-a11y | | Accessibility rules for JSX |
| nextjs | | Next.js best practices |
| import | | Import/export validation |
| jest | | Jest testing rules |
| vitest | | Vitest testing rules |
| jsdoc | | JSDoc documentation rules |
| node | | Node.js-specific rules |
| promise | | Promise best practices |
| react-perf | | React performance rules |
| vue | | Vue.js rules |
To disable a default plugin: , , .
--disable-typescript-plugin--disable-unicorn-plugin--disable-oxc-plugin默认启用: , ,
typescriptunicornoxc需手动启用(通过CLI标志或配置文件):
| 插件 | CLI标志 | 用途 |
|---|---|---|
| react | | React专属规则 |
| jsx-a11y | | JSX可访问性规则 |
| nextjs | | Next.js最佳实践 |
| import | | 导入/导出验证 |
| jest | | Jest测试规则 |
| vitest | | Vitest测试规则 |
| jsdoc | | JSDoc文档规则 |
| node | | Node.js专属规则 |
| promise | | Promise最佳实践 |
| react-perf | | React性能规则 |
| vue | | Vue.js规则 |
要禁用默认插件:, , 。
--disable-typescript-plugin--disable-unicorn-plugin--disable-oxc-pluginExtending shared configs
扩展共享配置
jsonc
{
"extends": ["./configs/base.json", "./configs/frontend.json"]
}Later entries override earlier ones. Paths resolve relative to the declaring config.
jsonc
{
"extends": ["./configs/base.json", "./configs/frontend.json"]
}后续配置会覆盖之前的配置。路径相对于当前配置文件解析。
Monorepo support
单仓库多项目支持
Oxlint supports nested configs. Each directory can have its own that overrides parent settings. Disable with if unwanted.
.oxlintrc.json--disable-nested-configOxlint支持嵌套配置。每个目录都可以有自己的文件,覆盖父级设置。如果不需要此功能,可使用禁用。
.oxlintrc.json--disable-nested-configCLI Quick Reference
CLI快速参考
| Flag | What it does |
|---|---|
| Use a specific config file |
| TypeScript config for path aliases |
| Auto-fix safe issues |
| Also apply suggested fixes |
| Suppress a rule (e.g., |
| Warn on a rule |
| Error on a rule |
| Suppress warnings, show only errors |
| Treat warnings as errors (exit non-zero) |
| Fail if more than N warnings |
| Output format: default, json, github, unix, etc. |
| Exclude files matching pattern |
| Enable type-informed rules (needs tsconfig) |
| Show resolved config (useful for debugging) |
| List all available rules |
Categories can also be used with //:
-A-W-Dbash
npx oxlint -D correctness -W suspicious -A pedantic| 标志 | 功能 |
|---|---|
| 使用指定的配置文件 |
| 用于路径别名的TypeScript配置 |
| 自动修复安全的问题 |
| 同时应用建议的修复方案 |
| 禁用某条规则(例如: |
| 将某条规则设为警告级别 |
| 将某条规则设为错误级别 |
| 抑制警告,仅显示错误 |
| 将警告视为错误(返回非零退出码) |
| 如果警告数量超过N则构建失败 |
| 输出格式:默认、json、github、unix等 |
| 排除匹配指定模式的文件 |
| 启用类型感知规则(需要tsconfig) |
| 显示解析后的配置(用于调试) |
| 列出所有可用规则 |
类别也可以与//一起使用:
-A-W-Dbash
npx oxlint -D correctness -W suspicious -A pedanticSuppressing rules inline
内联禁用规则
js
// oxlint-ignore no-console -- needed for debug logging
console.log(debugInfo);
// oxlint-ignore-next-line no-unused-vars
const _placeholder = computeValue();Use (not ) — oxlint recognizes both, but prefer its native syntax.
oxlint-ignoreeslint-disablejs
// oxlint-ignore no-console -- 用于调试日志
console.log(debugInfo);
// oxlint-ignore-next-line no-unused-vars
const _placeholder = computeValue();使用(而非)——oxlint可以识别这两种语法,但推荐使用它的原生语法。
oxlint-ignoreeslint-disableMigrating from ESLint
从ESLint迁移
If the project is moving from ESLint to oxlint:
-
Side-by-side approach — Run both linters, withdisabling rules that oxlint already covers:
eslint-plugin-oxlintbashnpm install -D eslint-plugin-oxlintAdd it as the last plugin in your ESLint config. -
Full replacement — Useto convert your ESLint config:
@oxlint/migratebashnpx @oxlint/migrateThis generates anfrom your existing ESLint configuration..oxlintrc.json
如果项目要从ESLint迁移到oxlint:
-
并行方式 — 同时运行两个代码检查工具,使用禁用oxlint已覆盖的规则:
eslint-plugin-oxlintbashnpm install -D eslint-plugin-oxlint在ESLint配置中将它作为最后一个插件添加。 -
完全替换 — 使用转换你的ESLint配置:
@oxlint/migratebashnpx @oxlint/migrate这会从现有的ESLint配置生成一个文件。.oxlintrc.json
Supported file types
支持的文件类型
.js.mjs.cjs.ts.mts.cts.jsx.tsx.vue.svelte.astroFor , , and files, oxlint lints only the blocks.
.vue.svelte.astro<script>.js.mjs.cjs.ts.mts.cts.jsx.tsx.vue.svelte.astro对于、和文件,oxlint仅检查块中的代码。
.vue.svelte.astro<script>