refactor: move scattered business logic into domain
- CodeGraph::merge_project_edges() replaces presentation-layer function - Language::is_test_file() centralises test file detection (was in walkdir) - AnalysisConfig::is_standard_excluded() centralises default dir exclusions (was in walkdir) - normalize_cargo_package() / normalize_python_package() in domain replace duplicated normalisers in each adapter - walkdir, cargo-workspace, python-project updated to call domain methods
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
use std::path::Path;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum Language {
|
||||
Rust,
|
||||
@@ -13,4 +15,26 @@ impl Language {
|
||||
Self::Python => "Python",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_test_file(&self, path: &Path) -> bool {
|
||||
let stem = path
|
||||
.file_stem()
|
||||
.and_then(|s| s.to_str())
|
||||
.unwrap_or_default();
|
||||
|
||||
let in_tests_dir = path
|
||||
.parent()
|
||||
.map(|p| p.components().any(|c| c.as_os_str() == "tests"))
|
||||
.unwrap_or(false);
|
||||
|
||||
if in_tests_dir {
|
||||
return true;
|
||||
}
|
||||
|
||||
match self {
|
||||
Self::Rust => stem.ends_with("_test") || stem.ends_with("_tests"),
|
||||
Self::Python => stem.starts_with("test_") || stem.ends_with("_test"),
|
||||
Self::CSharp => stem.ends_with("Tests") || stem.ends_with("Test"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,3 +7,11 @@ pub use file_path::FilePath;
|
||||
pub use language::Language;
|
||||
pub use module_name::ModuleName;
|
||||
pub use source_file::SourceFile;
|
||||
|
||||
pub fn normalize_cargo_package(name: &str) -> String {
|
||||
name.replace('_', "-")
|
||||
}
|
||||
|
||||
pub fn normalize_python_package(name: &str) -> String {
|
||||
name.to_lowercase().replace(['-', '.'], "_")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user