Skip to main content

fallow_cli/
health_types.rs

1//! Health / complexity analysis report types.
2//!
3//! Separated from the `health` command module so that report formatters
4//! (which are compiled as part of both the lib and bin targets) can
5//! reference these types without pulling in binary-only dependencies.
6
7/// Result of complexity analysis for reporting.
8#[derive(Debug, serde::Serialize)]
9pub struct HealthReport {
10    /// Functions exceeding thresholds.
11    pub findings: Vec<HealthFinding>,
12    /// Summary statistics.
13    pub summary: HealthSummary,
14}
15
16/// A single function that exceeds a complexity threshold.
17#[derive(Debug, serde::Serialize)]
18pub struct HealthFinding {
19    /// Absolute file path.
20    pub path: std::path::PathBuf,
21    /// Function name.
22    pub name: String,
23    /// 1-based line number.
24    pub line: u32,
25    /// 0-based column.
26    pub col: u32,
27    /// Cyclomatic complexity.
28    pub cyclomatic: u16,
29    /// Cognitive complexity.
30    pub cognitive: u16,
31    /// Number of lines in the function.
32    pub line_count: u32,
33    /// Which threshold was exceeded.
34    pub exceeded: ExceededThreshold,
35}
36
37/// Which complexity threshold was exceeded.
38#[derive(Debug, serde::Serialize)]
39#[serde(rename_all = "snake_case")]
40pub enum ExceededThreshold {
41    /// Only cyclomatic exceeded.
42    Cyclomatic,
43    /// Only cognitive exceeded.
44    Cognitive,
45    /// Both thresholds exceeded.
46    Both,
47}
48
49/// Summary statistics for the health report.
50#[derive(Debug, serde::Serialize)]
51pub struct HealthSummary {
52    /// Number of files analyzed.
53    pub files_analyzed: usize,
54    /// Total number of functions found.
55    pub functions_analyzed: usize,
56    /// Number of functions above threshold.
57    pub functions_above_threshold: usize,
58    /// Configured cyclomatic threshold.
59    pub max_cyclomatic_threshold: u16,
60    /// Configured cognitive threshold.
61    pub max_cognitive_threshold: u16,
62}