src/content/docs/linter/rules/no-parameters-only-used-in-recursion.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> :::caution This rule is part of the [nursery](/linter/#nursery) group. This means that it is experimental and the behavior can change at any time. ::: ## Summary - Rule available since: `v2.3.3` - Diagnostic Category: [`lint/nursery/noParametersOnlyUsedInRecursion`](/reference/diagnostics#diagnostic-category) - This rule has an [**unsafe**](/linter/#unsafe-fixes) fix. - The default severity of this rule is [**warning**](/reference/diagnostics#warning). - Sources: - Inspired from [`only_used_in_recursion`](https://rust-lang.github.io/rust-clippy/master/#only_used_in_recursion){
"linter": {
"rules": {
"nursery": {
"noParametersOnlyUsedInRecursion": "error"
}
}
}
}
Disallow function parameters that are only used in recursive calls.
A parameter that is only passed to recursive calls is effectively unused and can be removed or replaced with a constant, simplifying the function.
function factorial(n, acc) {
if (n === 0) return 1;
return factorial(n - 1, acc);
}
function countdown(n, step) {
if (n === 0) return 0;
return countdown(n - step, step);
}
class Counter {
count(n, acc) {
if (n === 0) return 0;
return this.count(n - 1, acc);
}
}
function fn(n, acc) {
if (n === 0) return 0;
return fn(n - 1, acc || 0);
}
class Counter {
count(n, acc) {
if (n === 0) return 0;
return this?.count(n - 1, acc);
}
}
function factorial(n, acc) {
if (n === 0) return acc;
return factorial(n - 1, acc * n);
}
function countdown(n, step) {
console.log(step);
if (n === 0) return 0;
return countdown(n - step, step);
}
function fn(n, threshold) {
if (n > threshold) return n;
return fn(n + 1, threshold);
}