Skip to content
← Back to rules

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

This rule is turned on by default.
An 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);
  }
}

如何使用

要通过配置文件或 CLI 启用 此规则,可以使用:

json
{
  "rules": {
    "oxc/only-used-in-recursion": "error"
  }
}
bash
oxlint --deny oxc/only-used-in-recursion

参考资料