Help us improve
Share bugs, ideas, or general feedback.
From aura-frog
Analyzes code complexity using cyclomatic, cognitive, and maintainability metrics. Identifies functions/classes needing refactoring and generates a summary report.
npx claudepluginhub nguyenthienthanh/aura-frog --plugin aura-frogHow this command is triggered โ by the user, by Claude, or both
Slash command
/aura-frog:complexityquality/The summary Claude sees in its command listing โ used to decide when to auto-load this command
# Command: quality:complexity **Command:** `quality:complexity [target]` **Agent:** tester --- ## ๐ฏ Purpose Analyze code complexity using cyclomatic complexity, cognitive complexity, maintainability index, and identify functions/classes that need refactoring. --- ## ๐ Usage --- ## ๐ง Complexity Metrics ### 1. Cyclomatic Complexity Measures number of linearly independent paths through code. **Scale:** - 1-5: โ Simple (low risk) - 6-10: ๐ก Moderate (medium risk) - 11-20: ๐ Complex (high risk) - 21+: ๐ด Very complex (very high risk) ### 2. Cognitive Complexity Measures how ha...
/analyze-complexityCalculates cyclomatic and cognitive complexity across source files, ranks top complex functions and files, benchmarks against standards, and suggests refactoring strategies.
/assess-qualityFull quality assessment combining code-complexity-analysis, naming-conventions, and error-handling-patterns.
/code_analysisAnalyzes code in specified file or directory for complexity, code smells, security, performance issues, and best practices; generates report with health score, prioritized fixes, and todos.
/analyzeAnalyzes repository code health via complexity metrics, git churn, and test coverage. Generates report with overview, critical issues, warnings, recommendations.
/reviews-pragmaticRuns pragmatic code review on a specified path or directory to detect over-engineering, assess complexity vs project scale, evaluate developer experience, and recommend simplifications. Saves report to verification/pragmatic-review.md.
Share bugs, ideas, or general feedback.
Command: quality:complexity [target]
Agent: tester
Analyze code complexity using cyclomatic complexity, cognitive complexity, maintainability index, and identify functions/classes that need refactoring.
# Analyze entire project
quality:complexity
# Analyze specific file
quality:complexity src/services/auth.ts
# Show only high complexity (>10)
quality:complexity --threshold 10
# Export detailed report
quality:complexity --export complexity-report.json
Measures number of linearly independent paths through code.
Scale:
// Complexity: 1 (linear flow)
function greet(name: string) {
return `Hello, ${name}`;
}
// Complexity: 3 (if/else + return paths)
function getDiscount(amount: number) {
if (amount > 100) {
return 0.2;
} else if (amount > 50) {
return 0.1;
}
return 0;
}
// Complexity: 15 (many conditions)
function validateForm(form) {
if (!form.email) return false;
if (!form.password) return false;
if (form.password.length < 8) return false;
if (!form.email.includes('@')) return false;
// ... 10 more conditions
return true;
}
Measures how hard code is to understand (considers nesting).
// Cyclomatic: 4, Cognitive: 7 (nested conditions harder to understand)
function processOrder(order) {
if (order.items.length > 0) { // +1
for (let item of order.items) { // +2 (nested)
if (item.quantity > 10) { // +3 (double nested)
if (item.price > 100) { // +4 (triple nested)
applyBulkDiscount(item);
}
}
}
}
}
Combines complexity, lines of code, and Halstead volume.
Scale:
# ESLint complexity plugin
npx eslint --rule 'complexity: [error, 10]' src/
# ts-complexity
npx ts-complexity src/**/*.ts
# Radon (cyclomatic complexity)
radon cc src/ -a -s
# Cognitive complexity
flake8 --max-cognitive-complexity 10 src/
# Maintainability index
radon mi src/ -s
# PHPMD (complexity)
./vendor/bin/phpmd src/ text codesize
# PHPMetrics
phpmetrics --report-html=report/ src/
# Gocyclo
gocyclo -over 10 .
# Gocognit
gocognit -over 15 .
# Code Complexity Report
**Project:** my-project
**Date:** 2025-11-26
**Files Analyzed:** 145
---
## Summary
**Average Complexity:** 6.2 (โ
Target: <10)
**High Complexity Functions:** 8 (๐ Needs attention)
**Very High Complexity:** 2 (๐ด Critical)
| Metric | Value | Status |
|--------|-------|--------|
| Avg Cyclomatic Complexity | 6.2 | โ
Good |
| Avg Cognitive Complexity | 8.1 | ๐ก Fair |
| Avg Maintainability Index | 72 | ๐ก Fair |
| Functions >10 complexity | 8 | ๐ Warning |
| Functions >20 complexity | 2 | ๐ด Critical |
---
## ๐ด Critical Complexity (2 functions)
### 1. validateUserForm()
**File:** `src/utils/validation.ts:45`
**Cyclomatic Complexity:** 24
**Cognitive Complexity:** 31
**Lines:** 85
**Maintainability:** 42 (๐ด Low)
```typescript
function validateUserForm(form: UserForm): ValidationResult {
const errors: string[] = [];
if (!form.email) {
errors.push('Email required');
} else if (!form.email.includes('@')) {
errors.push('Invalid email');
} else if (form.email.length > 255) {
errors.push('Email too long');
}
if (!form.password) {
errors.push('Password required');
} else if (form.password.length < 8) {
errors.push('Password too short');
} else if (!/[A-Z]/.test(form.password)) {
errors.push('Password needs uppercase');
} else if (!/[0-9]/.test(form.password)) {
errors.push('Password needs number');
}
// ... 15 more similar conditions
return { valid: errors.length === 0, errors };
}
Refactoring Suggestion:
// Split into smaller validators (complexity: 2-3 each)
function validateEmail(email: string): string | null {
if (!email) return 'Email required';
if (!email.includes('@')) return 'Invalid email';
if (email.length > 255) return 'Email too long';
return null;
}
function validatePassword(password: string): string | null {
if (!password) return 'Password required';
if (password.length < 8) return 'Password too short';
if (!/[A-Z]/.test(password)) return 'Password needs uppercase';
if (!/[0-9]/.test(password)) return 'Password needs number';
return null;
}
function validateUserForm(form: UserForm): ValidationResult {
const errors = [
validateEmail(form.email),
validatePassword(form.password),
validateName(form.name),
// ...
].filter(Boolean);
return { valid: errors.length === 0, errors };
}
Impact: Complexity 24 โ 3 per function
File: src/services/payment.ts:120
Cyclomatic Complexity: 21
Cognitive Complexity: 28
Lines: 120
Maintainability: 48 (๐ด Low)
Refactoring Suggestion:
File: src/services/api.ts:200
Complexity: 15
Refactor: Extract error handling by status code
File: src/utils/reports.ts:80
Complexity: 14
Refactor: Split into smaller report generation functions
File: src/services/shipping.ts:45
Complexity: 13
Refactor: Use lookup table for shipping rules
Complexity Range | Functions | Percentage
-----------------+-----------+-----------
1-5 (Simple) | 112 | 77% โ
6-10 (Moderate) | 23 | 16% ๐ก
11-20 (Complex) | 8 | 5.5% ๐
21+ (Very High) | 2 | 1.5% ๐ด
| Directory | Avg Complexity | High Risk Files |
|---|---|---|
| src/services/ | 8.5 | 4 |
| src/utils/ | 7.2 | 3 |
| src/components/ | 4.1 | 1 |
| src/hooks/ | 3.8 | 0 |
Most Complex Area: src/services/ (needs refactoring)
Break large functions into smaller ones.
Use strategy pattern for complex if/else chains.
Group related parameters into objects.
Early returns to reduce nesting.
// โ Nested (cognitive complexity: 8)
function process(data) {
if (data) {
if (data.valid) {
if (data.items.length > 0) {
return processItems(data.items);
}
}
}
return null;
}
// โ
Guard clauses (cognitive complexity: 3)
function process(data) {
if (!data) return null;
if (!data.valid) return null;
if (data.items.length === 0) return null;
return processItems(data.items);
}
# .git/hooks/pre-commit
#!/bin/bash
# Check complexity before commit
npx ts-complexity --threshold 15 src/**/*.ts
if [ $? -ne 0 ]; then
echo "โ Commit blocked: Functions with complexity >15 detected"
echo "Please refactor before committing"
exit 1
fi
Command: quality:complexity