Skip to main content

avoid-assignments-as-conditions

added in: 1.22.0
Pro+

Warns when an assignment is used inside a condition.

Example

❌ Bad:

void fn(List<String> values) {
bool? flag;

if (flag ??= values.isEmpty) {} // LINT
if (flag = values.isEmpty) {} // LINT
}

✅ Good:

void fn(List<String> values) {
bool? flag;

flag ??= values.isEmpty;
if (flag) {
...
}
}