complexity-analyzer

Measure and report code complexity metrics with actionable recommendations.

242 stars

Best use case

complexity-analyzer is best used when you need a repeatable AI agent workflow instead of a one-off prompt. It is especially useful for teams working in multi. Measure and report code complexity metrics with actionable recommendations.

Measure and report code complexity metrics with actionable recommendations.

Users should expect a more consistent workflow output, faster repeated execution, and less time spent rewriting prompts from scratch.

Practical example

Example input

Use the "complexity-analyzer" skill to help with this workflow task. Context: Measure and report code complexity metrics with actionable recommendations.

Example output

A structured workflow result with clearer steps, more consistent formatting, and an output that is easier to reuse in the next run.

When to use this skill

  • Use this skill when you want a reusable workflow rather than writing the same prompt again and again.

When not to use this skill

  • Do not use this when you only need a one-off answer and do not need a reusable workflow.
  • Do not use it if you cannot install or maintain the related files, repository context, or supporting tools.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/complexity-analyzer/SKILL.md --create-dirs "https://raw.githubusercontent.com/aiskillstore/marketplace/main/skills/curiouslearner/complexity-analyzer/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/complexity-analyzer/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How complexity-analyzer Compares

Feature / Agentcomplexity-analyzerStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Measure and report code complexity metrics with actionable recommendations.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Complexity Analyzer Skill

Measure and report code complexity metrics with actionable recommendations.

## Instructions

You are a code complexity analysis expert. When invoked:

1. **Calculate Metrics**: Measure various complexity indicators:
   - **Cyclomatic Complexity**: Number of independent paths through code
   - **Cognitive Complexity**: Mental effort required to understand code
   - **Lines of Code**: Physical lines, source lines, comment lines
   - **Halstead Metrics**: Program vocabulary and difficulty
   - **Maintainability Index**: Overall maintainability score (0-100)
   - **Nesting Depth**: Maximum nesting level

2. **Analyze Functions/Methods**: For each function, report:
   - Cyclomatic complexity score
   - Number of parameters
   - Lines of code
   - Nesting depth
   - Return points
   - Complexity rating (low/medium/high/very high)

3. **Analyze Files/Modules**: For each file:
   - Total complexity score
   - Number of functions
   - Average complexity per function
   - Most complex functions
   - Duplicate code detection

4. **Generate Report**: Provide:
   - Overall project complexity summary
   - Top 10 most complex functions
   - Complexity distribution graph (if possible)
   - Refactoring recommendations
   - Comparison with industry standards

## Complexity Thresholds

### Cyclomatic Complexity
- **1-10**: Simple, easy to test (✓ Good)
- **11-20**: Moderate complexity (⚠ Review)
- **21-50**: High complexity (⚠ Refactor recommended)
- **50+**: Very high complexity (❌ Refactor required)

### Function Length
- **1-20 lines**: Short and focused (✓ Good)
- **21-50 lines**: Acceptable
- **51-100 lines**: Long (⚠ Consider splitting)
- **100+ lines**: Too long (❌ Refactor required)

### Nesting Depth
- **1-2 levels**: Good
- **3-4 levels**: Acceptable
- **5+ levels**: Too deep (❌ Refactor)

### Parameters
- **0-3 parameters**: Good
- **4-5 parameters**: Acceptable
- **6+ parameters**: Too many (⚠ Consider parameter object)

## Usage Examples

```
@complexity-analyzer
@complexity-analyzer src/
@complexity-analyzer UserService.js
@complexity-analyzer --threshold 10
@complexity-analyzer --detailed
@complexity-analyzer --export-json
```

## Report Format

```markdown
# Code Complexity Report

## Summary
- Total Files: 42
- Total Functions: 156
- Average Complexity: 8.4
- Maintainability Index: 72/100

## High Complexity Functions (Complexity > 20)

### 1. processPayment() - src/payment/processor.js:45
- Cyclomatic Complexity: 28
- Lines of Code: 145
- Parameters: 6
- Nesting Depth: 5
- Issues:
  - Too many decision points (28 branches)
  - Function too long (145 lines)
  - Deep nesting (5 levels)
  - Too many parameters (6)

**Recommendation**: Break into smaller functions:
- extractValidation()
- calculateFees()
- processTransaction()
- handleErrors()

### 2. generateReport() - src/reports/generator.js:102
- Cyclomatic Complexity: 24
- Lines of Code: 98
- Parameters: 5
- Nesting Depth: 4

## Complexity Distribution
- Low (1-10): 98 functions (63%)
- Medium (11-20): 42 functions (27%)
- High (21-50): 14 functions (9%)
- Very High (50+): 2 functions (1%)

## Recommendations
1. Refactor 2 very high complexity functions
2. Review 14 high complexity functions
3. Reduce nesting in 8 functions
4. Extract parameter objects in 5 functions
```

## Analysis Tools Integration

- **JavaScript/TypeScript**: ESLint complexity rules, ts-complexity
- **Python**: radon, mccabe, pylint
- **Java**: Checkstyle, PMD, JaCoCo
- **Go**: gocyclo, gocognit
- **Ruby**: flog, reek

## Recommendations by Complexity Score

### Score 1-10 (Low)
- ✓ Good to go
- Easy to understand and maintain
- Low testing overhead

### Score 11-20 (Moderate)
- ⚠ Acceptable but monitor
- Add comprehensive tests
- Document complex logic

### Score 21-50 (High)
- ⚠ Refactoring recommended
- Break into smaller functions
- Reduce conditional logic
- Simplify control flow

### Score 50+ (Very High)
- ❌ Immediate refactoring required
- High bug risk
- Difficult to test
- Hard to maintain

## Best Practices

- **Single Responsibility**: Each function should do one thing
- **Early Returns**: Reduce nesting with guard clauses
- **Extract Methods**: Break complex functions into smaller ones
- **Limit Parameters**: Use objects for multiple related parameters
- **Avoid Deep Nesting**: Flatten conditional structures
- **Cyclomatic Complexity Target**: Keep below 10 for most functions
- **Regular Monitoring**: Track complexity trends over time

## What Increases Complexity

- Conditional statements (if, else, switch)
- Loops (for, while, do-while)
- Logical operators (&&, ||)
- Try-catch blocks
- Ternary operators
- Nested functions
- Multiple return points

## Notes

- Focus on hotspots (frequently changed complex code)
- Balance complexity with readability
- Some complexity is unavoidable (business logic)
- Track trends, not just absolute numbers
- Combine with test coverage metrics

Related Skills

health-trend-analyzer

242
from aiskillstore/marketplace

分析一段时间内健康数据的趋势和模式。关联药物、症状、生命体征、化验结果和其他健康指标的变化。识别令人担忧的趋势、改善情况,并提供数据驱动的洞察。当用户询问健康趋势、模式、随时间的变化或"我的健康状况有什么变化?"时使用。支持多维度分析(体重/BMI、症状、药物依从性、化验结果、情绪睡眠),相关性分析,变化检测,以及交互式HTML可视化报告(ECharts图表)。

when-optimizing-prompts-use-prompt-optimization-analyzer

242
from aiskillstore/marketplace

Active diagnostic tool for analyzing prompt quality, detecting anti-patterns, identifying token waste, and providing optimization recommendations

when-auditing-security-use-security-analyzer

242
from aiskillstore/marketplace

Comprehensive security auditing across static analysis, dynamic testing, dependency vulnerabilities, secrets detection, and OWASP compliance

when-analyzing-user-intent-use-intent-analyzer

242
from aiskillstore/marketplace

Advanced intent interpretation system using cognitive science principles and probabilistic intent mapping

when-analyzing-skill-gaps-use-skill-gap-analyzer

242
from aiskillstore/marketplace

Analyze skill library to identify coverage gaps, redundant overlaps, optimization opportunities, and provide recommendations for skill portfolio improvement

intent-analyzer

242
from aiskillstore/marketplace

Advanced intent interpretation system that analyzes user requests using cognitive science principles and extrapolates logical volition. Use when user requests are ambiguous, when deeper understanding would improve response quality, or when helping users clarify what they truly need. Applies probabilistic intent mapping, first principles decomposition, and Socratic clarification to transform vague requests into well-understood goals.

naming-analyzer

242
from aiskillstore/marketplace

Suggest better variable, function, and class names based on context and conventions.

log-analyzer

242
from aiskillstore/marketplace

Parse and analyze application logs to identify errors, patterns, and insights.

auth-analyzer

242
from aiskillstore/marketplace

Review and analyze authentication and authorization patterns for security vulnerabilities.

wp-test-analyzer

242
from aiskillstore/marketplace

Analyze WordPress theme PHP files to extract testable elements for E2E test generation.

test-coverage-analyzer

242
from aiskillstore/marketplace

Analyzes test coverage gaps and suggests test cases for untested code paths. Use when user requests test improvements, coverage analysis, or wants to increase test coverage.

security-analyzer

242
from aiskillstore/marketplace

Comprehensive security vulnerability analysis for codebases and infrastructure. Scans dependencies (npm, pip, gem, go, cargo), containers (Docker, Kubernetes), cloud IaC (Terraform, CloudFormation), and detects secrets exposure. Fetches live CVE data from OSV.dev, calculates risk scores, and generates phased remediation plans with TDD validation tests. Use when users mention security scan, vulnerability, CVE, exploit, security audit, penetration test, OWASP, hardening, dependency audit, container security, or want to improve security posture.