oxc/only-used-in-recursion
Disallow parameters that are only passed on to the function's own recursive calls
A parameter that a function only hands to itself never affects the result. Either it's left over and every caller passes a value for nothing, or the code that was meant to use it is missing.
The rule checks function declarations, and function expressions and arrow functions assigned to a variable. Methods aren't checked. In JSX, it also checks a destructured prop that a component only passes to itself under the same name.
--fix-dangerously removes the parameter, and the matching argument from calls in the same file. For a prop, it removes the prop and the attribute on the recursive element. It doesn't touch exported functions, or a parameter that isn't the last one.
Configure#
Off by default. To turn it on:
[lint.rules]
"oxc/only-used-in-recursion" = "error" # or "warn"Examples#
function countNodes(node, depthParameter depth is only used in recursive calls) {
if (!node) return 0;
return 1 + countNodes(node.left, depth) + countNodes(node.right, depth);
}function Tree({ nodes, themeParameter theme is only used in recursive calls }) {
return nodes.map(node => <Tree key={node.id} nodes={node.children} theme={theme} />);
}function countNodes(node) {
if (!node) return 0;
return 1 + countNodes(node.left) + countNodes(node.right);
}A parameter that's read anywhere else counts as used. That includes an expression in the recursive call, such as depth + 1:
function countNodes(node, depth) {
if (!node || depth > 10) return 0;
return 1 + countNodes(node.left, depth + 1) + countNodes(node.right, depth + 1);
}function Tree({ nodes, theme }) {
return nodes.map(node => (
<div key={node.id} className={theme}>
<Tree nodes={node.children} theme={theme} />
</div>
));
}