Analyze code complexity and maintainability including cyclomatic complexity, function length, nesting depth, and cognitive load. Use when reviewing code maintainability, refactoring candidates, or technical debt assessment.
Analyzes code complexity using cyclomatic complexity, function length, and nesting depth metrics. Use when reviewing code maintainability, identifying refactoring candidates, or assessing technical debt.
/plugin marketplace add djankies/claude-configs/plugin install review@claude-configsThis skill is limited to using the following tools:
Provides automated complexity analysis commands and manual detection patterns for identifying hard-to-maintain code. Use this as a reference for WHAT to check and HOW to detect complexity issues—not for output formatting or workflow.
Run Lizard complexity analyzer:
bash ~/.claude/plugins/marketplaces/claude-configs/review/scripts/review-complexity.sh
Returns:
NLOC CCN Token Parameter Length LocationExample output:
45 18 234 5 50 src/utils.ts:calculateTotal
Counts independent paths through code based on decision points: if/else, switch, loops, ternary operators, logical operators (&&, ||)
Thresholds:
Non-comment lines in a function.
Thresholds:
Thresholds:
Levels of indentation.
Thresholds:
When automated tools unavailable or for deeper analysis, use Read/Grep to detect:
# Find functions with multiple comment sections
grep -A 50 "function\|const._=._=>" <file> | grep -c "^[[:space:]]\*\/\/"
Look for: Functions with validation + transformation + persistence + notification in one place
# Find lines with >3 levels of indentation (12+ spaces)
grep -n "^[[:space:]]{12,}" <file>
Look for: Nested if statements >3 levels deep
# Find files with many else-if statements
grep -c "else if" <file>
Look for: Functions with >5 else-if branches
# Find function declarations
grep -n "function._([^)]_,[^)]_,[^)]_,[^)]_,[^)]_," <file>
Look for: Functions with >5 parameters
Use Read to identify functions that mix:
Magic Numbers:
grep -n "[^a-zA-Z_][0-9]{2,}[^a-zA-Z_]" <file>
Look for: Unexplained numeric literals
Excessive Comments:
# Count comment density
total_lines=$(wc -l < <file>)
comment_lines=$(grep -c "^[[:space:]]\*\/\/" <file>)
Look for: Comment ratio >20% (indicates unclear code)
Side Effects:
grep -n "this\.\|global\.\|window\.\|process\.env" <file>
Look for: Functions accessing external state
When reviewing flagged functions, identify specific causes:
| Pattern | Detection Method | Example |
|---|---|---|
| Multiple Responsibilities | Function does >1 distinct task | Validation + transformation + persistence |
| Deep Nesting | Indentation >3 levels | if > if > if > if |
| Long Conditional Chains | >5 else-if branches | type === 'A' || type === 'B' || ... |
| Mixed Abstraction Levels | High + low level code mixed | orchestration + string manipulation |
| Magic Numbers | Unexplained literals | if (status === 42) |
| Excessive Comments | Comment ratio >20% | Every line needs explanation |
| Side Effects | Modifies external state | Accesses globals, mutates inputs |
| High Parameter Count | >5 parameters | function(a, b, c, d, e, f) |
Suggest these patterns based on complexity source:
When: Function >50 lines or multiple responsibilities Pattern:
// Before: 40 lines doing validation + transformation + persistence
function process(data) {
/_ 40 lines _/;
}
// After: 3 focused functions
function process(data) {
validate(data);
const transformed = transform(data);
persist(transformed);
}
When: Deep nesting >3 levels Pattern:
// Before: Nested ifs
if (valid) {
if (ready) {
if (allowed) {
/_ logic _/;
}
}
}
// After: Early returns
if (!valid) return;
if (!ready) return;
if (!allowed) return;
/_ logic _/;
When: >5 else-if branches Pattern:
// Before: Long if-else chain
if (type === 'A') {
doA();
} else if (type === 'B') {
doB();
}
// After: Lookup table
const strategies = { A: doA, B: doB };
strategies[type]();
When: >5 parameters Pattern:
// Before: Many parameters
function create(name, email, age, address, phone, city) {}
// After: Object parameter
function create(userData: UserData) {}
When: Complex conditionals or magic numbers Pattern:
// Before: Unclear condition
if (user.age > 18 && user.status === 'active' && user.balance > 100) {
}
// After: Named boolean
const isEligibleUser = user.age > 18 && user.status === 'active' && user.balance > 100;
if (isEligibleUser) {
}
Use these criteria when classifying findings:
| Metric | Severity | Rationale |
|---|---|---|
| CCN >= 25 | critical | Extremely high risk, untestable |
| CCN 20-24 | high | High risk, difficult to maintain |
| CCN 15-19 | high | Complex, refactor recommended |
| NLOC > 100 | high | Too long, hard to understand |
| Nesting depth > 4 | high | Hard to follow logic |
| CCN 11-14 | medium | Moderate complexity |
| NLOC 51-100 | medium | Consider splitting |
| Parameters > 5 | medium | Hard to use correctly |
| Nesting depth 4 | medium | Approaching complexity limit |
| CCN 6-10 | nitpick | Acceptable but monitor |
| NLOC 21-50 | nitpick | Acceptable length |
| Parameters 4-5 | nitpick | Consider object parameter |
Watch for these warning signs when reviewing complex functions:
Master defensive Bash programming techniques for production-grade scripts. Use when writing robust shell scripts, CI/CD pipelines, or system utilities requiring fault tolerance and safety.