function-always-returns-null
preset: recommended
Warns when a function with nullable return type returns only null
.
⚙️ Config
Set ignored-invocations
(default is none) to ignore function expressions within specific function invocations.
dart_code_metrics:
...
rules:
...
- function-always-returns-null:
ignored-invocations:
- useCallback
Example
❌ Bad:
// LINT
String? function() {
if (value == 2) {
// ...
}
return null;
}
✅ Good:
String? function() {
if (value == 2) {
// ...
return 'some string';
}
return null;
}