pub const SKIP_DIRS: &[&str] = &[
".git",
".svn",
".hg",
"target",
"node_modules",
"vendor",
"dist",
"build",
".venv",
"venv",
"__pycache__",
".tox",
".pytest_cache",
".mypy_cache",
".ruff_cache",
".next",
".nuxt",
".turbo",
".cache",
".gradle",
".zig-cache",
".dart_tool",
"coverage",
".idea",
".vscode",
".cargo",
"Pods",
];
pub const HIDDEN_DIR_WHITELIST: &[&str] = &[".github", ".whycodes", ".config"];
pub const HIDDEN_FILE_WHITELIST: &[&str] = &[
".gitignore",
".gitattributes",
".gitmodules",
".editorconfig",
".dockerignore",
".env.example",
".env.sample",
".rustfmt.toml",
".clippy.toml",
];
pub fn is_pruned_dir(name: &str) -> bool {
if name.is_empty() || name == "." || name == ".." {
return true;
}
if SKIP_DIRS.contains(&name) {
return true;
}
if name.starts_with('.') {
return !HIDDEN_DIR_WHITELIST.contains(&name);
}
false
}
pub fn is_pruned_file(name: &str) -> bool {
if name.starts_with('.') {
return !HIDDEN_FILE_WHITELIST.contains(&name);
}
false
}
pub fn rel_path_allowed(rel: &str) -> bool {
let mut components = rel.split('/').filter(|c| !c.is_empty()).peekable();
while let Some(comp) = components.next() {
let last = components.peek().is_none();
if last {
if is_pruned_dir(comp) && is_pruned_file(comp) {
return false;
}
} else if is_pruned_dir(comp) {
return false;
}
}
true
}
#[cfg(test)]
#[path = "policy_tests.rs"]
mod tests;