use super::*;
use crate::domain::findings::{OrphanSuppression, SrpFinding, SrpFindingDetails};
use crate::domain::SuppressionTarget;
use crate::findings::{Dimension, Suppression};
pub(super) fn target_of(name: &str, pin: Option<f64>) -> SuppressionTarget {
match pin {
Some(pin) => SuppressionTarget::Metric {
name: name.to_string(),
pin,
},
None => SuppressionTarget::Boolean {
name: name.to_string(),
},
}
}
pub(super) fn orphans(
dim: Dimension,
target: &str,
pin: Option<f64>,
sup_line: usize,
seed: impl FnMut(&mut crate::report::AnalysisResult),
) -> Vec<OrphanSuppression> {
orphans_cfg(
target_of(target, pin),
dim,
sup_line,
&Config::default(),
seed,
)
}
pub(super) fn orphans_cfg(
target: SuppressionTarget,
dim: Dimension,
sup_line: usize,
config: &Config,
mut seed: impl FnMut(&mut crate::report::AnalysisResult),
) -> Vec<OrphanSuppression> {
let mut sups = HashMap::new();
sups.insert(
"src/x.rs".to_string(),
vec![Suppression {
line: sup_line,
dimensions: vec![dim],
reason: Some("r".to_string()),
target: Some(target),
}],
);
let mut analysis = empty_analysis();
seed(&mut analysis);
crate::app::orphan_suppressions::detect_orphan_suppressions(
&sups,
&std::collections::HashMap::new(),
&analysis,
config,
)
}
pub(super) fn srp_module(file: &str, production_lines: usize) -> SrpFinding {
let mut f = make_srp_module_finding(file);
if let SrpFindingDetails::ModuleLength {
production_lines: pl,
..
} = &mut f.details
{
*pl = production_lines;
}
f
}
pub(super) fn srp_module_full(
file: &str,
production_lines: usize,
length_score: f64,
clusters: usize,
) -> SrpFinding {
let mut f = make_srp_module_finding(file);
if let SrpFindingDetails::ModuleLength {
production_lines: pl,
independent_clusters: ic,
length_score: ls,
..
} = &mut f.details
{
*pl = production_lines;
*ic = clusters;
*ls = length_score;
}
f
}