Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Technical Debt Grade (TDG)

The Technical Debt Grade is a composite quality score computed by PMAT static analysis. It provides a single letter grade (A through F) that summarizes the migration readiness of the source project.

Grading Scale

GradeScore RangeMeaning
A85-100Excellent – clean code, low complexity, high coverage
B70-84Good – minor issues, suitable for automated transpilation
C55-69Fair – moderate debt, some manual intervention needed
D40-54Poor – significant debt, plan for refactoring
F0-39Critical – major rewrite may be more efficient than migration

What TDG Measures

TDG is a weighted composite of four dimensions:

  1. Cyclomatic Complexity – number of independent paths through functions
  2. Cognitive Complexity – how difficult code is for humans to understand
  3. Test Coverage – percentage of lines exercised by tests
  4. Code Quality – linting violations, dead code, duplication

How TDG Is Computed

Batuta delegates TDG computation to the PMAT tool:

# PMAT runs complexity analysis and returns JSON
pmat analyze complexity /path/to/project --format json

The analyze_quality() function in src/tools.rs invokes PMAT and parses the result:

#![allow(unused)]
fn main() {
pub fn analyze_quality(path: &Path) -> Result<String> {
    let args = vec!["analyze", "complexity", &path_str, "--format", "json"];
    run_tool("pmat", &args, None)
}
}

The resulting score is stored as tdg_score: Option<f64> in ProjectAnalysis.

CLI Usage

$ batuta analyze --tdg ./my-python-app

Technical Debt Grade
--------------------
Overall: B (78.3)

  Complexity:  72/100  (12 functions above threshold)
  Coverage:    85/100  (85% line coverage)
  Quality:     81/100  (3 clippy-equivalent warnings)
  Duplication: 75/100  (2 code clones detected)

Migration Priority

TDG scores guide migration order. High-scoring modules are the best candidates for automated transpilation because they have well-defined behavior and test coverage to validate against.

TDGMigration Strategy
A-BFully automated transpilation via Depyler/Decy/Bashrs
CAutomated with manual review of flagged functions
DPartial automation, refactor complex functions first
FConsider rewrite rather than transpilation

Pre-commit Integration

Batuta’s pre-commit hook enforces complexity thresholds to prevent TDG regression:

# Pre-commit runs on staged .rs files
pmat analyze complexity --max-cyclomatic 30 --max-cognitive 25

Functions exceeding these thresholds block the commit until the complexity is reduced.


Navigate: Table of Contents