一键导入
find-complexity
// Find functions with high cyclomatic complexity, excessive length, or too many parameters. Use when the user asks to find complex code, complexity hotspots, refactoring candidates, or wants to improve code maintainability.
// Find functions with high cyclomatic complexity, excessive length, or too many parameters. Use when the user asks to find complex code, complexity hotspots, refactoring candidates, or wants to improve code maintainability.
Find unused functions, types, constants, imports, and unreachable code paths. Use when the user asks to find dead code, unused code, cleanup candidates, or wants to reduce codebase size.
Find code duplication in the codebase. Supports two modes - scoped to current branch changes or a full codebase sweep. Use when the user asks to find duplicated code, copy-paste, repeated patterns, or wants to deduplicate before a PR.
Reviews Go code for idiomatic patterns, error handling, concurrency safety, and common mistakes. Use when reviewing .go files, checking error handling, goroutine usage, or interface design.
Reviews Go test code for proper table-driven tests, assertions, and coverage patterns. Use when reviewing *_test.go files.
Investigate CI/Prow job failures on a GitHub pull request. Use when the user pastes a PR URL and asks about CI failures, red checks, test failures, or wants to understand why a job failed.
Performs a strict clean rebase of a feature branch onto main with minimal conflict resolution and full validation. Use when the user asks to rebase carefully, avoid extra branches, avoid exploratory edits, and run go test and go vet until green.
| name | find-complexity |
| description | Find functions with high cyclomatic complexity, excessive length, or too many parameters. Use when the user asks to find complex code, complexity hotspots, refactoring candidates, or wants to improve code maintainability. |
| disable-model-invocation | true |
Identify Go functions that are hard to review, test, and maintain.
controller/, api/, cmd/, cli/). Skip tests unless explicitly asked.Ask the user:
For branch mode:
git diff --name-only upstream/main -- 'controller/' 'api/' 'cmd/' 'cli/' | grep '\.go$' | grep -v '_test\.go$'
Install gocyclo and gocognit if not available:
go install github.com/fzipp/gocyclo/cmd/gocyclo@latest
go install github.com/uudashr/gocognit/cmd/gocognit@latest
gocyclo -over 10 <target>
This shows functions with cyclomatic complexity over 10.
Thresholds: 1-10 (simple), 11-20 (moderate), 21-50 (complex), 51+ (untestable).
Cognitive complexity weights nesting depth — a 5-deep if scores much higher than 5 sequential ifs.
gocognit -over 15 <target>
This shows functions with cognitive complexity over 15.
Find long functions (50+ lines of code, excluding comments and blank lines):
for file in $(find <target> -name '*.go' -not -name '*_test.go'); do
awk '/^func / {start=NR; func=$0}
/^}/ && start {
len=NR-start;
if(len>50) print FILENAME":"start": "func" ("len" lines)"
}' "$file"
done
Find functions with too many parameters (6+):
rg "^func.*\([^)]{60,}\)" <target> -A 0
Functions with 6+ parameters are candidates for parameter objects or config structs.
Find large files (500+ lines):
wc -l $(find <target> -name '*.go' -not -name '*_test.go') | sort -rn | head -20
Files over 500 lines are candidates for splitting into focused packages.
For each function found, classify:
| Category | Criteria | Action |
|---|---|---|
| Split | High complexity + long body | Break into smaller functions |
| Simplify | High complexity + short body | Reduce branching (early returns, switch statements) |
| Parameterize | Too many arguments (6+) | Group into config struct |
| Monitor | Complexity 11-15, not growing | Note it, revisit if it gets worse |
| Split file | File over 500 lines | Break into focused packages |
For each finding:
Summary: total hotspots, top 5 worst offenders, estimated refactoring effort.