avoid-negated-conditions
added in: 1.7.0
style
Warns when an if statement or conditional expression have a negated condition that can be inverted.
Example
❌ Bad:
// LINT
if (!flag) {
...
} else {
...
}
// LINT
if (flag is! bool) {
...
} else {
...
}
final newValue = !flag ? value - 1 : value + 1; // LINT
✅ Good:
if (flag) {
...
} else {
...
}
if (flag is bool) {
...
} else {
...
}
final newValue = flag ? value + 1 : value - 1;