Initial commit
This commit is contained in:
76
skills/codebase-auditor/scripts/analyzers/technical_debt.py
Normal file
76
skills/codebase-auditor/scripts/analyzers/technical_debt.py
Normal file
@@ -0,0 +1,76 @@
|
||||
"""
|
||||
Technical Debt Calculator
|
||||
|
||||
Calculates:
|
||||
- SQALE rating (A-E)
|
||||
- Remediation effort estimates
|
||||
- Debt categorization
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Dict, List
|
||||
|
||||
|
||||
def analyze(codebase_path: Path, metadata: Dict) -> List[Dict]:
|
||||
"""
|
||||
Calculate technical debt metrics.
|
||||
|
||||
Args:
|
||||
codebase_path: Path to codebase
|
||||
metadata: Project metadata
|
||||
|
||||
Returns:
|
||||
List of technical debt findings
|
||||
"""
|
||||
findings = []
|
||||
|
||||
# Placeholder implementation
|
||||
# In production, this would calculate SQALE rating based on all findings
|
||||
|
||||
return findings
|
||||
|
||||
|
||||
def calculate_sqale_rating(all_findings: List[Dict], total_loc: int) -> str:
|
||||
"""
|
||||
Calculate SQALE rating (A-E) based on findings.
|
||||
|
||||
Args:
|
||||
all_findings: All findings from all analyzers
|
||||
total_loc: Total lines of code
|
||||
|
||||
Returns:
|
||||
SQALE rating (A, B, C, D, or E)
|
||||
"""
|
||||
# Estimate remediation time in hours
|
||||
severity_hours = {
|
||||
'critical': 8,
|
||||
'high': 4,
|
||||
'medium': 2,
|
||||
'low': 0.5
|
||||
}
|
||||
|
||||
total_remediation_hours = sum(
|
||||
severity_hours.get(finding.get('severity', 'low'), 0.5)
|
||||
for finding in all_findings
|
||||
)
|
||||
|
||||
# Estimate development time (1 hour per 50 LOC is conservative)
|
||||
development_hours = total_loc / 50
|
||||
|
||||
# Calculate debt ratio
|
||||
if development_hours == 0:
|
||||
debt_ratio = 0
|
||||
else:
|
||||
debt_ratio = (total_remediation_hours / development_hours) * 100
|
||||
|
||||
# Assign SQALE rating
|
||||
if debt_ratio <= 5:
|
||||
return 'A'
|
||||
elif debt_ratio <= 10:
|
||||
return 'B'
|
||||
elif debt_ratio <= 20:
|
||||
return 'C'
|
||||
elif debt_ratio <= 50:
|
||||
return 'D'
|
||||
else:
|
||||
return 'E'
|
||||
Reference in New Issue
Block a user