Skip to content

avoid_complex_conditions

v1.0.0WarningConfigurableCode Quality

This rule flags a condition combining more &&/|| operands than the configured budget.

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();
}

This rule is in the pedantic preset, so it is enabled by preset: pedantic or by name:

many_lints.yaml
rules:
avoid_complex_conditions:
enabled: true
analysis_options.yaml
many_lints:
rules:
avoid_complex_conditions:
max_operands: 4
Option Type Default Description
max_operands int 3 How many &&/`

To disable this rule:

many_lints.yaml
rules:
avoid_complex_conditions: false

To keep the rule on but skip certain paths, use per-rule exclude.