oxc/only-used-in-recursion

Disallow parameters that are only passed on to the function's own recursive calls

fixable

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:

bunfig.toml
[lint.rules]
"oxc/only-used-in-recursion" = "error" # or "warn"

Examples#

example.js1 problem
function countNodes(node, depth) {
  if (!node) return 0;
  return 1 + countNodes(node.left, depth) + countNodes(node.right, depth);
}
example.jsx1 problem
function Tree({ nodes, theme }) {
  return nodes.map(node => <Tree key={node.id} nodes={node.children} theme={theme} />);
}
example.jsNo problems
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:

example.jsNo problems
function countNodes(node, depth) {
  if (!node || depth > 10) return 0;
  return 1 + countNodes(node.left, depth + 1) + countNodes(node.right, depth + 1);
}
example.jsxNo problems
function Tree({ nodes, theme }) {
  return nodes.map(node => (
    <div key={node.id} className={theme}>
      <Tree nodes={node.children} theme={theme} />
    </div>
  ));
}