avoid_complex_conditions
This rule flags a condition combining more &&/|| operands than the configured budget.
Why use this rule
Section titled “Why use this rule”a && b && !c || d forces the reader to hold four facts and two precedence rules at once, and it is where an && that should have been || hides longest. Naming the parts turns the condition into something readable at a glance and debuggable one piece at a time.
The root of a chain carries the diagnostic, so a && b && c && d counts once rather than three times. Parentheses do not break a chain: (a && b) && c is still one condition.
A hand-written operator == is never reported. It is one && per field by construction, and splitting it would scatter an equality check that reads as a unit — this accounted for most of the hits when the rule was first run against a production codebase.
This rule is in the pedantic preset: an operand budget is a house style.
if (user.isActive && user.hasPaid && !user.isBanned && user.age > 18) { grantAccess();}final isEligible = user.isActive && user.hasPaid;final isPermitted = !user.isBanned && user.age > 18;
if (isEligible && isPermitted) { grantAccess();}Enabling this rule
Section titled “Enabling this rule”This rule is in the pedantic preset, so it is enabled by preset: pedantic or by name:
rules: avoid_complex_conditions: enabled: trueOptions
Section titled “Options”many_lints: rules: avoid_complex_conditions: max_operands: 4rules: avoid_complex_conditions: max_operands: 4| Option | Type | Default | Description |
|---|---|---|---|
max_operands |
int | 3 |
How many &&/` |
Turning this rule off
Section titled “Turning this rule off”To disable this rule:
rules: avoid_complex_conditions: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”avoid_deep_nesting— Keep control flow within a nesting budget.avoid_high_cyclomatic_complexity— Keep a function within a complexity budget.avoid_long_functions— Keep function bodies within a line budget.max_statements— Keep a function within a statement budget.