Complexity analyzer reference¶
The complexity analyzer measures three dimensions of code complexity from source code: cyclomatic complexity, cognitive complexity, and nesting depth. It operates on the UAST representation of your source files.
For the conceptual model — what each metric means and how cyclomatic and cognitive complexity differ — see Understanding complexity metrics. To run it, see the Quick start.
Configuration options¶
The complexity analyzer uses the UAST directly and has no analyzer-specific configuration options. Language support is determined by the UAST parser.
| Option | Type | Default | Description |
|---|---|---|---|
| (none) | -- | -- | Uses UAST; no analyzer-specific config |
Example output¶
{
"function_complexity": [
{
"name": "processFile",
"source_file": "cmd/server/main.go",
"language": "go",
"directory": "cmd/server",
"cyclomatic_complexity": 8,
"cognitive_complexity": 12,
"nesting_depth": 3,
"lines_of_code": 45,
"complexity_density": 0.178,
"risk_level": "LOW"
},
{
"name": "validate",
"source_file": "cmd/server/main.go",
"language": "go",
"directory": "cmd/server",
"cyclomatic_complexity": 15,
"cognitive_complexity": 22,
"nesting_depth": 5,
"lines_of_code": 80,
"complexity_density": 0.188,
"risk_level": "MEDIUM"
}
],
"high_risk_functions": [
{
"name": "validate",
"source_file": "cmd/server/main.go",
"language": "go",
"directory": "cmd/server",
"cyclomatic_complexity": 15,
"cognitive_complexity": 22,
"risk_level": "MEDIUM",
"issues": ["High cyclomatic complexity", "Deep nesting"]
}
],
"distribution": {
"simple": 180,
"moderate": 25,
"complex": 7
},
"aggregate": {
"total_functions": 212,
"average_complexity": 3.2,
"max_complexity": 15,
"health_score": 78.5,
"message": "Fair complexity - some functions could be simplified"
}
}
Each function record includes source_file, language, and directory for file-level joins and DWH aggregation.
Terminal output (readable risk triage)¶
Top issue rows include all core complexity dimensions in one compact value:
CC=<cyclomatic> | Cog=<cognitive> | Nest=<nesting>
Example:
Issues are sorted numerically by cyclomatic complexity (then cognitive, then nesting) so the highest-risk functions consistently appear first.
Plot output (fast visual scanning)¶
The plot output emphasizes fast interpretation for code-review and planning:
- Scatter view includes explicit cyclomatic/cognitive warning guide lines.
- Bubble size maps to nesting depth to preserve one-glance hotspot detection.
- Bar and pie views keep the same threshold semantics as terminal output.
See also¶
- Understanding complexity metrics — the mental model, McCabe vs cognitive, and limitations.
- Quick start — run static analysis.