Skip to main content

avoid-always-null-variables

effort: 2m
pro+

Warns when a variable is always null in the current code branch.

Example

❌ Bad:

void fn(String? value, String another) {
if (value == null) {
// LINT: This variable is always null in the current code branch.
// Try replacing it with a different variable or a null literal.
print(value);
}

if (value == null) {
// LINT: This variable is always null in the current code branch.
// Try replacing it with a different variable or a null literal.
print(value ?? another);
}

if (value != null) {
...
} else {
// LINT: This variable is always null in the current code branch.
// Try replacing it with a different variable or a null literal.
print(value);
}
}

✅ Good:

void fn(String? value, String another) {
if (value == null) {
print(null);
}

if (value == null) {
print(another);
}

if (value != null) {
...
}
}