Skip to content
← Back to rules

oxc/erasing-op Correctness

This rule is turned on by default.
⚠️ 🛠️ A dangerous auto-fix is available for this rule.

作用

检查擦除型运算,例如 x * 0

基于 https://rust-lang.github.io/rust-clippy/master/#/erasing_op

为什么这不好?

整个表达式可以被替换为零。这很可能不是预期的结果,应该进行修正。

示例

以下是此规则的错误代码示例:

javascript
let x = 1;
let y = x * 0;

以下是此规则的正确代码示例:

javascript
let x = 1;
let y = 0;

如何使用

To enable this rule using the config file or in the CLI, you can use:

json
{
  "rules": {
    "oxc/erasing-op": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "oxc/erasing-op": "error",
  },
});
bash
oxlint --deny oxc/erasing-op

版本

此规则是在 v0.1.1 中添加的。

参考