Code metrics calculation methodology for static analysis
Scanned 2/12/2026
Install via CLI
openskills install majiayu000/claude-skill-registry---
name: code-metrics
description: Code metrics calculation methodology for static analysis
---
# Code Metrics Calculation
## Objective
Calculate comprehensive code metrics for quality assessment.
## Metrics Definitions
### Complexity Metrics
1. **Cyclomatic Complexity**
- Count: decisions + 1
- Decisions: if, else, for, while, case, catch, &&, ||, ?:
- Thresholds: 1-10 (good), 11-20 (moderate), 21+ (high risk)
2. **Cognitive Complexity**
- Base: control flow structures
- Nesting penalty: +1 per nesting level
- Thresholds: 1-15 (good), 16-30 (moderate), 31+ (refactor)
3. **Nesting Depth**
- Maximum depth of nested structures
- Thresholds: 1-3 (good), 4-5 (moderate), 6+ (refactor)
### Size Metrics
1. **Lines of Code (LOC)**
- Physical lines (including blanks)
- Logical lines (statements)
- Comment lines
2. **Function Length**
- Lines per function/method
- Thresholds: 1-30 (good), 31-50 (moderate), 51+ (long)
3. **File Length**
- Total lines per file
- Thresholds: 1-300 (good), 301-500 (moderate), 501+ (large)
### Coupling Metrics
1. **Afferent Coupling (Ca)**
- Number of modules depending on this module
- High Ca = widely used, risky to change
2. **Efferent Coupling (Ce)**
- Number of modules this module depends on
- High Ce = high dependency, harder to maintain
3. **Instability (I)**
- Formula: Ce / (Ca + Ce)
- Range: 0 (stable) to 1 (unstable)
### Duplication Metrics
1. **Duplicate Lines**
- Exact match blocks > 6 lines
- Percentage of codebase
2. **Similar Blocks**
- Token-based similarity > 85%
- Parameterized duplicates
## Calculation Process
1. Parse source files into AST
2. Visit all nodes and calculate metrics
3. Aggregate at function, class, file, module levels
4. Compare against thresholds
5. Generate scores (0-100)
## Scoring Formula
```
Quality Score = 100 - (
complexity_penalty * 0.3 +
size_penalty * 0.2 +
coupling_penalty * 0.2 +
duplication_penalty * 0.3
)
```
Where penalties are percentage of violations.
No comments yet. Be the first to comment!
Use this skill when developing or maintaining browser extension code in the `browser/` directory, including Chrome/Firefox/Edge compatibility, content scripts, background scripts, or i18n updates.
SEO optimization with keyword analysis, readability assessment, technical validation, content quality. Use for search rankings, blog posts, content audits, or encountering keyword density, readability scores, meta tags, schema markup errors.
Python backend development expertise for FastAPI, security patterns, database operations, Upstash integrations, and code quality. Use when: (1) Building REST APIs with FastAPI, (2) Implementing JWT/OAuth2 authentication, (3) Setting up SQLAlchemy/async databases, (4) Integrating Redis/Upstash caching, (5) Refactoring AI-generated Python code (deslopification), (6) Designing API patterns, or (7) Optimizing backend performance.
Drive the full internationalization journey for a project — detect the stack, recommend a library, set up the chosen library, wrap existing strings, and optionally connect a translation platform. Use when the user asks to add or configure i18n, internationalization, localization, multi-language support, or translations — including when they explicitly mention LinguiJS, Lingui, next-intl, "wrap strings", "find hardcoded text", "make my app translatable", or "set up translations". Triggers on g...
PTES-aligned adversarial security audit for backend, frontend, and mobile applications. Produces a CVSS-scored Hacker Report with verified PoCs and phased remediation.