Skip to main content

tokmd_analysis_types/complexity/
maintainability.rs

1//! Maintainability index DTOs for complexity receipts.
2//!
3//! These serde-stable contract types remain re-exported from the crate root.
4
5use serde::{Deserialize, Serialize};
6
7/// Composite maintainability index based on the SEI formula.
8///
9/// MI = 171 - 5.2 * ln(V) - 0.23 * CC - 16.2 * ln(LOC)
10///
11/// When Halstead volume is unavailable, a simplified formula is used.
12#[derive(Debug, Clone, Serialize, Deserialize)]
13pub struct MaintainabilityIndex {
14    /// Maintainability index score (0-171 scale, higher is better).
15    pub score: f64,
16    /// Average cyclomatic complexity used in calculation.
17    pub avg_cyclomatic: f64,
18    /// Average lines of code per file used in calculation.
19    pub avg_loc: f64,
20    /// Average Halstead volume (if Halstead metrics were computed).
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub avg_halstead_volume: Option<f64>,
23    /// Letter grade: "A" (>=85), "B" (65-84), "C" (<65).
24    pub grade: String,
25}