Skip to content
← Back to rules

oxc/only-used-in-recursion 正确性

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

规则作用

检查仅在递归中使用且无副作用的参数。

灵感来源于 Clippy 中的 only_used_in_recursion 规则

为什么不好?

提供仅用于递归调用的参数可能是错误的。

它会增加认知复杂度并可能影响性能。

示例

此规则的错误代码示例:

ts
function test(onlyUsedInRecursion) {
  return test(onlyUsedInRecursion);
}

此规则的正确代码示例:

ts
function f(a: number): number {
  if (a == 0) {
    return 1;
  } else {
    return f(a - 1);
  }
}

如何使用

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

json
{
  "rules": {
    "oxc/only-used-in-recursion": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "oxc/only-used-in-recursion": "error",
  },
});
bash
oxlint --deny oxc/only-used-in-recursion

版本

此规则添加于 v0.1.1。

参考