Skip to content

chore: enforce explicit lint rules as errors and freeze existing findings - #5023

Merged
RealKai42 merged 21 commits into
mainfrom
chore/pre-commit-no-autofix
Nov 18, 2026
Merged

RealKai42 merged 21 commits into
mainfrom
chore/pre-commit-no-autofix

Conversation

@RealKai42

@RealKai42 RealKai42 commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

没有对应的 issue。现状有三个问题:

  1. pnpm lint 在 main 上输出两千多条 warning,但 warning 从不让 CI 失败,没人处理;agent 在本地跑 lint 时,这些输出全部进入上下文。
  2. 规则靠「整类开启」:oxlint 升级会悄悄改变规则集合;显式的 plugins 列表还让 oxlint 自带的 bug 检测插件 oxc 一直没有运行。
  3. 文字规则和检查对不上:AGENTS.md 写着 remote executor 的边界「由 lint:imports 强制」,但它不在任何命令或 CI 里。

pre-commit 自动改写代码的问题已经由 #5019 解决。这个 PR 在它的基础上,让 hook 里的 oxlint 和 CI 保持同样的严格度。

这个 PR 之后:lint 只有 error 一档,每条规则显式列出;已有违规的规则冻结存量、拦住新增;lint 配置和各道检查(包括 #5019 的注释检查)的接线由守卫保护。

Bug Reproduction Steps

只针对第 2 个问题里的 oxc 插件,在 main 上:

  1. 在仓库根目录新建 t.ts:

    export function check(value: number): void {
      if (value < 0) new Error('negative');
    }
  2. 运行 pnpm exec oxlint t.ts:没有 error,尽管这个 Error 创建了却没有抛出。

  3. 在 .oxlintrc.json 的 plugins 里加上 "oxc" 后再运行:oxc(missing-throw) 报出这一行。

Root Cause

.oxlintrc.json 里的 plugins 会替换 oxlint 的默认插件集合,而列表里没有 oxc,所以 oxc 的规则一条都没有启用(--print-config 里也没有)。根本修复:把 oxc 加回插件列表,并逐条写出要开启的 oxc 规则。

Code Changes

核心思路:把 lint 从「整类开启、一半是 warn」改成「每条规则显式写成 error」。已有违规、而且修复可能改变行为的规则不改代码,而是由一个棘轮按文件冻结现有数量:新代码不许增加,修掉以后基线只降不升。lint 自身的配置和各道检查的接线由守卫脚本保护,任何变化都会出现在 diff 里。

flowchart LR
  subgraph lint["pnpm lint(CI 的 lint job 运行它)"]
    Z["check-comments.mjs<br/>注释检查"] --> A["oxlint --type-aware --deny-warnings<br/>.oxlintrc.json:170 条 error 规则"]
    A --> B["agent-core-v2 import 边界检查"]
    B --> C["guards.mjs<br/>配置快照 + 接线清单"]
    C --> D["ratchet.mjs<br/>主配置 + 42 条冻结规则"]
  end
  H["pre-commit:lint-staged"] --> Y["check-comments.mjs"]
  Y --> E["oxlint --type-aware --deny-warnings<br/>只检查,不修复"]
  C --> G[("baselines/oxlint-config.json<br/>生效配置快照")]
  D --> F[("baselines/oxlint-ratchet.json<br/>每个文件每条规则的数量")]
Loading

主配置是唯一会拦住编辑器和 pre-commit 的配置,所以只放现在 0 违规的规则;冻结规则放在单独的棘轮配置里,只在 pnpm lint 和 CI 中运行,这样日常编辑和提交不受存量违规干扰。

规则的取舍参考了几个同类 TypeScript 开源项目的 lint 配置:被两个以上项目共同使用、而这里没有开启的通用规则,都是有意关闭并写明了原因的;剩下的差距在项目自定义的分层禁令上,留给后续改动。

关键决策

决策 选择 没选 理由
规则怎么开 所有类别关闭,逐条写出 保留 correctness 整类开启 升级到 1.94 时有 3 条规则被移进 correctness,测试覆盖项里还隐式开启了 13 条 vitest 规则(--print-config 看不到,一下子多出 589 个 error)。逐条写出后,升级不会再悄悄改变规则集合
存量违规怎么处理 自写的棘轮:单独的配置 + 按文件计数的基线 oxlint 原生的批量压制 oxlint 的 --suppress-all 等开关在帮助和文档里是隐藏的,官方给可能的破坏性变更留了余地
冻结规则放在哪 单独的 .oxlintrc.ratchet.json 放进主配置 编辑器和 pre-commit 不受影响;压冻结规则的 disable 指令(例如 TUI 里那条有意的 switch 例外)在主配置里不会被误报为「未使用」
未使用 disable 指令的检查 在棘轮那次运行里做 在主配置里做 只有那次运行同时开着全部规则,判断才准确
以误报为主的规则 关闭,并在配置里写明原因 继续冻结 逐条核对过全部发现:require-post-message-target-origin 的 9 处全是 Worker 和 webview 的 postMessage;no-promise-executor-return 的 33 处全是 new Promise((r) => setTimeout(r, ms)) 一类写法;no-unmodified-loop-condition 和 no-loop-func 的发现也都不是 bug。prefer-nullish-coalescing 会推动把 || 改成 ??,在空串和 0 上改变行为
类型安全规则(no-unsafe-* 等) 只在有类型的源码里冻结 全仓冻结,或者不开 抽样核对过:命中大多在 JS 脚本和 bench 里(参数天然是隐式 any,也不在任何 tsconfig 里),测试里大量是 expect.any() 和 mock。限定范围后冻结 317 处;新代码通常只要先标成 unknown 再收窄
抽样后决定不开的 6 条 关闭,并在配置里写明原因 冻结 例如 no-unnecessary-condition 抽查的 39 处里,有 21 处守护的是类型没有建模的运行时状态(取消信号、外部 JSON);require-await 要防的漏写 await,已被 no-floating-promises 等规则覆盖
棘轮遇到对不上任何规则的诊断 直接失败 跳过 oxlint 把 react hooks 规则报成 react-hooks(...),和配置里的 react/... 对不上,原来会被静默丢弃
已废弃的 API no-deprecated 冻结在现有的 136 处 不开 大部分是 zod 3 的旧 API;冻结后新代码不能再增加。代价:升级依赖时如果出现新的废弃项,需要用 --allow-increase 更新基线
空 catch 块 no-empty 加上 allowEmptyCatch: true 把合并 main 后新增的 116 处冻结进基线 #5019 删掉了空 catch 里的 // ignore 这类注释,以后也不能再写注释,所以新代码没有办法写出合法的空 catch。新增的 116 处全是空 catch;放开后这条规则只剩 2 处,都是测试里空的 for await 循环
no-unnecessary-type-assertion 保持关闭,并写明原因 自动修复后开启 自动修复删掉 1,135 处断言后,tsc 在 41 个文件里报出 97 个类型错误:它判定为多余的断言里,有一部分是 tsc 需要的
依赖过期检查 不做,只在 AGENTS.md 里提示先 pnpm install pnpm 的 verify-deps-before-run=error 全局开启会让 canary 发版失败(它先 install、再改版本号、再 pnpm build);而且在这个仓库里,只要 touch 一下 package.json 就会误报 overrides 过期
ratchet.mjs --update 默认只能降低基线 可以任意改写 防止把新问题直接写进基线;确实是挪动已有代码时用 --allow-increase,并在 PR 里说明

代价:pnpm lint 在本地从约 6 秒变成约 10 秒,多出来的主要是棘轮那一次类型感知运行。

不在这个 PR 里:两条自写规则(禁止 as unknown as T、禁止条件展开空对象,用 oxlint 的 JS 插件实现)和 TypeScript 的 noImplicitReturns,留给后续改动。后者现在会报 45 处,都在 agent-core-v2 和 core;而有 9 个项目通过路径映射直接编译这两个包的源码,所以没法只对这两个包关掉,要先把这 45 处改成显式返回。

阅读指南

  1. .oxlintrc.json:完整规则集,按插件分组;末尾两组是「暂缓」和「有意关闭」,都写了理由。
  2. .oxlintrc.ratchet.json 和 scripts/checks/ratchet.mjs:冻结哪些规则、怎么比对、失败时怎么提示。
  3. scripts/checks/guards.mjs 和 scripts/checks/registry.json:配置快照(包括隐式开启的规则)和接线清单,清单里也登记了注释检查。
  4. scripts/checks/*.test.mjs:26 个测试,由 CI 的 lint job 运行。

可以略读:两个生成的基线 JSON、pnpm-lock.yaml,以及下面折叠块里的机械改动。

改动后的规则一览

规则分四层,越靠前拦得越早:

层 规则数 在哪里拦 对新代码的要求
主配置 .oxlintrc.json 170 条 编辑器、提交前、CI 一处都不允许
React 应用目录(apps/vis/web、apps/vscode/webview-ui) 19 条 同上 一处都不允许
测试文件 16 条 vitest 规则 同上 一处都不允许
棘轮 .oxlintrc.ratchet.json 42 条(冻结 2,129 处) pnpm lint 和 CI 每个文件不能比基线多

另外 19 条有意关闭或暂缓,原因写在配置里,见下面最后一个折叠块。

前三层的 205 条规则,按防的问题分组:

类别 条数 防什么 代表规则
逻辑写错 36 写出来不报错、但结果不是本意的逻辑:恒真恒假的比较、重复的条件或分支、算错的运算 eslint/no-self-compare、oxc/const-comparisons、eslint/no-dupe-else-if
异步与 Promise 13 漏写 await、把 Promise 当普通值用、在 Promise 里混用回调 typescript/no-floating-promises、typescript/no-misused-promises、typescript/await-thenable
类型安全与类型写法 20 绕过或误用类型系统的写法 typescript/no-non-null-asserted-optional-chain、typescript/no-unsafe-enum-assignment、typescript/no-duplicate-type-constituents
模块与导入 16 循环依赖、自己导入自己、重复或写法不一致的导入 import/no-cycle、import/no-self-import、import/no-duplicates
错误处理与异常 7 抛出非 Error 的值、丢掉错误原因、创建了 Error 却没有抛出 typescript/only-throw-error、eslint/preserve-caught-error、oxc/missing-throw
正则与字符串 10 写错的正则、用错的字符串 API eslint/no-invalid-regexp、eslint/no-misleading-character-class、oxc/bad-replace-all-arg
数组、对象与内置 API 的误用 28 对数组、对象、Map、Set 等内置 API 的错误用法 unicorn/no-instanceof-array、unicorn/no-array-fill-with-reference-type、oxc/uninvoked-array-callback
声明、作用域、类与 this 30 变量和类的声明、作用域、this 用错 eslint/no-var、eslint/no-const-assign、eslint/no-this-before-super
运行环境与安全 7 eval、改写全局对象、Node 专有 API 的危险或过时用法 eslint/no-implied-eval、eslint/no-global-assign、eslint/no-caller
lint 指令与类型检查指令 3 绕过 lint 或类型检查的指令必须写明规则和理由 typescript/ban-ts-comment、typescript/prefer-ts-expect-error、unicorn/no-abusive-eslint-disable
React 19 hooks 调用规则、列表 key、直接修改 state 等 React 常见错误 react/rules-of-hooks、react/jsx-key、react/no-direct-mutation-state
测试(vitest) 16 会导致漏测或测试假通过的写法 vitest/no-focused-tests、vitest/expect-expect、vitest/no-identical-title
完整清单:立即生效的 205 条规则

逻辑写错(36 条)

  • eslint/eqeqeq:==/!= 会做隐式类型转换(如 '' == 0 为真),应改用 ===/!==(严格模式,== null 也不允许)
  • eslint/for-direction:for (i = 0; i < 10; i--) 这类计数器朝反方向变化,循环永远不会结束
  • eslint/no-compare-neg-zero:x === -0 对 +0 同样成立,区分不了负零,本意应是 Object.is(x, -0)
  • eslint/no-cond-assign:if (a = b) 这类条件里的赋值,多半是把比较运算符误写成了 =
  • eslint/no-constant-binary-expression:结果恒定的比较或短路运算(如 x === [] 恒为 false),多为笔误或误判优先级
  • eslint/no-constant-condition:if (false) 这类恒定不变的条件,多为笔误或遗留的调试开关
  • eslint/no-debugger:遗留的 debugger 语句,多是调试残留,挂上调试器时会让程序停住
  • eslint/no-dupe-else-if:if-else-if 链中出现重复条件,后面那个分支永远不会执行
  • eslint/no-dupe-keys:对象字面量里同一个 key 写了两次,后写的值会静默覆盖前面的
  • eslint/no-duplicate-case:switch 里有重复的 case 值,后一个分支永远走不到,多为复制粘贴忘改
  • eslint/no-empty-pattern:const { a: {} } = foo 这类空解构不声明任何变量,多半本想写默认值 a = {}
  • eslint/no-extra-boolean-cast:在 if (!!x) 等本就会转布尔的位置再写 !! 或 Boolean(),纯属多余
  • eslint/no-loss-of-precision:数字字面量超出双精度可表示范围(如 9007199254740993),实际值与所写不同
  • eslint/no-self-assign:foo = foo 这类自己赋值给自己的语句没有效果,多为重构未完成
  • eslint/no-self-compare:x === x 这类变量与自身比较,多为笔误或重构遗漏,也让读者困惑
  • eslint/no-unexpected-multiline:不写分号时以 (、[ 或模板串开头的行会接到上一行,意外变成调用或取下标
  • eslint/no-unneeded-ternary:a === 1 ? true : false 这种多余的三元表达式,直接用条件本身即可
  • eslint/no-unreachable:return/throw/break/continue 之后的代码永远不会执行
  • eslint/no-unsafe-negation:!key in obj 实为 (!key) in obj,取反只作用到左操作数,并非本意
  • eslint/no-unsafe-optional-chaining:在不能接受 undefined 的位置用可选链(如 const { a } = obj?.b),短路时抛 TypeError
  • eslint/no-unused-expressions:a === b; 这类求值后结果被丢弃的表达式语句,多为漏写赋值或调用
  • eslint/no-unused-labels:声明了却从未被 break/continue 引用的标签,多为重构残留
  • oxc/bad-char-at-comparison:s.charAt(i) === 'ab' 这类单个字符与多字符字符串比较,结果恒为 false
  • oxc/bad-min-max-func:Math.min(Math.max(100, x), 0) 这类上下界写反的截断,结果恒为常量
  • oxc/bad-object-literal-comparison:x === {}、x === [] 与新建字面量按引用比较,结果恒为 false
  • oxc/const-comparisons:x <= 400 && x > 500 这类恒真/恒假比较或 a < a 自比较,说明运算符或变量写错
  • oxc/double-comparisons:x === y || x < y 这类可合并为 x <= y 的冗余双重比较,读起来易混淆
  • oxc/erasing-op:x * 0 这类结果恒为 0 的运算,另一操作数毫无意义,多半是写错
  • oxc/misrefactored-assign-op:a += a + b 这类复合赋值右侧又写了一遍目标变量,本意多为 a += b
  • oxc/only-used-in-recursion:参数只在递归调用里原样传递、从未真正使用,多为错误,徒增理解成本
  • eslint/require-yield:function* 生成器里一个 yield 都没有,多半是写错了
  • typescript/no-duplicate-enum-values:枚举成员取值重复(如 A = 0, B = 0),两个成员无法区分,易出隐蔽 bug
  • typescript/no-meaningless-void-operator:对本就返回 void 或 undefined 的表达式再加 void(如 void foo()),毫无意义
  • unicorn/no-negation-in-equality-check:!foo === bar 实际是 (!foo) === bar,本意多半是 foo !== bar
  • eslint/use-isnan:x === NaN 这类与 NaN 的比较永远为假,应改用 Number.isNaN(x)
  • eslint/valid-typeof:typeof x === 'strnig' 与非法类型名比较,结果恒为 false,多为拼写错误

异步与 Promise(13 条)

  • eslint/no-async-promise-executor:new Promise(async (resolve) => …) 内抛出的错误不会让 Promise reject,会被吞掉
  • promise/no-multiple-resolved:Promise 执行器中某条路径会先后调用 reject 和 resolve,后一次调用无效,说明逻辑有误
  • promise/no-new-statics:new Promise.resolve(x) 对 Promise 静态方法用 new,运行时抛 TypeError
  • promise/no-return-in-finally:promise.finally() 回调里的 return 值会被忽略,写了只会误导读者
  • promise/valid-params:Promise.resolve(1, 2) 这类参数个数不对的 Promise 方法调用,行为与预期不符
  • typescript/await-thenable:await 一个不是 Promise 的值,常是漏了调用(如 await getPromise)
  • typescript/no-floating-promises:Promise 既没 await、也没 .catch 或返回,执行顺序会错乱、拒绝无人处理
  • typescript/no-misused-promises:在 if (promise)、forEach(async …) 等不会等待 Promise 的位置使用 Promise,多为漏了 await
  • typescript/return-await:try 中 return p 不加 await,catch 就捕获不到它的 reject;try 外则不应加 await
  • unicorn/no-await-in-promise-methods:Promise.all([await p, q]) 在数组里先 await,会推迟后续元素求值、失去并发
  • unicorn/no-single-promise-in-promise-methods:Promise.all([p]) 只包了一个 Promise,包装多余,直接 await p 即可
  • unicorn/no-thenable:对象或类定义了 then 属性,一旦被误 await 就会被当成 Promise 处理,引发问题
  • unicorn/no-unnecessary-await:await 非 Promise 值没有意义,如 await [p1, p2] 并不会等待数组里的 Promise

类型安全与类型写法(20 条)

  • typescript/consistent-type-assertions:使用 <Foo>x 尖括号类型断言,与 JSX 语法冲突,统一改写为 x as Foo
  • typescript/no-base-to-string:String(obj)、obj + '' 等把没有自定义 toString 的对象转字符串,只得到 [object Object]
  • typescript/no-confusing-non-null-assertion:a! == b 中非空断言 ! 紧挨 ==,容易被误读成 !=
  • typescript/no-duplicate-type-constituents:联合或交叉类型里重复的成员(如 A | A | B),毫无作用且多为笔误
  • typescript/no-extra-non-null-assertion:foo!!.bar 这类对同一个值叠加多个非空断言,多出的 ! 毫无作用
  • typescript/no-misused-new:class 里定义 new 方法或 interface 里声明 constructor,构造签名写错了
  • typescript/no-mixed-enums:同一个 enum 里混用数字和字符串成员,编译后的运行时行为容易出乎意料
  • typescript/no-non-null-asserted-nullish-coalescing:foo! ?? bar 既断言非空又给空值兜底,自相矛盾,说明混淆了 ! 与 ??
  • typescript/no-non-null-asserted-optional-chain:foo?.bar! 可选链本就可能得到 undefined,再用 ! 断言非空自相矛盾
  • typescript/no-redundant-type-constituents:联合类型里不改变结果的冗余成员,如与 any/unknown 并列的类型,徒增阅读负担
  • typescript/no-unnecessary-type-arguments:显式写出与泛型默认值相同的类型参数,如默认就是 string 还写 f<string>()
  • typescript/no-unnecessary-type-constraint:<T extends any>、<T extends unknown> 的约束多余,泛型参数默认就是 unknown
  • typescript/no-unsafe-declaration-merging:同名 interface 与 class 声明合并,TS 不检查接口属性是否初始化,可能运行时出错
  • typescript/no-unsafe-enum-assignment:把裸数字或字符串当 enum 值用,如 const f: Fruit = 0,绕过了枚举类型约束
  • typescript/no-unsafe-unary-minus:对非 number/bigint 的值取负(如 -str),会隐式类型转换,结果出人意料
  • typescript/no-wrapper-object-types:用 String、Number、Object 等包装对象类型做注解,应改用小写原始类型
  • typescript/prefer-as-const:let x: 'a' = 'a' 把字面量类型重复写一遍,应改用 as const
  • typescript/prefer-literal-enum-member:enum 成员值用变量或表达式计算,枚举自带作用域会让取值出乎意料
  • typescript/restrict-plus-operands:+ 两侧类型不一致(如 num + str),会隐式转换成字符串拼接等意外结果
  • typescript/restrict-template-expressions:模板字符串插入对象、数组等非原始类型,会得到 [object Object] 之类无意义文本

模块与导入(16 条)

  • import/default:对没有 default 导出的模块做默认导入,运行时拿到 undefined 或直接报错
  • import/extensions:相对导入带 .js/.ts/.tsx 后缀(如 './foo.js'),按本仓库配置应省略扩展名
  • import/namespace:import * as ns 后访问模块并未导出的 ns.foo,运行时会出错
  • import/no-absolute-path:用 /foo 这类绝对路径导入模块,换台机器或发布到 npm 就会失效
  • import/no-cycle:模块间存在循环依赖,导入时可能拿到尚未初始化的 undefined,架构也难以理清
  • import/no-duplicates:同一模块被拆成多条 import 重复导入,冗余且易造成用法不一致
  • import/no-empty-named-blocks:import {} from 'mod' 这类空的具名导入块毫无作用,多是删导入后的残留
  • import/no-self-import:模块导入自身(foo.js 中 import './foo.js'),形成循环依赖,可能拿到 undefined
  • eslint/no-import-assign:给 import 进来的绑定或命名空间成员赋值,ES 模块导入是只读的,运行时报错
  • node/no-exports-assign:exports = {} 赋的新对象并不会被导出,应改写 module.exports
  • typescript/no-useless-empty-export:文件已有其他 import/export 时多余的 export {},不起任何作用
  • typescript/prefer-namespace-keyword:用 module Foo {} 声明命名空间是过时写法,应改写为 namespace Foo {}
  • typescript/triple-slash-reference:用 /// <reference path> 或与 import 重复的 /// <reference types> 引入依赖,应改用 import
  • unicorn/no-empty-file:只有注释、空白或指令、没有实际代码的文件,多为重构遗留
  • unicorn/prefer-node-protocol:导入 Node 内置模块不带 node: 前缀(如 'fs'),易与同名模块混淆
  • unicorn/require-module-specifiers:import {} from 'foo'、export {} 这类空说明符列表毫无作用,徒增困惑

错误处理与异常(7 条)

  • eslint/no-ex-assign:在 catch (e) 里给 e 重新赋值,原始异常就此丢失、无从追查
  • eslint/no-unsafe-finally:finally 里的 return/throw/break 会覆盖 try/catch 中已有的返回值或异常
  • eslint/no-useless-catch:只把错误原样 throw e 重新抛出的 catch 块毫无作用
  • oxc/missing-throw:new Error() 前漏写 throw,错误对象创建后直接被丢弃,并没有抛出
  • eslint/preserve-caught-error:catch 中重新 throw new Error() 却没带 { cause: err },原始错误信息丢失
  • typescript/only-throw-error:throw 'error' 这类抛出非 Error 的值,没有调用栈,难以排查
  • unicorn/no-useless-error-capture-stack-trace:Error 子类构造函数里调用 Error.captureStackTrace,父构造函数已自动完成,属多余

正则与字符串(10 条)

  • eslint/no-empty-character-class:正则里的空字符类 [](如 /^abc[]/)匹配不到任何字符,多为笔误
  • eslint/no-invalid-regexp:new RegExp('[') 这类非法正则字符串,要到运行时才抛 SyntaxError
  • eslint/no-irregular-whitespace:代码中混入 NBSP、零宽空格等不可见的异常空白字符,难以察觉且可能干扰解析
  • eslint/no-misleading-character-class:正则字符类里写 [👍🏻] 这类多码点字符,会被拆成单个码点分别匹配
  • eslint/no-nonoctal-decimal-escape:字符串里的 \8、\9 是规范遗留语法,实际就等于 8、9,不应再使用
  • eslint/no-useless-backreference:正则中永远只能匹配空串的反向引用,如 /\1(a)/ 在分组之前就引用
  • eslint/no-useless-escape:字符串或正则中多余的转义(如 '\e' 就是 'e'),不改变含义却干扰阅读
  • oxc/bad-match-all-arg:str.matchAll(/x/) 传入不带 g 标志的正则,运行时直接抛 TypeError
  • oxc/bad-replace-all-arg:str.replaceAll(/x/, y) 传入不带 g 标志的正则,运行时直接抛 TypeError
  • unicorn/prefer-string-starts-ends-with:用 /^abc/.test(s) 判断前后缀,应改用不需解析正则、更易读的 startsWith/endsWith

数组、对象与内置 API 的误用(28 条)

  • eslint/no-array-constructor:用 new Array(a, b) 代替 [a, b] 建数组,单参数时含义却变成长度,易混淆
  • eslint/no-iterator:使用已废弃的非标准 __iterator__ 属性,应改用 Symbol.iterator
  • eslint/no-new-native-nonconstructor:new Symbol()、new BigInt() 会直接抛 TypeError,它们不是构造器
  • eslint/no-new-wrappers:new String/Number/Boolean() 得到对象而非原始值,new Boolean(false) 也是真值
  • eslint/no-obj-calls:把 Math()、JSON()、Reflect() 等全局对象当函数调用,运行时抛 TypeError
  • eslint/no-object-constructor:用无参 new Object() 建空对象,应写 {},且全局 Object 可能被改写
  • eslint/no-prototype-builtins:直接调 obj.hasOwnProperty(k),遇到 Object.create(null) 或同名属性遮蔽时会出错
  • eslint/no-sparse-arrays:[1, , 2] 这类带空位的稀疏数组,空位上并没有元素,易引起混淆
  • oxc/bad-array-method-on-arguments:对 arguments 直接调用数组方法(如 arguments.reduce),它不是真数组,会抛 TypeError
  • oxc/number-arg-out-of-range:n.toString(64) 这类数字方法的进制或精度参数越界,进制超出 2–36 会抛 RangeError
  • oxc/uninvoked-array-callback:new Array(5).map(fn) 作用在全是空槽的数组上,回调根本不会执行
  • eslint/prefer-spread:fn.apply(null, args) 是 ES2015 之前的写法,应改用展开语法 fn(...args)
  • eslint/radix:parseInt(s) 不传进制时会把 0x 开头的串按十六进制解析,结果出乎意料
  • typescript/no-array-delete:delete arr[i] 只在数组里留下空洞、长度不变,应改用 splice
  • typescript/no-for-in-array:用 for...in 遍历数组,会连带遍历到原型和实例上额外的可枚举属性
  • typescript/no-misused-spread:{...promise}、{...fn}、{...map} 这类展开拿不到预期内容,本意多是 await、调用或转换
  • typescript/require-array-sort-compare:nums.sort() 不传比较函数会按字符串排序,[1, 10, 2] 排不成 [1, 2, 10]
  • unicorn/no-array-fill-with-reference-type:new Array(3).fill({}) 让所有元素共享同一个对象,改一处全跟着变
  • unicorn/no-confusing-array-with:arr.with(arr.length, v) 必然越界抛 RangeError,arr.with(-1, v) 的负下标含义易被误解
  • unicorn/no-instanceof-array:x instanceof Array 跨 iframe 或 vm 上下文时判断失效,应改用 Array.isArray
  • unicorn/no-instanceof-builtins:对 Array、String 等内置构造器用 instanceof,跨 iframe/vm 或遇到原始值时会判断错误
  • unicorn/no-invalid-fetch-options:fetch/new Request 在 GET、HEAD 请求中带 body,运行时直接抛 TypeError
  • unicorn/no-invalid-remove-event-listener:removeEventListener('click', () => {}) 传入新建函数,原监听器根本移除不掉
  • unicorn/no-new-array:new Array(n) 只传一个参数时,分不清是指定长度还是唯一元素
  • unicorn/no-useless-fallback-in-spread:{ ...(foo ?? {}) } 里的空对象兜底多余,展开 null/undefined 本就不会添加属性
  • unicorn/no-useless-length-check:arr.length === 0 || arr.every(f) 中的长度检查多余,every 对空数组本就返回 true
  • unicorn/no-useless-spread:[...[1, 2]]、Promise.all([...iterable]) 这类多余展开,原值本可直接使用
  • unicorn/prefer-set-size:[...set].length 为了计数新建数组,应直接用 set.size

声明、作用域、类与 this(30 条)

  • eslint/accessor-pairs:对象或类里只有 setter 没有 getter 的属性,写进去的值永远读不到
  • eslint/block-scoped-var:var 在块内声明却在块外使用(如循环后读 i),依赖变量提升,作用域易被误读
  • eslint/constructor-super:派生类构造函数漏调 super(),或非派生类误调 super(),运行时会直接报错
  • eslint/getter-return:getter 没有 return 值,读取该属性只得到 undefined,多半是漏写了
  • eslint/no-case-declarations:在 case 里直接写 let/const/函数声明,作用域覆盖整个 switch 却可能未初始化
  • eslint/no-class-assign:给 class 声明的类名重新赋值(如 class A {} 后 A = 0),几乎都是笔误
  • eslint/no-const-assign:给 const 变量重新赋值(包括 +=),运行时直接抛 TypeError
  • eslint/no-constructor-return:构造函数里 return 一个值,会被忽略或替换掉 new 的结果,多为误写
  • eslint/no-delete-var:对变量用 delete x:delete 只用于删除对象属性,用在变量上行为出乎意料
  • eslint/no-dupe-class-members:类中同名成员重复声明,后者静默覆盖前者(如方法被同名字段覆盖)
  • eslint/no-empty-static-block:空的 static {} 块什么也不做,多为未完成的重构
  • eslint/no-extra-bind:对箭头函数或不使用 this 的函数调用 .bind(),绑定不起任何作用
  • eslint/no-func-assign:给函数声明重新赋值(如 function foo() {} 后 foo = bar),多为笔误
  • eslint/no-setter-return:setter 里 return 一个值会被静默忽略,多半是写错了
  • eslint/no-shadow-restricted-names:用 undefined、NaN、eval 等作变量或参数名,遮蔽了内置含义,易引发混乱
  • eslint/no-this-before-super:派生类构造函数在 super() 之前使用 this/super,运行时抛 ReferenceError
  • eslint/no-unassigned-vars:let/var 变量只被读取从未赋值,读到的永远是 undefined,多为漏写赋值
  • eslint/no-unused-private-class-members:声明了却从未被读取的 #私有 字段或方法,多为重构残留
  • eslint/no-unused-vars:声明后从未被使用的变量、导入、参数或类型,多为重构残留
  • eslint/no-useless-rename:import { foo as foo }、{ a: a } = obj 这种改成同名的重命名纯属多余
  • eslint/no-var:var 是函数作用域,块内声明会泄漏到块外,应改用 let/const
  • eslint/no-with:with 把对象属性混入当前作用域,看不出变量指向谁,严格模式下已禁止
  • oxc/no-this-in-exported-function:导出函数里使用 this,被其他模块导入调用时 this 通常是 undefined
  • eslint/prefer-rest-params:用 arguments 取可变参数,它不是真数组、用起来别扭,应改用 ...args
  • typescript/no-extraneous-class:只有静态成员或只有构造函数的类没有存在必要,应改用模块级函数或常量
  • typescript/no-this-alias:const self = this 给 this 起别名,用箭头函数即可直接捕获 this
  • typescript/no-unnecessary-parameter-property-assignment:参数属性(constructor(public name))已自动赋值,再写 this.name = name 多余
  • typescript/unbound-method:把方法单独取出调用(const f = obj.method; f()),会丢失 this 导致运行时出错
  • unicorn/no-accessor-recursion:getter/setter 里读写自身属性(如 get bar() { return this.bar }),会无限递归导致栈溢出
  • unicorn/no-this-assignment:const self = this 把 this 存进变量,徒增间接、让代码更难追踪

运行环境与安全(7 条)

  • eslint/no-caller:使用已废弃的 arguments.callee/arguments.caller,严格模式下直接报错且妨碍引擎优化
  • eslint/no-eval:用 eval() 执行字符串代码,处理不可信输入时有注入风险,而且慢
  • eslint/no-extend-native:Object.prototype.x = … 这类扩展内置对象,会影响所有代码并污染 for…in 遍历
  • eslint/no-global-assign:给只读全局变量重新赋值(如 Object = null),会丢掉内置功能
  • eslint/no-implied-eval:setTimeout('code()', 100) 传字符串会像 eval 一样执行,有安全与性能隐患
  • typescript/no-implied-eval:setTimeout('code')、new Function(...) 把字符串当代码执行,等同 eval,有安全和性能风险
  • unicorn/no-new-buffer:new Buffer() 已被 Node 废弃,应改用 Buffer.from() 或 Buffer.alloc()

lint 指令与类型检查指令(3 条)

  • typescript/ban-ts-comment:@ts-ignore、@ts-nocheck 会压制类型错误,一律禁止;@ts-expect-error 须附 ≥10 字符说明
  • typescript/prefer-ts-expect-error:@ts-ignore 在错误修好后仍会留着并压制新错误,应改用无错时会报错的 @ts-expect-error
  • unicorn/no-abusive-eslint-disable:不带规则名的 eslint-disable/oxlint-disable 注释会屏蔽全部规则,掩盖真实问题

React(19 条)

  • react/forward-ref-uses-ref(React 目录):forwardRef((props) => ...) 回调没接收 ref 参数,forwardRef 形同虚设
  • react/jsx-key(React 目录):list.map(x => <Item />) 生成的元素没有 key,React 无法正确识别列表项的增删改
  • react/jsx-no-duplicate-props(React 目录):同一 JSX 元素重复写同名属性(<App a a />),多为笔误且行为难料
  • react/jsx-no-undef(React 目录):JSX 里用了未声明的组件如 <Foo />,多为拼写错误,运行时抛 ReferenceError
  • react/jsx-props-no-spread-multi(React 目录):同一元素上重复展开同一对象(如 {...props} a="1" {...props}),夹在中间的属性会被覆盖
  • react/no-children-prop(React 目录):用 children 属性传子节点(<div children='x' />),应写在开闭标签之间
  • react/no-danger-with-children(React 目录):同一元素同时传 children 和 dangerouslySetInnerHTML,React 会因冲突发出警告
  • react/no-did-mount-set-state(React 目录):componentDidMount 里调用 setState 会立即触发第二次 render,造成性能问题和布局抖动
  • react/no-did-update-set-state(React 目录):在 componentDidUpdate 里调用 setState 会再触发一次 render,可能导致布局抖动
  • react/no-direct-mutation-state(React 目录):直接改 this.state.x = ...,改动可能被随后的 setState() 覆盖掉
  • react/no-find-dom-node(React 目录):使用已废弃、React 19 已移除的 findDOMNode,它会穿透组件封装
  • react/no-is-mounted(React 目录):this.isMounted() 是反模式,class 组件与函数组件中均不可用
  • react/no-render-return-value(React 目录):使用 ReactDOM.render() 的返回值是遗留用法,React 19 已彻底移除该 API
  • react/no-string-refs(React 目录):ref="hello" 这类字符串 ref 自 React 16.3 起废弃,React 19 已移除
  • react/no-this-in-sfc(React 目录):函数组件里使用 this.props,函数组件的 props 来自参数而非 this
  • react/no-unsafe(React 目录):使用 UNSAFE_componentWillMount 等遗留生命周期,常被误用,在异步渲染下易出问题
  • react/no-will-update-set-state(React 目录):componentWillUpdate 里调用 setState,在更新阶段改状态会让组件状态不可预测
  • react/rules-of-hooks(React 目录):在条件、循环或非组件函数里调用 Hook,渲染间调用顺序不一致会让状态错乱
  • react/void-dom-elements-no-children(React 目录):给 <br>、<img> 等空元素传入 children,这类元素只能自闭合、不能有子节点

测试(vitest)(16 条)

  • vitest/expect-expect(测试文件):测试里没有任何 expect/assert 断言,被测代码坏了测试也照样通过(把 expect*、assert*、*.expect* 等辅助函数也算作断言)
  • vitest/hoisted-apis-on-top(测试文件):vi.mock 等会被提升到文件顶部先于导入执行,写在条件或测试体内会误导读者
  • vitest/no-commented-out-tests(测试文件):被注释掉的测试(如 // it(...))容易被遗忘,应改用 skip 或直接删除
  • vitest/no-conditional-tests(测试文件):用 if 包住 it/test/describe,测试是否注册取决于运行时条件,结果不确定
  • vitest/no-focused-tests(测试文件):提交了 it.only/describe.only,构建时其余测试会被跳过
  • vitest/no-identical-title(测试文件):同一层级的 describe/test 标题重复,失败时难以分辨是哪一个出错
  • vitest/no-import-node-test(测试文件):误从 node:test 导入测试函数,与 Vitest 混用会导致测试结果不一致
  • vitest/no-interpolation-in-snapshots(测试文件):内联快照里写 ${} 插值会使快照无法更新,应改用属性匹配器
  • vitest/no-mocks-import(测试文件):直接 import __mocks__ 目录里的文件,绕过了框架的自动 mock 机制
  • vitest/no-standalone-expect(测试文件):expect 写在 it/test 之外(如 describe 体内),不属于任何测试,断言形同虚设
  • vitest/no-unneeded-async-expect-function(测试文件):expect(async () => await f()) 多包了一层 async 函数,直接 expect(f()) 即可
  • vitest/prefer-snapshot-hint(测试文件):同一作用域多个 toMatchSnapshot() 未写提示名,增删一个就让后续快照编号错位
  • vitest/require-awaited-expect-poll(测试文件):expect.poll/expect.element 返回的 Promise 未被 await,测试会在断言完成前结束
  • vitest/require-local-test-context-for-concurrent-snapshots(测试文件):并发测试中用全局 expect 做快照,全局 expect 追踪不了并发测试,须用上下文的 expect
  • vitest/valid-describe-callback(测试文件):describe 的回调带参数、含 return 或根本不是函数,会导致测试意外出错
  • vitest/valid-expect-in-promise(测试文件):在 .then() 回调里调用 expect 却没有 await 或 return 该 Promise,断言可能还没跑测试就结束了
冻结的 42 条规则:防什么、新代码怎么写
规则 范围 冻结 防什么 新代码怎么写
typescript/no-explicit-any 全部文件(测试除外) 545 显式写 any 会关闭该处的类型检查,类型错误被推迟到运行时 用 unknown 再收窄,或写出具体类型
eslint/no-unused-vars 测试文件 239 声明后从未被使用的变量、导入、参数或类型,多为重构残留 删掉,或补上漏写的断言
vitest/no-conditional-expect 测试文件 236 expect 写在 if/catch 等条件分支里,分支没执行时测试会静默通过 用 expect(...).rejects、toThrow,或拆成多个用例
unicorn/no-array-sort 全部文件 142 使用 arr.sort() 的返回值,它会原地改动原数组,应改用 toSorted() 用不修改原数组的 toSorted()
typescript/no-deprecated 全部文件 136 使用标注了 @deprecated 的 API;TS 只在编辑器里划线、不报错,容易被忽视 换成文档推荐的新 API,如 zod 4 的 z.url()、z.looseObject()
typescript/no-unsafe-assignment 有类型的源码 119 把 any 值赋给有类型的变量或属性(如 const s: string = anyValue),绕过了类型检查 先标成 unknown,再收窄或用 zod 校验
typescript/use-unknown-in-catch-callback-variable 全部文件 108 .catch(err => …) 回调的参数没标成 unknown,拒绝值实为任意类型却可不经检查直接使用 写成 .catch((error: unknown) => ...)
typescript/no-unsafe-member-access 有类型的源码 89 在 any 值上访问成员如 anyValue.foo,成员是否存在完全无从检查 先标成 unknown,再收窄或用 zod 校验
typescript/no-unsafe-argument 有类型的源码 72 把 any 类型的值作为参数传给函数,绕过了参数的类型检查 先标成 unknown,再收窄或用 zod 校验
typescript/prefer-promise-reject-errors 全部文件 60 Promise.reject('error') 这类用非 Error 值拒绝,没有调用栈,难以排查 reject(new Error(...))
typescript/switch-exhaustiveness-check 全部文件 56 对联合类型 switch 时漏掉某个成员的 case,即使有 default 也照样报 补全联合类型的每个分支,不用 default 兜底
eslint/no-unsafe-optional-chaining 测试文件 42 在不能接受 undefined 的位置用可选链(如 const { a } = obj?.b),短路时抛 TypeError 先判空,再调用或展开
eslint/prefer-const 全部文件 41 从未重新赋值的 let 应改为 const,让读者一眼确定它不会被改 不会重新赋值的变量用 const
typescript/no-unsafe-return 有类型的源码 36 函数返回 any 值,把类型不安全传给调用方,声明的返回类型形同虚设 给返回值写明类型,或先校验再返回
typescript/no-unnecessary-type-parameters 有类型的源码 32 只出现一次的泛型参数(如 parse<T>(s: string): T)关联不了任何类型,还可能掩盖不安全的类型断言 返回 unknown,再用 zod 校验
import/no-named-as-default-member 全部文件 27 通过默认导入读取同名具名导出(如 foo.bar),可能拿到 undefined,应改为 import { bar } 改用具名导入,如 import { join } from 'pathe'
typescript/no-unnecessary-boolean-literal-compare 全部文件 24 布尔值再与 true/false 字面量比较(如 ok === true),比较多余 已经是 boolean 时直接用,不写 === true
typescript/no-unnecessary-type-conversion 全部文件 23 对已是目标类型的值再做转换,如 String('a'),类型和值都不变 去掉多余的 String()、Number() 等转换
eslint/no-console packages//src、apps//src 20 代码里的 console.log 等调试输出,不应进入发布的产品代码 走日志服务;确需直接输出时写带理由的 disable 指令
typescript/no-unsafe-function-type 全部文件 11 使用内置 Function 类型,可用任意参数调用且返回 any,失去类型检查 写出具体的函数签名,不用 Function
oxc/no-accumulating-spread 全部文件 8 在 reduce 或循环里反复 { ...acc } 展开累加器,时间和内存退化到 O(n²) 用 Object.fromEntries(...),或在局部可变的累加器上修改
eslint/no-regex-spaces 全部文件 7 正则里连续多个空格(如 /foo bar/)看不清个数,应写成 /foo {3}bar/ 连续空格写成量词,如 / {3}/
react/exhaustive-deps React 应用 7 useEffect 等 Hook 的依赖数组缺失或不全,effect 会多跑或该跑时不跑 把 hook 用到的值都写进依赖数组
typescript/no-useless-default-assignment 全部文件 6 给永远不会是 undefined 的参数写默认值,如 [1].map((a = 0) => a),永不生效 删掉永远用不到的默认值
typescript/no-require-imports 全部文件 5 用 require() 导入模块,路径等错误要到运行时才暴露,应改用静态 import 改用 import
typescript/no-unnecessary-template-expression 全部文件 5 模板字符串里插入字符串字面量或本就是字符串的值(如 ${'b'}),属多余插值 直接用变量,不要包成 `${x}`
unicorn/no-array-reverse 全部文件 5 arr.reverse() 会原地修改原数组,应改用返回新数组的 toReversed() 用不修改原数组的 toReversed()
vitest/valid-title 测试文件 5 测试标题为空、不是字符串、首尾带空格或以块名开头(如 it('it foo')),会误导读者 用字符串写测试标题
eslint/no-sequences 全部文件 4 未加括号的逗号运算符如 x = a(), b,常掩盖副作用,且多半是误用 拆成多条语句
promise/no-callback-in-promise 全部文件 3 在 .then()/.catch() 里调用回调 cb(),回调抛错会进入 .catch 导致它再被调用一次 改用 async/await,不在 then 里调用回调
promise/no-promise-in-callback 全部文件 3 在 (err, val) => {} 式错误优先回调里使用 Promise,混用两种异步模式使错误处理混乱 统一改用 async/await
typescript/no-namespace 全部文件 3 使用 TS namespace 这种过时的组织方式,应改用 ES 模块的 import/export 用 ES 模块组织代码
eslint/no-empty 全部文件 2 if (x) {} 这类空代码块(空 catch 与含注释的块除外),多为未写完的残留 删掉空代码块,或写上实际逻辑(空 catch {} 允许)
eslint/array-callback-return 全部文件 1 arr.map(x => { f(x); }) 这类 map/filter/reduce 等回调漏写 return,多半是写错了 回调的每条路径都返回值
eslint/no-useless-constructor 全部文件 1 空构造函数或只把参数原样传给 super(...) 的构造函数,删掉后行为不变 删掉什么都不做的构造函数
import/no-named-as-default 全部文件 1 默认导入起的名字与该模块某个具名导出同名,易混淆到底导入的是哪个 改用具名导入
oxc/bad-comparison-sequence 全部文件 1 a == b == c 实际是先比 a == b,再拿布尔结果和 c 比较 拆成 a < b && b < c
typescript/no-unsafe-enum-comparison 全部文件 1 枚举值与非本枚举的值比较(如 status === 'unknown'),绕过了枚举的类型保护 和枚举成员比较,不和字面量比较
typescript/related-getter-setter-pairs 全部文件 1 getter 返回类型无法赋给同名 setter 的参数类型,连 o.x = o.x 都不成立 让 getter 的返回类型和 setter 的参数类型一致
typescript/no-unsafe-call 有类型的源码 1 调用 any 类型的值,TS 无法检查它是否可调用、参数和返回值是否正确 先标成 unknown,再收窄或用 zod 校验
vitest/no-disabled-tests 测试文件 1 it.skip、xtest、无回调的 it('x') 等被禁用的测试,容易被遗忘而提交 修好或删掉被跳过的测试
eslint/no-fallthrough 全部文件 0 case 末尾既无 break 也无 // falls through 注释,会意外落入下一个分支 每个 case 用 break、return 或 throw 结束
有意关闭或暂缓的 19 条
规则 原因
typescript/no-non-null-assertion 暂缓:存量太大(源码 1,059 处、测试 3,848 处),同类项目里有的开、有的主动关掉
eslint/no-redeclare TS 自己会报真正的重复声明(ts(2451));这条会误报 DI 写法里同名的服务接口和标识符
typescript/no-empty-object-type 事件和服务声明要靠「只继承载荷类型的空接口」和类合并
typescript/no-unnecessary-type-assertion 它判定多余的断言里有一部分是 tsc 需要的:按它修复后,tsc 在 41 个文件里报 97 个错
eslint/no-control-regex TUI 有意匹配终端控制字符
promise/catch-or-return no-floating-promises 已经覆盖未处理的 Promise
unicorn/require-post-message-target-origin 只适用于 window.postMessage;这里全是 Worker、MessagePort 和 VS Code webview,9 处全是误报
eslint/no-promise-executor-return 33 处全是 new Promise((r) => setTimeout(r, ms)) 一类无害写法
eslint/no-unmodified-loop-condition 12 处都是复合条件里另一个操作数在变,或标志位由回调在 await 期间设置
eslint/no-loop-func 11 处都是本轮迭代内执行的回调,或有意和循环共享状态
typescript/prefer-nullish-coalescing 修复会把 || 改成 ??,对空串和 0 的结果不同;这里很多 || 是有意的空串回退
typescript/no-unsafe-type-assertion 会报大多数向下转型,包括 (error as NodeJS.ErrnoException).code 这类惯用法,逼出自写类型守卫或 disable 指令
typescript/no-unnecessary-condition 很多发现守护的是类型没有建模的运行时状态(取消信号、外部 JSON),删掉这些检查会出 bug
typescript/require-await 它要防的漏写 await 已被 no-floating-promises、no-misused-promises 和 tsc 覆盖;去掉 async 会把 reject 变成同步抛错
typescript/no-invalid-void-type 这里的回调契约返回 X | void,和 ACP、fastify 的类型一致
typescript/no-dynamic-delete 发现都是从字典型对象里删 key;替代写法会改变序列化和 in 的结果
typescript/no-confusing-void-expression 发现都是 () => voidCall() 这类简写;加花括号可能丢掉 void 类型调用实际返回的 Promise
promise/always-return 团队原有决定
unicorn/prefer-add-event-listener 团队原有决定
代码文件的改动(160 个文件;除了 ToolBubble 的修复,都不改变运行时行为)

核对方式:把每个文件在 main 上和本分支上的版本,用仓库相同的编译选项(verbatimModuleSyntax、experimentalDecorators、ES2024)转译成 JS 后比对。159 个机械改动的文件里,117 个完全相同,11 个只差 let/const,31 个只差 import 语句;这 31 个文件运行时加载的模块和加载顺序也都和 main 一致。删掉的注释全是 lint 指令,没有影响打包或覆盖率的注释。

提交 改动 为什么不改变行为
remove type arguments that repeat their defaults 91 处 类型参数在编译后被擦除
drop redundant undefined from optional parameters 31 处,全部是函数参数,包括 node-sdk 和 oauth 的方法 参数上的 ? 本来就允许 undefined,而且不受 exactOptionalPropertyTypes 影响
use const for bindings that are never reassigned 11 处 这些变量从不重新赋值;另外 41 处「先声明、后赋值」的写法没有改,冻结进了棘轮
merge duplicate imports of the same module 59 处 运行时加载的模块和加载顺序不变(见上)
upgrade oxlint to 1.94 without changing what lint reports 删掉 10 个只被 re-export 的多余 import;2 条 no-thenable 指令改用新的规则名 被删的 import 所在语句都还保留其他导入项,模块加载不变
remove lint suppression comments that suppress nothing 82 条无用的 disable 指令 只改注释;全部规则开启时未使用的指令为 0,冻结规则的违规数也没变
两次合并 main 时的冲突处理 第一次:5 个文件里,#5019 删掉的说明性注释和本分支删掉的无用 disable 指令都不保留;openai-responses/decode.ts 用本分支合并后的 import,不带文件头注释。第二次:promptEvents.ts 保留 main 新加的 PromptOrigin 导入和本分支收窄后的 disable 指令 只删注释和指令;合并后的 import 加载的还是同一个模块
remove imports a merged test no longer uses idle-notification-repro.test.ts 里 2 个没被使用的导入名 所在的 import 语句还在,模块加载不变
fix(vis): call useState before the early return in ToolBubble 1 处 有意的行为变化:见下面的行为变化表
提交列表(21 个)
  1. chore: stop the pre-commit hook from rewriting staged code
  2. chore: guard the lint setup and run the import-boundary check in pnpm lint
  3. chore: upgrade oxlint to 1.94 without changing what lint reports
  4. chore: list every oxlint rule explicitly and enforce them as errors
  5. chore: remove lint suppression comments that suppress nothing
  6. chore: freeze lint rules that already have findings at their current count
  7. chore: remove type arguments that repeat their defaults
  8. chore: drop redundant undefined from optional parameters
  9. chore: use const for bindings that are never reassigned
  10. chore: merge duplicate imports of the same module
  11. chore: keep no-unnecessary-type-assertion off
  12. docs: describe the lint ratchet and suppression rules for agents
  13. 合并 main,解决和 chore: reject comments in JS/TS code and remove existing ones #5019 的冲突(说明写在合并提交里)
  14. chore: fit the comment check into the lint guards
  15. build(nix): update the pnpm dependency hash for the oxlint upgrade
  16. fix(vis): call useState before the early return in ToolBubble
  17. chore: drop noisy lint rules, add rules-of-hooks, freeze deprecated APIs
  18. 再次合并 main(2.6.3 发版同步),解决 promptEvents.ts 的冲突
  19. chore: remove imports a merged test no longer uses
  20. chore: fail the ratchet on findings it cannot attribute to a rule
  21. chore: freeze type-safety rules for new code and add React correctness rules

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
pre-commit hook 先跑注释检查,再跑 oxlint --type-aware --quiet:warning 被隐藏,也不会让提交失败 先跑注释检查,再跑 oxlint --type-aware --deny-warnings;规则只有 error 一档,和 CI 一致 无:主配置里已经没有 warn 级规则 无需处理
pnpm lint 包含的检查 注释检查、oxlint --type-aware 注释检查、oxlint(--deny-warnings)、agent-core-v2 import 边界检查、守卫、棘轮 CI、开发者、agent 无,有意为之
warning 两千多条,从不让 lint 失败 没有 warn 级规则;一旦出现 warning 就失败 依赖 warning 提示的开发者 原来的 warn 规则要么已是 error(0 命中),要么冻结进棘轮,要么关闭并写明原因
规则集合 4 个类别整类开启(correctness 为 error,其余为 warn),另有 69 条显式关闭 170 条显式 error;React 应用目录另开 19 条 React 规则(含 rules-of-hooks);oxc 插件生效;测试文件另有 16 条 vitest 规则 所有写代码的人 规则不合适时在 PR 里提出,改 .oxlintrc.json 并更新快照
冻结规则 基本不检查(多数原来是 warn) 42 条规则按文件冻结(共 2,129 处,分布在 538 个文件),新增即失败;no-empty 允许空 catch 块;no-deprecated 挡住新增的废弃 API;no-unsafe-* 等类型安全规则只管有类型的源码;测试里的 no-unused-vars、no-unsafe-optional-chaining 从豁免改为冻结 所有写代码的人 修掉以后运行 node scripts/checks/ratchet.mjs --update;挪动已有代码或升级依赖带来新的废弃项时加 --allow-increase
pnpm lint:fix pnpm run lint --fix:先跑注释检查,再 oxlint --type-aware --fix oxlint --type-aware --fix,不再先跑注释检查(它本来也不修复注释) 运行 lint:fix 的开发者 pnpm lint 仍然会跑注释检查
vis 调试工具的 ToolBubble 组件 非 tool 消息先返回 null,再调用 useState,hook 顺序取决于消息角色 先调用 useState 再返回;tool 消息的初始状态不变 无 无需处理
scripts/check-service-naming.mjs 存在,但没有任何命令或 CI 运行它,扫描的 packages/services/src 也已不存在 删除 无 无
oxlint 版本 oxlint 1.59.0,oxlint-tsgolint 0.20.0 oxlint 1.94.0,oxlint-tsgolint 7.0.2007 本地 lint 结果 无
flake.nix 的 pnpm 依赖哈希 对应 main 的 lockfile 按 CI 算出的值更新为本 PR 的 lockfile Nix 构建 无需处理
产品运行时行为 — None:代码改动只涉及类型、let 改 const、合并重复 import、删除无用的 import 和注释,核对方式见上面的折叠块 — —
node-sdk 和 oauth 的公开方法签名 31 个可选参数写作 x?: T | undefined x?: T SDK 使用方 类型等价,无需处理
packages/node-sdk/src/index.ts(对外契约文件) 第 1 行有一条没被用到的 import type 删除这一行,导出不变 SDK 使用方 无需处理

受影响模块与验证

  • lint 基础设施:pnpm lint 通过(守卫:189 条规则、5 个 override、13 项接线;棘轮:42 条规则、2,129 处)。scripts/checks/*.test.mjs 共 26 个测试,加上 CI 一起运行的注释检查测试,本地 38 个全部通过。另外对守卫和棘轮做了反向验证,以下情况都会被拦住:把规则从 error 降为 off、新增忽略目录、从 lint 命令里删掉某项检查、给 lint-staged 加回 --fix、拿掉测试覆盖项里的 vitest 插件、新增违规、基线大于实际、两份配置的忽略列表不一致、有违规时直接 --update、诊断对不上任何冻结规则(去掉 react-hooks 的映射后,棘轮报出 7 处并失败)。
  • 运行时行为:上面折叠块里的逐文件转译比对。
  • 类型:两次合并 main 之后都跑了和 CI typecheck job 相同的检查,全部通过。
  • 单元测试:第一次合并 main 之后,CI 的全量测试(5 个分片)全部通过;删掉导入的那个测试文件,本地 6 个测试通过。本地全量运行时有 11 个失败,与本 PR 无关:6 个只在高负载运行时失败,单独运行能通过;另外 5 个在 main(2931c7efd)上同样失败。
那 5 个在 main 上也失败的测试

在不带本 PR 改动的 HEAD 上,以及在 main(2931c7efd)的临时 worktree 里,单独运行都能复现,失败位置完全一致:

  • packages/node-sdk/test/sdk-rpc-client-v2.test.ts › serves suggestFiles through the workspace handler fs service
  • packages/kap-server/test/hosts.test.ts › lets a managed host sign in and renew with its own Kimi login
  • packages/agent-core-v2/test/tool/tool.test.ts 里 3 个 ... subagents without a deadline ... 相关的测试(假定时器,30 秒超时)

它们在 CI 上都能通过,看起来和本机环境有关。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

没有 changeset:改动是开发工具、和原来等价的代码改动,以及 vis 调试工具里的一处修复(vis 不发布),用户感知不到。不需要更新用户文档:AGENTS.md 和 CONTRIBUTING 已同步修改。没有关联 issue:这是维护者发起的内部改动。

lint-staged ran `oxlint --fix --quiet` before the type-aware check.
`--quiet` only hides warnings: fixes from warn-level rules were still
applied and staged into the commit without any output. Some of those
fixes change behavior, e.g. unicorn/no-array-sort rewrites `xs.sort()`
to `xs.toSorted()`, so callers relying on the in-place sort break.

The type-aware step already runs every rule, so dropping the fix step
only removes the silent rewrite. Errors still block the commit.
… lint

pnpm lint now runs oxlint (errors only), the agent-core-v2 import
boundary check, and scripts/checks/guards.mjs. The guards fail when the
effective oxlint config drifts from the committed snapshot, when a
registered check stops being invoked where it is registered, or when
the pre-commit hook passes --fix again. CI runs the guards' tests in
the lint job.

The boundary check passed on main but nothing ran it, although
AGENTS.md says it enforces the remote executor layering.
check-service-naming.mjs is removed: no command or workflow ran it,
half of its scan roots no longer exist, and no AGENTS.md rule refers to
its naming convention.

AGENTS.md and CONTRIBUTING now say how to run lint, that lint:fix is
not a formatter, and that some of its fixes change behavior.
Upgrade oxlint 1.59.0 -> 1.94.0 and oxlint-tsgolint 0.20.0 -> 7.0.2007
(1.94 requires tsgolint >= 7.0.2007).

With the config unchanged, the upgrade enabled new rules through the
enabled categories, including vitest rules for test files that
--print-config does not show, and started applying import/extensions
options that 1.59 never reported: 1,176 errors and 34,910 warnings
(before: 0 and 2,801). This change keeps what lint reports unchanged:

- Turn off the 14 newly enabled rules that already report on existing
  code until the lint restructure decides each one. Newly enabled rules
  without findings stay on.
- Allow `.js` import specifiers in minidb, klient, migration-legacy and
  one acp-server test helper, which 1.59 did not report.
- Teach vitest/expect-expect the repository's assertion helpers
  (expect*, assert*, *.expect*) instead of turning it off.
- Remove ten imports that were only re-exported from their source
  module, and rename two unicorn/no-thenable directives that 1.94 no
  longer matched.

The guards now add the category rules of plugins enabled only in an
override and compare every top-level key of the printed config, so the
snapshot records changes like the hidden vitest rules.

The pnpm dependency hash in flake.nix still needs the value reported by
the Nix build.
All rule categories are now off and each enabled rule is listed in
.oxlintrc.json as an error: 165 rules, plus 16 vitest rules for test
files. The 1.94 upgrade moved rules between categories and enabled
vitest rules that --print-config does not show, so with categories on
an oxlint upgrade could change the rule set without this file changing.

The rules come from the upstream recommended configs (eslint,
typescript-eslint) or report bug patterns. All rules that were errors
stay errors, and the 62 newly enabled ones have no findings today.

The plugins list now includes oxc. Listing plugins replaces oxlint's
defaults and the list had left oxc out, so oxlint's own bug detectors
(const-comparisons, erasing-op and others) never ran.

The warn level is gone: lint and the pre-commit hook run with
--deny-warnings. Former warn rules are either errors now, off as
style, or will be frozen at their current findings by a follow-up
change. Rules kept off on purpose are listed with the reason.
Remove 82 disable directives that no rule uses, checked against the
full rule set: the enabled rules plus the rules a follow-up change
freezes at their current findings.

- 54 Event2 headers also named eslint-plugin-import/namespace, which no
  config enables. The no-unsafe-declaration-merging suppression and its
  reason stay.
- 27 standalone directives and one trailing directive suppressed rules
  that are off: style rules, rules the team keeps off, or rules whose
  checks no longer report the line.

Five directives that only suppress rules frozen by the follow-up stay,
including the documented switch-exhaustiveness exception in the TUI
notify controller. Only comments change.
…count

Thirty-two rules that report bugs or bug-prone patterns already have
findings in existing code, and fixing those changes behavior. Instead of
leaving them off, .oxlintrc.ratchet.json turns them on over the main
config and scripts/checks/ratchet.mjs holds each file to its current
count: 1,542 findings in 429 files.

Frozen rules include no-explicit-any (outside tests), switch
exhaustiveness, empty blocks, in-place array sort, || where ?? may be
meant, console calls in packages/*/src and apps/*/src, conditional
expects and skipped tests.

The check fails when a file gains findings (listing its locations), when
the baseline allows more than the code has, when a disable directive
suppresses nothing with all rules on, and when the ratchet config's
ignorePatterns drift from the main config, since extends does not carry
them over. --update only lowers the baseline; raising it needs
--allow-increase. pnpm lint runs the check and the registry keeps it
wired. The pre-commit hook and editors keep using the main config.
Remove 91 explicit type arguments that equal the type parameter's
default, in 16 files, and enforce typescript/no-unnecessary-type-arguments.
Type arguments are erased at compile time, so runtime behavior does not
change; type-checking passes for every project CI checks.
Remove `| undefined` from 31 optional parameters in 8 files, where the
`?` already allows undefined, and enforce
typescript/no-duplicate-type-constituents. All 31 sites are function or
method parameters, including methods of the node-sdk and oauth
packages; parameter types are unaffected by exactOptionalPropertyTypes,
so the published signatures stay equivalent.
Change 11 let declarations that are never reassigned to const, which
does not change behavior, and freeze eslint/prefer-const in the ratchet
for the other 41. Those declare a binding early and assign it later
(for example a TUI referenced by closures created before it exists);
making them const means moving the declaration, which can change when
the value is first read.
Merge 59 duplicate imports in 46 files into one statement per module and
enforce import/no-duplicates. Under verbatimModuleSyntax a declaration
that is not `import type` still loads its module, so every touched file
was checked: the set of modules loaded at runtime is unchanged for all
1,293 imports. Merged statements follow the existing layout: one line up
to 100 characters, otherwise one specifier per line.
Applying this rule's fixes removed 1,135 assertions and broke
type-checking with 97 errors in 41 files: assertions it reports as
unnecessary are needed by tsc in this codebase, mostly for
index-signature access and properties absent from the declared type.
Its findings are not reliable here, so the rule stays off with the
reason in .oxlintrc.json.
AGENTS.md now lists what pnpm lint runs, forbids editing the ratchet
config or raising its baseline to get a passing run, says how a needed
disable directive gives its reason, and explains that rules frozen in
the ratchet must not gain findings and that the baseline is lowered
after fixing them. CONTRIBUTING describes the ratchet in pnpm lint.
Resolve the conflicts with the comment check from #5019:

- package.json and ci.yml: keep the comment check in pnpm lint and
  lint-staged, and its tests in CI, next to the new lint steps.
  lint-staged runs the comment check and then
  oxlint --type-aware --deny-warnings.
- pnpm-lock.yaml: main's lockfile plus the oxlint upgrade.
- scripts/check-service-naming.mjs: stays deleted.
- Five source files: drop both the explanatory comments that main
  removed and the disable directives that this branch removed because
  they no longer suppress anything.
- openai-responses/decode.ts: keep the merged import, without the file
  header comment.
Register the comment check in pnpm lint and lint-staged, and its tests
in CI, in the wiring registry, so the guards report it if it is
unwired. List it in the pnpm lint descriptions in AGENTS.md and
CONTRIBUTING.

Empty catch blocks used to carry a comment such as `// ignore`, which
eslint/no-empty accepts. #5019 removed those comments and comments are
no longer allowed, so after the merge the rule reported 116 more
findings, all of them empty catch blocks, and new code had no way to
write one. Allow empty catch blocks instead of freezing them. The rule
has two findings left, both empty for-await loops in tests, and the
ratchet baseline drops from 1,583 findings in 442 files to 1,412 in
368.

Also reword a config comment that still called the lint restructure a
future step.
@changeset-bot

changeset-bot Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 2fce113

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T09:16:52.729208Z 2fce113 Manual request
🔒 Security Review ✅ Completed 2026-11-17T16:03:41.960246Z 3d72dd6 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@2fce113
npx https://pkg.pr.new/@moonshot-ai/kimi-code@2fce113

commit: 2fce113

@github-actions

Copy link
Copy Markdown
Contributor

❌ Nix build failed

Hash mismatch in pnpmDeps:

Hash
specified sha256-dyj4CTzTHkLJaWiGehV7dSNZBmAlzefSnpGwKA7cCQc=
got sha256-CSe6uqTDxjuljspokul3gdNOeHAv9tsQwnoj8WmxAVI=

Please update flake.nix with the got hash.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3d72dd690b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pnpm-lock.yaml Resolved
The oxlint and oxlint-tsgolint upgrade changed pnpm-lock.yaml, so the
fixed-output hash of pnpmDeps no longer matched and
`nix build .#kimi-code` failed. Use the hash that the CI build reported.
ToolBubble returned null for non-tool messages before it called
useState, so its hook order depended on the message role, which React
does not allow. Call useState first. Tool messages start with the same
state as before.
Remove five rules from the ratchet and record why in .oxlintrc.json:

- unicorn/require-post-message-target-origin: every call here is a
  Worker, MessagePort, or VS Code webview postMessage, which takes no
  target origin.
- eslint/no-promise-executor-return: every finding was a one-line
  executor such as `new Promise((resolve) => setTimeout(resolve, ms))`.
- eslint/no-unmodified-loop-condition: every finding was a compound
  condition whose other operand changes in the loop, or a flag that a
  callback sets while the loop awaits.
- eslint/no-loop-func: every finding was a callback that runs within
  the same iteration or shares state with the loop on purpose.
- typescript/prefer-nullish-coalescing: its fix turns || into ??, which
  changes the result for '' and 0, and many || here fall back on an
  empty string on purpose.

Add three rules that have no findings today: eslint/radix,
unicorn/no-abusive-eslint-disable, so every disable directive names the
rules it disables, and react/rules-of-hooks for the two React apps.

Freeze typescript/no-deprecated at its current count so new code does
not add more uses of deprecated APIs, most of them zod 3 ones. In tests,
freeze no-unused-vars and no-unsafe-optional-chaining instead of
exempting tests from them. The ratchet now freezes 31 rules at 1,629
findings in 422 files.

lint:fix only runs the main config, which no longer has the rules behind
the old `||` to `??` and `sort()` to `toSorted()` examples. Replace them
in AGENTS.md, CONTRIBUTING, and the wiring registry with one that
applies.
Resolve the conflict in packages/agent-core-v2/src/agent/prompt/promptEvents.ts:
keep main's PromptOrigin import and this branch's narrower disable
directive, which no longer lists eslint-plugin-import/namespace.
The 2.6.3 release sync removed the code in
idle-notification-repro.test.ts that used one of its imports, so the
ratchet reported a new unused import. Drop createMockProvider and the
TestAgentOptions type from the harness import, which still loads the
same module, and lower the baseline for that file and for the two
findings the release sync fixed.
oxlint reports the react hooks rules under the react-hooks prefix while
the config names them react/..., so the ratchet dropped those findings
without a word: a frozen react/exhaustive-deps would never have been
counted or enforced. Map that prefix, and fail with a clear message on
any finding that matches no rule in the ratchet config instead of
skipping it.
…s rules

Freeze these rules in the ratchet without changing existing code:
- all files: use-unknown-in-catch-callback-variable (108),
  import/no-named-as-default-member (27), oxc/no-accumulating-spread (8)
  and no-unnecessary-template-expression (5);
- typed source only (packages/*/src, apps/*/src, apps/vis/*/src and
  apps/vscode/webview-ui/src; tests, JS scripts and bench excluded):
  no-unsafe-argument, no-unsafe-call, no-unsafe-member-access,
  no-unsafe-assignment and no-unsafe-return (317 together) and
  no-unnecessary-type-parameters (32);
- the React apps: react/exhaustive-deps (7).

Add 18 React correctness rules that have no findings to the React
override.

Move six rules from "off for now" to "off on purpose", with the reason
found when sampling their findings: no-unsafe-type-assertion,
no-unnecessary-condition, require-await, no-invalid-void-type,
no-dynamic-delete and no-confusing-void-expression.

The ratchet now freezes 42 rules at 2,129 findings in 538 files.
@RealKai42

Copy link
Copy Markdown
Collaborator Author

@codex

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 2fce1131f1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@RealKai42
RealKai42 merged commit 4567ffc into main Nov 18, 2026
19 checks passed
@RealKai42
RealKai42 deleted the chore/pre-commit-no-autofix branch November 18, 2026 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants