Technical Debt
File Metric | Derived
An estimate of remediation effort, derived from the Maintainability Index and Halstead Volume. Unlike effort-based models, this score is dimensionless — use it for relative comparison across files.
Formula
debt_f(MI, HV) = max(0, 1 − MI/100) × √(HV + 1)
total_debt = Σ debt_f over all functions in the file
debt_per_100_sloc = total_debt / sloc × 100
A function with a perfect MI score (100) contributes zero debt. As MI drops toward 0 and HV grows, debt rises sharply.
Interpretation
| debt_per_100_sloc | Interpretation |
|---|---|
| 0 – 5 | Excellent — high maintainability, simple code |
| 5 – 20 | Acceptable — some complexity, watch trending files |
| 20 – 50 | Concerning — schedule refactoring soon |
| > 50 | Critical — difficult to maintain, high bug risk |
TypeScript Example
// Simple arrow function
const double = (x: number) => x * 2;
// MI ≈ 95, HV ≈ 12 → debt_f ≈ (1-0.95) × √13 ≈ 0.18
// Complex function with nested conditions
function parseConfig(raw: string): Config {
// 80 LOC, CC=12, HV=520
}
// MI ≈ 42, HV ≈ 520 → debt_f ≈ (1-0.42) × √521 ≈ 13.2
Notes
- SLOC (source lines of code) excludes blank lines and comment-only lines.
- The
per_100_slocnormalisation allows fair comparison between files of different sizes. - Functions with HV = 0 still contribute debt when MI < 100:
debt_f = (1 − MI/100) × √(0+1) = 1 − MI/100. Only a perfect MI of 100 reduces the contribution to zero.
Related metrics
Maintainability Index · Halstead Volume · Cyclomatic Complexity