Skip to main content

function-always-returns-null

added in: 1.4.0
⚙️
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;
}