This skill should be used when the user asks about "code complexity", "cyclomatic complexity", "cognitive complexity", "code metrics", "maintainability index", "code coverage", or when measuring code quality quantitatively. Provides metrics thresholds and measurement techniques.
Provides code complexity metrics (cyclomatic, cognitive, maintainability) and measurement techniques when users ask about quantitative code quality analysis.
/plugin marketplace add shabaraba/shabaraba-cc-plugins/plugin install dev-org@shabaraba-cc-pluginsThis skill inherits all available tools. When active, it can use any tool Claude has access to.
references/measurement-tools.mdCode quality metrics provide quantitative measures of code characteristics. This skill covers complexity metrics, maintainability indices, and their practical thresholds across different languages.
Measures the number of linearly independent paths through code.
Calculation: CC = E - N + 2P
Simplified: Count decision points + 1
if, elif, else, for, while, case, catch, &&, ||, ?: adds 1Thresholds:
| Range | Risk | Action |
|---|---|---|
| 1-10 | Low | Simple, well-structured |
| 11-20 | Moderate | More complex, consider refactoring |
| 21-50 | High | Complex, difficult to test |
| >50 | Very High | Untestable, must refactor |
Measures how difficult code is to understand (introduced by SonarQube).
Key differences from CC:
Calculation rules:
if, for, while, switch, catch, ?:)&&, ||)Thresholds:
| Range | Assessment |
|---|---|
| 0-7 | Easy to understand |
| 8-15 | Moderate complexity |
| 16-24 | High complexity, refactor |
| 25+ | Very high, immediate refactoring |
Example:
def process(items): # 0
for item in items: # +1 (loop)
if item.active: # +1 (if) +1 (nesting=1)
if item.valid: # +1 (if) +2 (nesting=2)
handle(item)
return items # Total: 6
Based on counting operators and operands:
| Metric | Formula | Meaning |
|---|---|---|
| Vocabulary | n = n1 + n2 | Unique operators + operands |
| Length | N = N1 + N2 | Total operators + operands |
| Volume | V = N × log2(n) | Size of implementation |
| Difficulty | D = (n1/2) × (N2/n2) | Error-proneness |
| Effort | E = D × V | Mental effort to understand |
Composite metric combining complexity, size, and comments.
Formula: MI = 171 - 5.2 × ln(V) - 0.23 × CC - 16.2 × ln(LOC)
Thresholds:
| Range | Maintainability |
|---|---|
| 85-100 | High maintainability |
| 65-84 | Moderate maintainability |
| 0-64 | Low maintainability |
| Metric | Description | Threshold |
|---|---|---|
| Physical LOC | All lines including blanks/comments | Method: <100, Class: <500 |
| Logical LOC | Executable statements | Method: <30, Class: <200 |
| Comment Ratio | Comments / Total | 10-30% typical |
Number of classes that depend on this class.
Number of classes this class depends on.
I = Ce / (Ca + Ce)
Measures how related methods are within a class.
LCOM1: Number of method pairs without shared instance variables
LCOM4: Number of connected components in method-field graph
1 = Multiple responsibilities
| Metric | Tool | Good | Warning | Critical |
|---|---|---|---|---|
| Cyclomatic | ESLint, SonarQube | ≤10 | 11-20 | >20 |
| Cognitive | SonarQube | ≤15 | 16-24 | >24 |
| Method LOC | - | ≤30 | 31-50 | >50 |
| Class LOC | - | ≤300 | 301-500 | >500 |
| Parameters | ESLint | ≤3 | 4-5 | >5 |
| Nesting Depth | ESLint | ≤3 | 4 | >4 |
| LCOM4 | - | 1 | 2 | >2 |
npx eslint --rule 'complexity: ["error", 10]' src/
sonar-scanner -Dsonar.projectKey=myproject
radon cc src/ -a -s # Cyclomatic complexity
radon mi src/ -s # Maintainability index
For detailed measurement techniques:
references/measurement-tools.md - Tool configurations and usagereferences/thresholds-by-language.md - Language-specific thresholdsCombine with:
solid-principles for structural analysisrefactoring-patterns for improvement strategiesUse when working with Payload CMS projects (payload.config.ts, collections, fields, hooks, access control, Payload API). Use when debugging validation errors, security issues, relationship queries, transactions, or hook behavior.
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems. Create original algorithmic art rather than copying existing artists' work to avoid copyright violations.