Skip to content

cognitive-complexity

Default severity: warning

Reports a function when its cognitive-complexity score exceeds 7. Each control structure adds one plus its nesting depth, so deeply nested decisions cost more than an equivalent sequence of guard clauses.

func process(items []Item) {
if ready() {
for _, item := range items {
if valid(item) {
for retry(item) {
process(item)
}
}
}
}
}
func process(items []Item) {
if !ready() {
return
}
for _, item := range items {
processItem(item)
}
}

The maximum cognitive-complexity score is fixed at 7. Configure the rule’s severity and path exclusions in strider.toml:

[checks.rules.cognitive-complexity]
severity = "error"
excludes = ["generated/**"]