Skip to content

oxc/only-used-in-recursion Correctness

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

What it does

Checks for arguments that are only used in recursion with no side-effects.

Inspired by https://rust-lang.github.io/rust-clippy/master/#/only_used_in_recursion

Why is this bad?

Supplying an argument that is only used in recursive calls is likely a mistake.

It increase cognitive complexity and may impact performance.

Examples

Examples of incorrect code for this rule:

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

Examples of correct code for this rule:

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

References

Released under the MIT License.