Skip to main content

tokmd_analysis_types/
complexity.rs

1//! Complexity, Halstead, maintainability, and technical-debt receipt DTOs.
2//!
3//! These contract types remain re-exported from the crate root to preserve
4//! existing `tokmd_analysis_types::...` names.
5
6use serde::{Deserialize, Serialize};
7
8mod file;
9mod halstead;
10mod histogram;
11mod maintainability;
12mod risk;
13mod technical_debt;
14
15pub use file::{FileComplexity, FunctionComplexityDetail};
16pub use halstead::HalsteadMetrics;
17pub use histogram::ComplexityHistogram;
18pub use maintainability::MaintainabilityIndex;
19pub use risk::ComplexityRisk;
20pub use technical_debt::{TechnicalDebtLevel, TechnicalDebtRatio};
21
22#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct ComplexityReport {
24    pub total_functions: usize,
25    pub avg_function_length: f64,
26    pub max_function_length: usize,
27    pub avg_cyclomatic: f64,
28    pub max_cyclomatic: usize,
29    /// Average cognitive complexity across files.
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub avg_cognitive: Option<f64>,
32    /// Maximum cognitive complexity found.
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub max_cognitive: Option<usize>,
35    /// Average nesting depth across files.
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub avg_nesting_depth: Option<f64>,
38    /// Maximum nesting depth found.
39    #[serde(skip_serializing_if = "Option::is_none")]
40    pub max_nesting_depth: Option<usize>,
41    pub high_risk_files: usize,
42    /// Histogram of cyclomatic complexity distribution.
43    #[serde(skip_serializing_if = "Option::is_none")]
44    pub histogram: Option<ComplexityHistogram>,
45    /// Halstead software science metrics (requires `halstead` feature).
46    #[serde(skip_serializing_if = "Option::is_none")]
47    pub halstead: Option<HalsteadMetrics>,
48    /// Composite maintainability index.
49    #[serde(skip_serializing_if = "Option::is_none")]
50    pub maintainability_index: Option<MaintainabilityIndex>,
51    /// Complexity-to-size debt heuristic.
52    #[serde(skip_serializing_if = "Option::is_none")]
53    pub technical_debt: Option<TechnicalDebtRatio>,
54    pub files: Vec<FileComplexity>,
55}