avoid-unreachable-for-loop
Warns when the if statement's condition makes the inner for-loop unreachable.
Unreachable for-loops will never be executed and should be either removed, or the condition should be updated.
Example
❌ Bad:
void fn(List<int> arr) {
// LINT: This condition makes the inner for loop unreachable.
// Try updating the condition or removing the whole if statement.
if (arr.isEmpty) {
for (final item in arr) {
// ...
}
}
// LINT: This condition makes the inner for loop unreachable.
// Try updating the condition or removing the whole if statement.
if (arr.length == 0) {
arr.forEach((_) {
// ...
});
}
}
✅ Good:
void fn(List<int> arr) {
for (final item in arr) {
// ...
}
if (arr.isNotEmpty) {
arr.forEach((_) {
// ...
});
}
}