Skip to main content

sniff/
roles_surface_config.rs

1use crate::roles::file_name;
2use crate::types::FileRecord;
3
4fn is_validation_helper_name(name: &str) -> bool {
5    name.starts_with("_ensure_") || name.starts_with("_parse_") || name.starts_with("load_")
6}
7
8pub fn is_config_validation_module(file: &FileRecord) -> bool {
9    let normalized = crate::roles::normalize_path(&file.file_path);
10    let name = file_name(&normalized);
11    let is_config_named = matches!(
12        name,
13        "config.py" | "config.rs" | "config.ts" | "config.js" | "config.go"
14    ) || name.ends_with("_config.py")
15        || name.ends_with("_config.rs")
16        || name.ends_with("_config.ts")
17        || name.ends_with("_config.js")
18        || name.ends_with("_config.go");
19    if !is_config_named || file.methods.is_empty() {
20        return false;
21    }
22
23    let validation_methods = file
24        .methods
25        .iter()
26        .filter(|method| is_validation_helper_name(&method.name))
27        .count();
28    if validation_methods == 0 {
29        return false;
30    }
31
32    validation_methods * 2 >= file.methods.len()
33}