Skip to main content

cargo_coupling/balance/
rationale.rs

1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2pub enum GradeDimension {
3    /// Coupling strength is the dominant issue driver.
4    Strength,
5    /// Coupling distance is the dominant issue driver.
6    Distance,
7    /// Volatility or churn is the dominant issue driver.
8    Volatility,
9}
10
11impl std::fmt::Display for GradeDimension {
12    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
13        match self {
14            GradeDimension::Strength => write!(f, "strength"),
15            GradeDimension::Distance => write!(f, "distance"),
16            GradeDimension::Volatility => write!(f, "volatility"),
17        }
18    }
19}
20
21/// Top issue-type contribution used to explain a project grade.
22#[derive(Debug, Clone, PartialEq, Eq)]
23pub struct IssueTypeContribution {
24    /// Issue type contributing to the grade.
25    pub issue_type: IssueType,
26    /// Number of surfaced issues of this type.
27    pub count: usize,
28    /// Highest severity observed for this issue type.
29    pub highest_severity: Severity,
30}
31
32/// Short explanation of why a project received its health grade.
33#[derive(Debug, Clone, PartialEq, Eq)]
34pub struct GradeRationale {
35    /// Human-readable one-line explanation.
36    pub summary: String,
37    /// Highest-impact issue types by severity-weighted count.
38    pub top_issue_types: Vec<IssueTypeContribution>,
39    /// Dominant coupling dimension behind the surfaced issues.
40    pub dominant_dimension: Option<GradeDimension>,
41    /// Extra note when git churn or accidental volatility dominates.
42    pub volatility_note: Option<String>,
43}
44
45impl GradeRationale {
46    /// Empty rationale for hand-built test fixtures.
47    pub fn empty() -> Self {
48        Self {
49            summary: "No surfaced coupling issues; grade reflects low issue density.".to_string(),
50            top_issue_types: Vec::new(),
51            dominant_dimension: None,
52            volatility_note: None,
53        }
54    }
55}
56
57/// Specific refactoring actions
58use super::issue_type::IssueType;
59use super::severity::Severity;