# 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.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

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

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```js
function countNodes(node, depth) {
  if (!node) return 0;
  return 1 + countNodes(node.left, depth) + countNodes(node.right, depth);
}
```

{/* bad */}
```jsx
function Tree({ nodes, theme }) {
  return nodes.map(node => <Tree key={node.id} nodes={node.children} theme={theme} />);
}
```

Not reported:

{/* good */}
```js
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`:

{/* good */}
```js
function countNodes(node, depth) {
  if (!node || depth > 10) return 0;
  return 1 + countNodes(node.left, depth + 1) + countNodes(node.right, depth + 1);
}
```

{/* good */}
```jsx
function Tree({ nodes, theme }) {
  return nodes.map(node => (
    <div key={node.id} className={theme}>
      <Tree nodes={node.children} theme={theme} />
    </div>
  ));
}
```
