Skip to main content

avoid-complex-conditions

effort: 4m
configurable
teams+

Warns when the complexity of a binary expression exceeds the configured threshold.

Overly complex conditions reduce readability and require additional effort to understand how different values affect the result. Consider simplifying such conditions by extracting methods or variables.

⚙️ Config

Set threshold (default is 10) to configure the complexity threshold.

analysis_options.yaml
dcm:
rules:
- avoid-complex-conditions:
threshold: 10

Example

❌ Bad:

void fn() {
final list = <String>[];

// LINT: The complexity of this condition (9) exceeds the configured threshold (3).
// Try simplifying this condition.
if ((list.contains('123') ?? false) && _condition() ||
(list
.where((item) => item.isNotEmpty)
.any((item) => item.contains('123')))) {}
}

bool _condition() => false;

✅ Good:

void fn() {
final list = <String>[];

final leftCondition = (list.contains('123') ?? false) && _condition();
final rightCondition = list.where((item) => item.isNotEmpty).any((item) => item.contains('123'));
if (leftCondition || rightCondition) {}
}

bool _condition() => false;