avoid-local-functions
Warns when a function declaration is a local function.
Local functions complicate the readability of the containing function by inverting its flow (you see a lot of code at first that will be somehow used later) and can lead to unexpected inclusion of outer scope variables.
Example
❌ Bad:
bool someFunction(String externalValue) {
final value = 'some value';
// LINT: Avoid local functions. Try converting this function to a method or a top-level function instead.
bool isValid() {
// some
// additional
// logic
}
return isValid() && externalValue != value;
}
✅ Good:
bool someFunction(String externalValue) {
final value = 'some value';
return isValid() && externalValue != value;
}
// Correct, moved outside of 'someFunction'
bool isValid() {
// some
// additional
// logic
}