2026-09-13
每日一文 · 长文精读
tsgolint Reaches Stable v7, Bringing Go-Powered Type-Aware Linting to Oxlint
tsgolint 达到稳定版 v7,为 Oxlint 带来 Go 驱动的类型感知检查
作者:Daniel Curtis · InfoQ 原文
摘要:tsgolint 是 Oxlint 背后的类型感知检查引擎,现已发布稳定版 v7。它利用 typescript-go(TypeScript 7 的官方 Go 移植版)处理需要 TypeScript 语义分析的规则,覆盖 typescript-eslint 61 条规则中的 59 条,性能比 ESLint 快 12-18 倍。文章还讨论了与 Biome 的对比、迁移注意事项以及未来工作方向。
tsgolint, the type-aware linting engine behind Oxlint, has reached a stable v7 release, bringing native Go speed to the TypeScript lint rules that teams have long run through ESLint.
tsgolint 是 Oxlint 背后的类型感知检查引擎,现已发布稳定版 v7,将原生的 Go 速度带给了团队长期通过 ESLint 运行的 TypeScript 检查规则。
tsgolint handles the rules that need TypeScript semantic analysis, the ones that answer questions such as whether a promise is ever awaited.
tsgolint 处理那些需要 TypeScript 语义分析的规则,比如判断一个 promise 是否被 await 过。
Rather than reimplementing a type checker, it builds real TypeScript programs on top of typescript-go, the official Go port of the compiler that ships as TypeScript 7.
它没有重新实现类型检查器,而是在 typescript-go(TypeScript 7 附带的编译器的官方 Go 移植版)之上构建真实的 TypeScript 程序。
Oxlint, written in Rust, handles file discovery, configuration and the cheap syntactic rules, then passes the type-aware work to the Go binary, which returns structured diagnostics.
用 Rust 编写的 Oxlint 负责文件发现、配置和廉价的语法规则,然后将类型感知工作传递给 Go 二进制文件,该文件返回结构化的诊断信息。
The release tracks TypeScript v7.0.2 and covers 59 of typescript-eslint's 61 type-aware rules, up from 43 at the December alpha.
该版本跟踪 TypeScript v7.0.2,覆盖了 typescript-eslint 61 条类型感知规则中的 59 条,高于 12 月 alpha 版的 43 条。
Getting started takes two commands:
入门只需两条命令:
pnpm add -D oxlint oxlint-tsgolint@7
pnpm add -D oxlint oxlint-tsgolint@7
pnpm oxlint --type-aware
pnpm oxlint --type-aware
Adding --type-check reports compiler errors alongside lint diagnostics from the same TypeScript program, and both flags can be pinned in an oxlint.config.ts or .oxlintrc.json file.
添加 --type-check 会在同一 TypeScript 程序中同时报告编译错误和检查诊断,这两个标志都可以固定在 oxlint.config.ts 或 .oxlintrc.json 文件中。
The release also adds per-rule timings, surfaced with oxlint --type-aware --debug timings, so teams can see which type-aware rules dominate a run.
该版本还增加了每条规则的计时功能,通过 oxlint --type-aware --debug timings 显示,以便团队了解哪些类型感知规则在运行中占主导地位。
The team's benchmarks put the stable build at 12 to 18 times faster than ESLint with typescript-eslint across microsoft/vscode, microsoft/typescript, typeorm and vuejs/core on an Apple M4 Pro.
团队的基准测试显示,在 Apple M4 Pro 上针对 microsoft/vscode、microsoft/typescript、typeorm 和 vuejs/core,稳定版比使用 typescript-eslint 的 ESLint 快 12 到 18 倍。
Writing before the release, Jökull Sólberg concluded that "Oxlint is making the right long-term bet," reasoning that aligning with tsgo inherits "every future optimisation the TypeScript team ships, while keeping the rule surface identical to typescript-eslint."
在发布前撰文时,Jökull Sólberg 总结道:“Oxlint 正在做出正确的长期押注”,理由是它与 tsgo 对齐,继承了“TypeScript 团队推出的每一个未来优化,同时保持规则表面与 typescript-eslint 一致。”
The same argument runs through a Biome discussion weighing whether Biome should adopt typescript-go too.
同样的论点也贯穿于 Biome 关于是否也应该采用 typescript-go 的讨论中。
Biome v2 synthesises its own types without the compiler, and one analysis puts its noFloatingPromises rule at roughly 75 percent of the cases typescript-eslint catches, a gap it notes Vite creator Evan You has publicly questioned.
Biome v2 在不使用编译器的情况下合成自己的类型,一项分析显示其 noFloatingPromises 规则只能捕获 typescript-eslint 捕获案例的大约 75%,它指出 Vite 创建者 Evan You 公开质疑了这一差距。
The typescript-eslint team, whose contributor auvred created the original prototype, still calls its own tsgolint fork an experiment that is "not under active development."
typescript-eslint 团队(其贡献者 auvred 创建了原始原型)仍将其自己的 tsgolint 分支称为一个“未在积极开发中”的实验。
On the oxc side, correctness is still being refined, with users filing reports such as one where an autofix removed a type assertion that tsc actually required.
在 oxc 方面,正确性仍在完善中,用户提交了报告,例如一个自动修复移除了 tsc 实际需要的类型断言。
ESLint users can run npx @oxlint/migrate --type-aware to translate an existing config, following the migrate-from-eslint guide.
ESLint 用户可以运行 npx @oxlint/migrate --type-aware 来转换现有配置,并遵循 migrate-from-eslint 指南。
The catch is the dependency, because type-aware linting needs TypeScript 7.0 or later, some legacy tsconfig options such as baseUrl are unsupported, and projects using removed TypeScript 6 features have to migrate first.
问题在于依赖关系,因为类型感知检查需要 TypeScript 7.0 或更高版本,一些旧的 tsconfig 选项(如 baseUrl)不受支持,使用已移除的 TypeScript 6 功能的项目必须先迁移。
The jump straight from the experimental 0.x line to a stable v7 is a deliberate change, because tsgolint is now versioned against the compiler it embeds, v7.0.2000 aligns with TypeScript 7.0.2.
从实验性的 0.x 直接跳到稳定版 v7 是一个刻意的改变,因为 tsgolint 现在与其嵌入的编译器版本对齐,v7.0.2000 与 TypeScript 7.0.2 一致。
Work now focuses on the final rules, editor integration and monorepo performance.
目前的工作重点是最终规则、编辑器集成和 monorepo 性能。
Linting is the static-analysis step that flags likely bugs and enforces conventions before code runs, and its most expensive tier is type-aware linting, which needs a real model of a program's types to answer questions a single file cannot.
检查是在代码运行前标记潜在错误并强制执行约定的静态分析步骤,其中最昂贵的层级是类型感知检查,它需要程序类型的真实模型来回答单个文件无法回答的问题。
Oxlint is the linter in oxc, a suite of Rust-based JavaScript tools developed under VoidZero, the company Evan You founded to consolidate a famously fragmented toolchain, and tsgolint is the piece that lets it reach for the real compiler rather than reimplement one.
Oxlint 是 oxc 中的检查器,oxc 是一套基于 Rust 的 JavaScript 工具,由 Evan You 创立的 VoidZero 公司开发,旨在整合著名的碎片化工具链,而 tsgolint 是让它使用真实编译器而不是重新实现一个的部分。
Its stable release lands amid a wider rewrite of that toolchain in native languages, from bundlers and formatters to the TypeScript compiler itself.
它的稳定版发布正值该工具链以原生语言进行更广泛重写之际,从打包器和格式化程序到 TypeScript 编译器本身。
阅读理解
1. How does tsgolint handle type-aware linting?
2. According to the team's benchmarks, how much faster is the stable build of tsgolint compared to ESLint with typescript-eslint?
3. What is a requirement for using tsgolint's type-aware linting?