Skip to content
← Back to rules

oxc/only-used-in-recursion Correctness

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。

参考资料