Skip to content

代码检查工具

🌐 Linter

贡献新规则

🌐 Contributing New Rules

请参阅 添加规则 指南,了解如何向 Oxlint 添加新规则。

🌐 See the adding rules guide for how to add new rules to Oxlint.

发展

🌐 Development

创建一个 ./test.ts 然后

🌐 Create a ./test.ts and then

bash
just watch "cargo run --bin oxlint -- test.ts"

或者根据规则进行测试和筛选:

🌐 Or test and filter against the rule:

bash
just watch "cargo test -p oxc_linter -- rule-name"

在完整代码库上测试 oxlint

🌐 Testing oxlint against a full codebase

要在完整的代码库上测试 oxlint,例如在大型 JavaScript/TypeScript 项目中测试你的更改,你可以构建 oxlint CLI 并针对该代码库运行它。

🌐 To test oxlint on a full codebase, for example to test your changes with a large JavaScript/TypeScript project, you can build the oxlint CLI and run it against that codebase.

bash
# build the oxlint cli in the oxc repo
just oxlint-node
# and then in the directory of the codebase you want to test with, run oxlint with node:
node <path-to-oxc-repo>/apps/oxlint/dist/cli.js
# You can also pass flags to it, like -D to enable a specific rule, and --disable-x-plugin to turn off default plugins:
node <path-to-oxc-repo>/apps/oxlint/dist/cli.js -D rulename --disable-unicorn-plugin --disable-oxc-plugin --disable-typescript-plugin

快照测试

🌐 Snapshot Testing

cargo insta 用于快照测试。

在运行 cargo test -p oxc_linter 并调用 Tester::new(RULE::NAME, pass, fail).test_and_snapshot() 行之后,将生成一个新的 rule.snap.new 文件。

🌐 After running cargo test -p oxc_linter and the line Tester::new(RULE::NAME, pass, fail).test_and_snapshot() is called, a new rule.snap.new file will be generated.

使用 cargo insta accept 接受所有快照更改。

🌐 Use cargo insta accept to accept all snapshot changes.

规则类别

🌐 Rule Category

  • 正确性 - 明显错误或无用的代码
  • 可疑 - 最有可能错误或无用的代码
  • 吹毛求疵的 - 检查相当严格或偶尔会产生误报的代码分析工具
  • perf - 可以编写得更快运行的代码
  • 风格 - 代码应该以更地道的方式编写
  • 限制 - 在启用之前,应根据具体情况逐一考虑 lint。
  • 苗圃 - 仍在开发中的新棉纤维