avoid-unnecessary-negations
preset: recommended
Warns when a negation can be simplified.
Example
❌ Bad:
void main() {
final someCondition = true;
if (!!someCondition) {} // LINT: Avoid unnecessary negations. Try rewriting the code without it.
if (!true) {} // LINT: Avoid unnecessary negations. Try rewriting the code without it.
// LINT: Avoid unnecessary negations on each side of this binary expression. Try removing them.
if (!flag == !another) {}
// LINT: Avoid unnecessary negations on each side of this binary expression. Try removing them.
if (!flag != !another) {}
}
✅ Good:
void main() {
final someCondition = true;
if (someCondition) {} // Correct, uses 'someCondition' directly
if (false) {} // Correct, uses 'false' instead
if (flag == another) {}
}