avoid-inverted-boolean-checks
- Group
- Suspicious
- Path
lint/suspicious/avoid-inverted-boolean-checks- Default
- Off, opt in
- Origin
- Falcon
- Rule
- 78 of 512
Prefer direct equality comparisons and De Morgan forms in control-flow conditions.
Unlike avoid-inverted-boolean-expressions, this does not diagnose !!value.
Relational operators are excluded because NaN and custom operators lack reliable inverses.
Invalid
void f(int x, int y, bool a, bool b) {
if (!(x == y)) {}
if (!(x != y)) {}
if (!(a && b)) {}
while (!(a || b)) {}
}void f(int x, int y, bool a, bool b) { if (!(x == y)) {} if (!(x == y)) {} if (!(x != y)) {} if (!(x != y)) {} if (!(a && b)) {} if (!(a && b)) {} while (!(a || b)) {}Valid
void f(int x, int y, bool a, bool b) {
if (x != y) {}
if (x == y) {}
if (!a) {}
final c = !!a;
final d = !a || !b;
final e = !(x + y).isEven;
final inverted = !(a || b);
final comparison = !(x == y);
final callback = () => !(x > y);
}
void relational(double x, int y, GreaterOnly custom) {
if (!(x > 0)) {}
if (!(x >= 0)) {}
if (!(x < 0)) {}
if (!(x <= 0)) {}
final d = !((x <= y)) ? 1 : 2;
if (!(custom > 0)) {}
}
class GreaterOnly {
bool operator >(int other) => true;
}Configure avoid-inverted-boolean-checks
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"suspicious": {
"avoid-inverted-boolean-checks": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/suspicious/avoid-inverted-boolean-checks: <reason>More suspicious rules
- avoid-multi-assignment
Split chained assignments into separate statements.
- avoid-mutating-parameters
Detects writes through named function, method and constructor parameter objects.
- avoid-negated-conditions
Prefer positive conditions when both branches can be swapped.
- avoid-nested-assignments
Require assignments to be standalone statements, arrow bodies or loop operations.
- avoid-non-final-exception-class-fields
Exception and Error payloads should not change after construction.
- avoid-passing-async-when-sync-expected
avoid-passing-async-when-sync-expectedrecommendedFlags an
asyncclosure passed to a proven synchronous callback parameter. - avoid-passing-bloc-to-blocbloc
Rejects direct Bloc and Cubit arguments to other blocs.
- avoid-passing-bloc-to-widgetbloc
Rejects direct Bloc and Cubit arguments to Flutter widget constructors.