Skip to main content

avoid-recursive-calls

added in: 1.9.0
Pro+

Warns when a function calls itself recursively.

Dart does not support tail call optimization, so when working with a recursion there is always a chance to hit a StackOverflow error. Consider rewriting recursion to a stack instead.

Example

❌ Bad:

String some() {
return some(); // LINT: Avoid calling the same function recursively. Try rewriting the code without recursion.
}

✅ Good:

String some() {
return another();
}