# no-useless-recursion πŸ“ Disallow simple recursive function calls that can be replaced with a loop. πŸ’ΌπŸš« This rule is enabled in the βœ… `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config). This rule is _disabled_ in the β˜‘οΈ `unopinionated` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config). Recursive functions can throw a stack overflow error when they run too deeply. Simple tail-recursive functions are usually clearer as loops in JavaScript. This rule intentionally only reports direct returned self-calls in named functions. More complex recursion can be useful and is left alone. ## Examples ```js // ❌ function foo(bar) { if (bar.baz) { return foo(bar.baz); } return bar; } ``` ```js // βœ… function foo(bar) { while (bar.baz) { bar = bar.baz; } return bar; } ``` ```js // βœ… function foo(bar) { if (Array.isArray(bar)) { return bar.map(baz => foo(baz)); } return bar; } ```