一键导入
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 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.
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.
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 make test and make lint until green.
Review PR with structured approach covering architecture, naming, patterns, and critical questions
After a code change, find affected tests, update them to match new behavior, then guide the user to run validation. Use when the user has made or asked for a code change and wants to make sure nothing is broken.
Run the full validation pipeline (make test, make lint, optionally make test-e2e) and auto-fix trivial failures like formatting and import issues. Use when the user asks to validate, run tests, check the pipeline, or verify changes are clean.
| 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.
internal/, api/, cmd/). Skip tests unless explicitly asked.Ask the user:
For branch mode:
git diff --name-only upstream/main -- 'internal/' 'api/' 'cmd/' | 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.