Oxlint
Oxlint(/oʊ-ɛks-lɪnt/)是一个基于 Oxc 编译器栈的高性能 JavaScript 和 TypeScript 代码检查工具。
🌐 Oxlint (/oʊ-ɛks-lɪnt/) is a high-performance linter for JavaScript and TypeScript built on the Oxc compiler stack.
为规模而建
🌐 Built for scale
Oxlint 专为大型代码库和持续集成环境而设计。它的架构消除了限制 ESLint 性能的结构性瓶颈。
🌐 Oxlint is built for large repositories and CI environments. Its architecture removes structural bottlenecks that limit performance in ESLint.
我们的基准测试显示,Oxlint 的速度比 ESLint 快 50 到 100 倍。
🌐 Our benchmarks show Oxlint is 50 to 100 times faster than ESLint.
以正确性为重点的默认设置
🌐 Correctness-focused defaults
Oxlint 开箱即用。默认情况下,它优先进行高信号的正确性检查。这些检查会揭示不正确、不安全或无用的代码,因此团队可以在不产生过多干扰的情况下使用 Oxlint。
🌐 Oxlint is useful out of the box. By default, it prioritizes high-signal correctness checks. These checks surface code that is incorrect, unsafe, or useless, so teams can adopt Oxlint without excessive noise.
随着需求的发展,可以逐步启用附加规则。
🌐 Additional rules can be enabled incrementally as requirements evolve.
庞大且不断扩展的规则集
🌐 A large and growing rule set
Oxlint 包含 超过 655 条规则,涵盖大多数团队已经使用的插件,包括:
🌐 Oxlint includes more than 655 rules, with coverage across the plugins most teams already use, including:
- ESLint 核心规则
- TypeScript 规则
- 流行的插件,如 React、Jest、Unicorn 和 jsx-a11y
- 与 ESLint 插件生态系统兼容的自定义 JS 插件
这种广度使迁移变得简单,同时不影响规则覆盖范围。
🌐 This breadth makes migration straightforward without sacrificing rule coverage.
类型感知的代码检查
🌐 Type-aware linting
Oxlint 利用 TypeScript 编译器的原生 Go 版本(tsgo,即 TypeScript 7),提供完整的 TypeScript 兼容性以及你期望从 TypeScript 本身获得的相同类型系统行为。
🌐 Oxlint leverages the native Go port of the TypeScript compiler (tsgo aka TypeScript 7), providing full TypeScript compatibility and the same type system behavior you expect from TypeScript itself.
这可以启用需要类型的关键任务检查,例如检测悬浮的 promise。
🌐 This enables mission critical checks that require types, such as detecting floating promises.
相比之下,Biome 的方法是实现自己的类型推断,而不是依赖 TypeScript 编译器,他们指出覆盖率仍在不断提高。
🌐 In contrast, Biome’s approach is to implement its own type inference instead of relying on the TypeScript compiler, and they note coverage is still improving.
参见:类型感知的代码检查
🌐 See: Type-aware linting
多文件分析
🌐 Multi-file analysis
Oxlint支持多文件分析作为一项一级功能。
🌐 Oxlint supports multi-file analysis as a first-class capability.
启用后,Oxlint 会构建整个项目的模块图,并在规则间共享解析和解析结果。这可以改善依赖跨文件导入的检查,并有助于避免在使用 ESLint 中像 import/no-cycle 这样的规则时常见的性能下降问题。
🌐 When enabled, Oxlint builds a project-wide module graph and shares parsing and resolution across rules. This improves checks that depend on cross-file imports and helps avoid the performance cliff often seen with rules like import/no-cycle in ESLint.
参见:多文件分析
🌐 See: Multi-file analysis
适合人工智能的诊断
🌐 AI-friendly diagnostics
Oxlint 诊断旨在既便于人类阅读,又可供机器操作。
🌐 Oxlint diagnostics are designed to be both human-readable and machine-actionable.
除了清晰的消息之外,诊断还包括结构化信息,如精确的范围和上下文数据。这有助于 AI 理解问题并可靠地应用修复。
🌐 In addition to clear messages, diagnostics include structured information such as precise spans and contextual data. This helps AI to understand issues and apply fixes reliably.
将可靠性作为首要任务
🌐 Reliability as a priority
Oxlint 适用于无法容忍失败的工作流程。
🌐 Oxlint is built for workflows where failures are not acceptable.
崩溃被视为最高优先级的错误。性能回退被视为错误。
🌐 Crashes are treated as top priority bugs. Performance regressions are treated as bugs.
稳定性和吞吐量始终是优先考虑的,尤其是对于持续集成(CI)和大型单体仓库。
🌐 Stability and throughput are always prioritized, especially for CI and large monorepos.
入门
🌐 Getting started
推荐的设置是将 Oxlint 安装为开发依赖并添加脚本。
🌐 The recommended setup is to install Oxlint as a dev dependency and add scripts.
pnpm add -D oxlint向 package.json 添加脚本:
🌐 Add scripts to package.json:
{
"scripts": {
"lint": "oxlint",
"lint:fix": "oxlint --fix"
}
}下一步:
🌐 Next steps:
采用路径
🌐 Adoption paths
TIP
如果你正在从 ESLint 迁移,请查看 从 ESLint 迁移 页面 获取详细指导。
选择适合你仓库的方法:
🌐 Choose the approach that fits your repository:
- 替换 ESLint(大多数项目推荐使用)。 使用 Oxlint 作为你的主要代码检查工具。
- 使用像
@oxlint/migrate这样的工具来迁移你现有的 ESLint 配置。
- 使用像
- 逐步迁移(大仓库推荐)。 先运行 Oxlint,然后在禁用重叠规则的情况下运行 ESLint。这可以在迁移过程中保持 CI 的速度。
- 在同时运行时,使用
eslint-plugin-oxlint来禁用重叠的 ESLint 规则。 - 你也可以——而且应该——为这种方法使用
@oxlint/migrate。
- 在同时运行时,使用
Oxlint 支持什么
🌐 What Oxlint supports
Oxlint 支持:
🌐 Oxlint supports:
- JavaScript 和 TypeScript(
.js、.mjs、.cjs、.ts、.mts、.cts) - JSX 和 TSX(
.jsx,.tsx) - 通过仅对其
<script>块进行 lint 检查来处理框架文件(.vue、.svelte、.astro)
特性
🌐 Features
- 本地插件 提供广泛的规则覆盖,内置 660 条规则,无需庞大的 JavaScript 依赖树。
- 自动修复 可快速应用安全更改。
- 忽略文件 来控制哪些路径会被 lint 检查。
- 内联忽略注释 用于在文件中忽略规则。
- 多文件分析 用于需要项目范围上下文的规则,例如像 no-cycle 这样的导入分析。
- 针对需要 TypeScript 类型信息的规则的类型感知 lint。
- JS 插件(实验性),用于与现有的 ESLint 插件兼容。
使用 Oxlint 的项目
🌐 Projects using Oxlint
Oxlint 被以下流行项目在生产环境中使用:
🌐 Oxlint is used in production by popular projects such as:
迁移
🌐 Migration
参考文献
🌐 References
