avoid-constant-assert-conditions
Warns when an assert
statement has a constant condition.
Constant conditions in assert
statements always evaluate to true
or false
and usually indicate a typo or a bug.
Example
❌ Bad:
void fn() {
const value = 1;
// LINT: This condition is constant and will always evaluate to true or false.
// Try changing this condition or removing the assert.
assert(value > 1);
// LINT: This condition is constant and will always evaluate to true or false.
// Try changing this condition or removing the assert.
assert(true);
}
class SomeClass {
static const first = 1;
// LINT: This condition is constant and will always evaluate to true or false.
// Try changing this condition or removing the assert.
const SomeClass() : assert(first > 1);
}
✅ Good:
void fn(int value) {
assert(value > 1);
}
class SomeClass {
final int first;
const SomeClass(this.first) : assert(this.first > 1);
}