---
title: "cyclomatic-complexity"
description: "Limit branching complexity in declared functions."
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.

# cyclomatic-complexity

**Default severity:** `warning`

**Maximum:** `10`  

Reports a declared function when its calculated complexity is greater than
10. A low complexity score makes control flow easier to understand, test, and
change safely.

## How the score is calculated

Every function starts at `1`. Strider adds one for each:

- `if`, `for`, `range`, or type-switch statement;
- non-default `case` clause;
- non-default `select` communication clause; and
- `&&` or `||` binary expression.

The rule currently runs on function declarations. Branches in a function
literal nested inside a declaration contribute to the enclosing declaration's
score.

## Bad

```go
func route() string {
	if first() { return "first" }
	if second() { return "second" }
	if third() { return "third" }
	if fourth() { return "fourth" }
	if fifth() { return "fifth" }
	if sixth() { return "sixth" }
	if seventh() { return "seventh" }
	if eighth() { return "eighth" }
	if ninth() { return "ninth" }
	if tenth() { return "tenth" }
	return "fallback"
}
```

## Good

```go
func route(value any, state routeState) string {
	if text, ok := value.(string); ok {
		return routeText(text, state)
	}
	return routeOther(value, state)
}
```

Extract cohesive decisions into named helpers. Avoid splitting code solely to
satisfy the number; each helper should represent a meaningful unit.

## Configuration

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

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

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