#[must_use]
pub fn apply_satd_filters(
items: Vec<crate::models::tdg::SatdItem>,
severity: Option<SatdSeverity>,
critical_only: bool,
) -> Vec<crate::models::tdg::SatdItem> {
items
.into_iter()
.filter(|item| {
if critical_only {
matches!(item.severity, crate::models::tdg::SatdSeverity::Critical)
} else if let Some(min_severity) = &severity {
let item_level = match item.severity {
crate::models::tdg::SatdSeverity::Low => 1,
crate::models::tdg::SatdSeverity::Medium => 2,
crate::models::tdg::SatdSeverity::High => 3,
crate::models::tdg::SatdSeverity::Critical => 4,
};
let min_level = match min_severity {
SatdSeverity::Low => 1,
SatdSeverity::Medium => 2,
SatdSeverity::High => 3,
SatdSeverity::Critical => 4,
};
item_level >= min_level
} else {
true
}
})
.collect()
}
#[derive(Debug, Clone)]
pub struct DeepContextConfigParams {
pub project_path: PathBuf,
pub output: Option<PathBuf>,
pub format: DeepContextOutputFormat,
pub full: bool,
pub include: Vec<String>,
pub exclude: Vec<String>,
pub period_days: u32,
pub dag_type: DeepContextDagType,
pub max_depth: Option<usize>,
pub include_patterns: Vec<String>,
pub exclude_patterns: Vec<String>,
pub cache_strategy: DeepContextCacheStrategy,
pub parallel: Option<usize>,
pub verbose: bool,
}
#[allow(clippy::too_many_arguments)]
pub fn build_deep_context_config(
_project_path: PathBuf,
_output: Option<PathBuf>,
_format: DeepContextOutputFormat,
_full: bool,
_include: Vec<String>,
_exclude: Vec<String>,
_period_days: u32,
_dag_type: DeepContextDagType,
_max_depth: Option<usize>,
_include_patterns: Vec<String>,
_exclude_patterns: Vec<String>,
_cache_strategy: DeepContextCacheStrategy,
_parallel: Option<usize>,
_verbose: bool,
) -> anyhow::Result<crate::models::deep_context_config::DeepContextConfig> {
Ok(crate::models::deep_context_config::DeepContextConfig {
entry_points: vec![],
dead_code_threshold: 0.15,
complexity_thresholds: Default::default(),
include_tests: false,
include_benches: false,
cross_language_detection: true,
})
}
#[must_use]
pub fn convert_dag_type(dag_type: DeepContextDagType) -> crate::models::dag::DagType {
match dag_type {
DeepContextDagType::CallGraph => crate::models::dag::DagType::CallGraph,
DeepContextDagType::ImportGraph => crate::models::dag::DagType::ImportGraph,
DeepContextDagType::Inheritance => crate::models::dag::DagType::Inheritance,
DeepContextDagType::FullDependency => crate::models::dag::DagType::FullDependency,
}
}
#[must_use]
pub fn convert_cache_strategy(strategy: DeepContextCacheStrategy) -> DeepContextCacheStrategy {
strategy
}
pub fn parse_analysis_filters(
include: Vec<String>,
exclude: Vec<String>,
) -> anyhow::Result<(Vec<AnalysisType>, Vec<AnalysisType>)> {
let include_analysis = include
.into_iter()
.map(|s| parse_analysis_type(&s))
.collect::<Result<Vec<_>, _>>()?;
let exclude_analysis = exclude
.into_iter()
.map(|s| parse_analysis_type(&s))
.collect::<Result<Vec<_>, _>>()?;
Ok((include_analysis, exclude_analysis))
}
pub fn parse_analysis_type(s: &str) -> anyhow::Result<AnalysisType> {
match s.to_lowercase().as_str() {
"complexity" => Ok(AnalysisType::Complexity),
"dead-code" | "deadcode" => Ok(AnalysisType::DeadCode),
"duplication" | "duplicates" => Ok(AnalysisType::Duplication),
"technical-debt" | "tdg" => Ok(AnalysisType::TechnicalDebt),
"big-o" | "bigo" => Ok(AnalysisType::BigO),
"all" => Ok(AnalysisType::All),
_ => anyhow::bail!("Unknown analysis type: {s}"),
}
}