avoid-complex-conditions

Path
lint/complexity/avoid-complex-conditions
Default
Off, opt in
Origin
Falcon
Rule
35 of 512

Flags boolean expressions with more logical operands than the configured threshold.

Each operand joined by && or || counts as one; parentheses and unary operators do not hide logical operands. Calls and comparisons are opaque operands, so callback bodies do not inflate their caller's complexity. Only the outermost connected logical expression is reported. Logical expressions inside calls and callbacks are checked independently.

Options

threshold (integer, default: 10) — maximum number of logical operands.

Invalid

example.dartdart
void f(bool a, bool b, bool c, bool d) {
  if (a && b && c && d) {}
  final x = a || b || c || d;
  final y = (a && b) || (c && d);
  if (!(a || b || c || d)) {}
  final z = a ? (b && c && d && a) : false;
  final callback = a && [1].any((x) => a && b && c && d);
  while (a && b && c && d) { break; }
}
Condition has 4 logical operands (max 3). Extract a named condition.
1void f(bool a, bool b, bool c, bool d) {
2 if (a && b && c && d) {}
Condition has 4 logical operands (max 3). Extract a named condition.
2 if (a && b && c && d) {}
3 final x = a || b || c || d;
Condition has 4 logical operands (max 3). Extract a named condition.
3 final x = a || b || c || d;
4 final y = (a && b) || (c && d);
Condition has 4 logical operands (max 3). Extract a named condition.
4 final y = (a && b) || (c && d);
5 if (!(a || b || c || d)) {}
Condition has 4 logical operands (max 3). Extract a named condition.
5 if (!(a || b || c || d)) {}
6 final z = a ? (b && c && d && a) : false;
Condition has 4 logical operands (max 3). Extract a named condition.
6 final z = a ? (b && c && d && a) : false;
7 final callback = a && [1].any((x) => a && b && c && d);
Condition has 4 logical operands (max 3). Extract a named condition.
7 final callback = a && [1].any((x) => a && b && c && d);
8 while (a && b && c && d) { break; }

Valid

example.dartdart
void f(bool a, bool b, bool c) {
  if (a) {}
  if (a && b) {}
  if (a || b || c) {}
  final x = (a && b) || c;
  final y = !(a && b);
  while (a && b && c) { break; }
  final z = a && b && [1].any((x) => a || c);
  final fallback = (a ?? b) && c;
  final bits = (1 & 2) == (3 | 4);
}

Configure avoid-complex-conditions

Set its severity in falcon.json. See the configuration guide.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "complexity": {
        "avoid-complex-conditions": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/complexity/avoid-complex-conditions: <reason>