Linter
新增规则
请参阅 新增规则 指南。
开发流程
在项目根写好 ./test.ts 后执行:
bash
just watch "cargo run --bin oxlint -- test.ts"或按规则名过滤单元测试:
bash
just watch "cargo test -p oxc_linter -- rule-name"在全量代码库上测试 oxlint
要在完整项目上验证变更,可先编译 oxlint CLI:
bash
# 在 oxc 仓库构建 oxlint CLI
just oxlint-node
# 在目标工程目录中用 node 运行:
node <指向 oxc 仓库>/apps/oxlint/dist/cli.js
# 可加 -D 启用特定规则,--disable-*-plugin 关闭默认插件:
node <指向 oxc 仓库>/apps/oxlint/dist/cli.js -D rulename --disable-unicorn-plugin --disable-oxc-plugin --disable-typescript-plugin快照测试
使用 cargo insta 做快照测试。
运行 cargo test -p oxc_linter 且执行到 Tester::new(...).test_and_snapshot() 时,会生成 rule.snap.new。
使用 cargo insta accept 接受全部快照变更。
规则分类
- correctness — 代码明显错误或无效
- suspicious — 极有可能有问题或冗余
- pedantic — 较严格或偶发误判
- perf — 可改写以提升性能的写法
- style — 更地道的写法约定
- restriction — 启用前应按项目逐项评估
- nursery — 实验中的新规则