use crate::domain::Dimension;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TargetKind {
Metric,
Boolean,
}
#[derive(Debug, Clone, PartialEq)]
pub enum SuppressionTarget {
Metric { name: String, pin: f64 },
Boolean { name: String },
}
impl SuppressionTarget {
pub fn name(&self) -> &str {
match self {
Self::Metric { name, .. } | Self::Boolean { name } => name,
}
}
pub fn pin(&self) -> Option<f64> {
match self {
Self::Metric { pin, .. } => Some(*pin),
Self::Boolean { .. } => None,
}
}
}
pub fn target_kind(dim: Dimension, name: &str) -> Option<TargetKind> {
use Dimension as D;
use TargetKind::{Boolean, Metric};
match dim {
D::Complexity => match name {
"max_cognitive" | "max_cyclomatic" | "max_nesting_depth" | "max_function_lines" => {
Some(Metric)
}
"magic_numbers" | "error_handling" | "unsafe" => Some(Boolean),
_ => None,
},
D::Srp => match name {
"file_length" | "max_independent_clusters" | "max_parameters" => Some(Metric),
"god_struct" | "btc" | "slm" | "nms" => Some(Boolean),
_ => None,
},
D::Coupling => match name {
"max_fan_in" | "max_fan_out" | "max_instability" => Some(Metric),
"sdp" | "oi" | "sit" | "deh" | "iet" => Some(Boolean),
_ => None,
},
D::Dry => match name {
"duplicate" | "fragment" | "boilerplate" | "wildcard_imports" | "repeated_matches" => {
Some(Boolean)
}
_ => None,
},
D::Architecture => match name {
"call_parity" | "forbidden" | "layer" | "pattern" | "trait_contract" => Some(Boolean),
_ => None,
},
D::TestQuality => match name {
"no_assertion" | "no_sut" | "untested" | "uncovered" | "untested_logic" => {
Some(Boolean)
}
_ => None,
},
D::Iosp => None,
}
}
pub fn target_names(dim: Dimension) -> &'static [&'static str] {
use Dimension as D;
match dim {
D::Complexity => &[
"max_cognitive",
"max_cyclomatic",
"max_nesting_depth",
"max_function_lines",
"magic_numbers",
"error_handling",
"unsafe",
],
D::Srp => &[
"file_length",
"max_independent_clusters",
"max_parameters",
"god_struct",
"btc",
"slm",
"nms",
],
D::Coupling => &[
"max_fan_in",
"max_fan_out",
"max_instability",
"sdp",
"oi",
"sit",
"deh",
"iet",
],
D::Dry => &[
"duplicate",
"fragment",
"boilerplate",
"wildcard_imports",
"repeated_matches",
],
D::Architecture => &[
"call_parity",
"forbidden",
"layer",
"pattern",
"trait_contract",
],
D::TestQuality => &[
"no_assertion",
"no_sut",
"untested",
"uncovered",
"untested_logic",
],
D::Iosp => &[],
}
}