unicorn/no-useless-recursion
eslint-plugin-unicorn
No autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/no-useless-recursion": "error",
},
},
];Disallow simple recursive function calls that can be replaced with a loop.
function foo(bar) {
if (bar.baz) {
return foo(bar.baz);
}
return bar;
}function foo(bar) {
while (bar.baz) {
bar = bar.baz;
}
return bar;
}function foo(bar) {
if (Array.isArray(bar)) {
return bar.map(baz => foo(baz));
}
return bar;
}Examples from the ESLint documentation.
unicorn/no-useless-recursion
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/no-useless-recursion": "error",
},
},
];Oxlint does not have this rule.
nursery/noUselessRecursion
nursery · since 2.6.4
{
"linter": {
"rules": {
"nursery": {
"noUselessRecursion": "error"
}
}
}
}Disallow checking a Map key before accessing a different key.
Prefer early continues over conditionals wrapping the remainder of the loop body.
Do not use a for loop that can be replaced with a for-of loop.
Prefer Iterator.zip() over parallel-array indexing.
Enforce consistent labels on tuple type elements.
Enforce consistent class references in static methods.