use serde::{Deserialize, Serialize};
use crate::graph::locality::{ClassifierConfig, ValidatorConfig};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(default)]
pub struct LocalityConfig {
pub max_distance: usize,
pub l1_threshold: usize,
pub hub_threshold: f64,
pub min_hub_afferent: usize,
pub god_module_threshold: usize,
pub deadwood_threshold: usize,
pub mode: String,
#[serde(default)]
pub exempt_patterns: Vec<String>,
}
impl Default for LocalityConfig {
fn default() -> Self {
Self {
max_distance: 4,
l1_threshold: 2,
hub_threshold: 1.0,
min_hub_afferent: 5,
god_module_threshold: 20,
deadwood_threshold: 2,
mode: "warn".to_string(),
exempt_patterns: Vec::new(),
}
}
}
impl LocalityConfig {
#[must_use]
pub fn to_validator_config(&self) -> ValidatorConfig {
ValidatorConfig {
max_distance: self.max_distance,
l1_threshold: self.l1_threshold,
classifier: ClassifierConfig {
hub_threshold: self.hub_threshold,
min_hub_afferent: self.min_hub_afferent,
god_module_threshold: self.god_module_threshold,
deadwood_threshold: self.deadwood_threshold,
volatile_leaf_efferent: 5,
},
exempt_patterns: self.exempt_patterns.clone(),
}
}
#[must_use]
pub fn is_enabled(&self) -> bool {
self.mode != "off"
}
#[must_use]
pub fn is_error_mode(&self) -> bool {
self.mode == "error"
}
}