avoid-negated-conditions
Warns when an if statement or conditional expression have a negated condition that can be inverted.
⚙️ Config
Set ignore-null-checks
(default is false
) to exclude null checks.
dart_code_metrics:
...
rules:
...
- avoid-negated-conditions:
ignore-null-checks: true
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;