avoid-complex-loop-conditions
- Group
- Complexity
- Path
lint/complexity/avoid-complex-loop-conditions- Default
- Off, opt in
- Origin
- Falcon
- Rule
- 36 of 512
Flags loop conditions with more logical operands than the configured threshold.
Checks while, do/while, and C-style for conditions. Each operand
joined by && or || counts as one; comparisons and calls are opaque.
For-in iterables and for-loop initializers and updates are not conditions.
Options
threshold (integer, default: 1) — maximum number of logical operands.
Invalid
void f(bool a, bool b, bool c) {
while (a && b && c) { break; }
while (a || b || c) { break; }
do {} while (a && (b || c));
for (; a && b && c;) { break; }
for (var i = 0; i < 4 && a && b; i++) {}
final values = [for (var i = 0; i < 4 && a && b; i++) i];
}void f(bool a, bool b, bool c) { while (a && b && c) { break; } while (a && b && c) { break; } while (a || b || c) { break; } while (a || b || c) { break; } do {} while (a && (b || c)); do {} while (a && (b || c)); for (; a && b && c;) { break; } for (; a && b && c;) { break; } for (var i = 0; i < 4 && a && b; i++) {} for (var i = 0; i < 4 && a && b; i++) {} final values = [for (var i = 0; i < 4 && a && b; i++) i];Valid
void f(bool a, bool b, List<bool> items) {
while (a) { break; }
while (a && b) { break; }
do {} while (a || b);
for (var i = 0; i < 2; i++) {}
for (final item in items) { if (item && a && b) {} }
for (;;) { break; }
}Configure avoid-complex-loop-conditions
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"complexity": {
"avoid-complex-loop-conditions": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/complexity/avoid-complex-loop-conditions: <reason>More complexity rules
- 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.
- avoid-nested-switches
Reports deeply nested switch statements.