avoid-complex-conditions
- Group
- Complexity
- 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
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; }
}void f(bool a, bool b, bool c, bool d) { if (a && b && c && d) {} if (a && b && c && d) {} final x = a || b || c || d; final x = a || b || c || d; final y = (a && b) || (c && d); final y = (a && b) || (c && d); if (!(a || b || c || d)) {} if (!(a || b || c || d)) {} final z = a ? (b && c && d && a) : false; final z = a ? (b && c && d && a) : false; final callback = a && [1].any((x) => a && b && c && d); final callback = a && [1].any((x) => a && b && c && d); while (a && b && c && d) { break; }Valid
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.
{
"linter": {
"rules": {
"complexity": {
"avoid-complex-conditions": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/complexity/avoid-complex-conditions: <reason>More complexity rules
- avoid-complex-loop-conditions
Flags loop conditions with more logical operands than the configured threshold.
- avoid-function-literals-in-foreach-calls
avoid_function_literals_in_foreach_callsFlags a function literal passed to an Iterable's
forEach. - avoid-if-with-many-branches
Reports long if/else-if chains; replace them with a switch or extracted helpers.
- avoid-inverted-boolean-expressions
avoid_inverted_boolean_expressionsrecommendedFlags a doubly-negated boolean expression such as
!!x. - avoid-long-records
Reports record values and record types with too many fields.
- avoid-nested-conditional-expressions
avoid-nested-conditional-expressionsFlags a ternary conditional expression nested inside another ternary.
- avoid-nested-if
avoid_nested_ifFlags an
ifstatement whose then-branch contains nestedifstatements. - avoid-nested-switch-expressions
Reports deeply nested switch expressions.