use crate::domain::{Dimension, SuppressionTarget};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum OrphanKind {
#[default]
Stale,
PinTooLoose,
}
impl OrphanKind {
pub fn status_word(self) -> &'static str {
match self {
OrphanKind::Stale => "stale",
OrphanKind::PinTooLoose => "too-loose",
}
}
pub fn json_kind(self) -> &'static str {
match self {
OrphanKind::Stale => "stale",
OrphanKind::PinTooLoose => "too_loose",
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct OrphanSuppression {
pub file: String,
pub line: usize,
pub dimensions: Vec<Dimension>,
pub target: Option<SuppressionTarget>,
pub reason: Option<String>,
pub kind: OrphanKind,
}
impl OrphanSuppression {
pub fn target_spec(&self) -> Option<String> {
self.target.as_ref().map(|t| match t.pin() {
Some(pin) => format!("{}={}", t.name(), fmt_pin(pin)),
None => t.name().to_string(),
})
}
pub fn target_suffix(&self) -> String {
self.target_spec()
.map(|s| format!(", {s}"))
.unwrap_or_default()
}
}
fn fmt_pin(v: f64) -> String {
if v.fract() == 0.0 {
format!("{v:.0}")
} else {
format!("{v}")
}
}