---
title: "cognitive-complexity"
description: "Limit nested control-flow complexity."
image: "https://strider.gempir.com/og.png"
---

> Documentation Index
> Fetch the complete documentation index at: https://strider.gempir.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 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.

## Bad

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

## Good

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

## Configuration

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

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

Source: https://strider.gempir.com/lints/cognitive-complexity/index.mdx
