fallow_cli/health_types/
mod.rs1mod coverage;
8mod scores;
9mod targets;
10mod trends;
11mod vital_signs;
12
13pub use coverage::*;
14pub use scores::*;
15pub use targets::*;
16pub use trends::*;
17pub use vital_signs::*;
18
19#[derive(Debug, serde::Serialize)]
21pub struct HealthReport {
22 pub findings: Vec<HealthFinding>,
24 pub summary: HealthSummary,
26 #[serde(skip_serializing_if = "Option::is_none")]
28 pub vital_signs: Option<VitalSigns>,
29 #[serde(skip_serializing_if = "Option::is_none")]
31 pub health_score: Option<HealthScore>,
32 #[serde(skip_serializing_if = "Vec::is_empty")]
34 pub file_scores: Vec<FileHealthScore>,
35 #[serde(skip_serializing_if = "Option::is_none")]
37 pub coverage_gaps: Option<CoverageGaps>,
38 #[serde(skip_serializing_if = "Vec::is_empty")]
40 pub hotspots: Vec<HotspotEntry>,
41 #[serde(skip_serializing_if = "Option::is_none")]
43 pub hotspot_summary: Option<HotspotSummary>,
44 #[serde(skip_serializing_if = "Vec::is_empty")]
46 pub targets: Vec<RefactoringTarget>,
47 #[serde(skip_serializing_if = "Option::is_none")]
49 pub target_thresholds: Option<TargetThresholds>,
50 #[serde(skip_serializing_if = "Option::is_none")]
52 pub health_trend: Option<HealthTrend>,
53}
54
55#[cfg(test)]
56mod tests {
57 use super::*;
58
59 #[test]
60 fn health_report_skips_empty_collections() {
61 let report = HealthReport {
62 findings: vec![],
63 summary: HealthSummary {
64 files_analyzed: 0,
65 functions_analyzed: 0,
66 functions_above_threshold: 0,
67 max_cyclomatic_threshold: 20,
68 max_cognitive_threshold: 15,
69 files_scored: None,
70 average_maintainability: None,
71 coverage_model: None,
72 },
73 vital_signs: None,
74 health_score: None,
75 file_scores: vec![],
76 coverage_gaps: None,
77 hotspots: vec![],
78 hotspot_summary: None,
79 targets: vec![],
80 target_thresholds: None,
81 health_trend: None,
82 };
83 let json = serde_json::to_string(&report).unwrap();
84 assert!(!json.contains("file_scores"));
86 assert!(!json.contains("hotspots"));
87 assert!(!json.contains("hotspot_summary"));
88 assert!(!json.contains("targets"));
89 assert!(!json.contains("vital_signs"));
90 assert!(!json.contains("health_score"));
91 }
92
93 #[test]
94 fn health_score_none_skipped_in_report() {
95 let report = HealthReport {
96 findings: vec![],
97 summary: HealthSummary {
98 files_analyzed: 0,
99 functions_analyzed: 0,
100 functions_above_threshold: 0,
101 max_cyclomatic_threshold: 20,
102 max_cognitive_threshold: 15,
103 files_scored: None,
104 average_maintainability: None,
105 coverage_model: None,
106 },
107 vital_signs: None,
108 health_score: None,
109 file_scores: vec![],
110 coverage_gaps: None,
111 hotspots: vec![],
112 hotspot_summary: None,
113 targets: vec![],
114 target_thresholds: None,
115 health_trend: None,
116 };
117 let json = serde_json::to_string(&report).unwrap();
118 assert!(!json.contains("health_score"));
119 }
120}