avoid-constant-conditions
Warns when both sides of a binary expression are constant.
Constant conditions always evaluate to true
or false
and usually indicate a typo or a bug.
Example
❌ Bad:
void fn() {
// LINT: This condition is constant and will always evaluate to 'false'.
// Try changing this condition.
if (_another == 11) {
print(value);
}
// LINT: This condition is constant and will always evaluate to 'true'.
// Try changing this condition.
if (Some._val == '1') {
print('hello');
} else {
print('hi');
}
}
abstract final class Some {
static const _val = '1';
}
const _another = 10;
✅ Good:
void fn(String value) {
if (value == '1') {
print('hello');
} else {
print('hi');
}
}