1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/// Toyota Way: Extract Method - Check if path is source file (complexity ≤8)
/// Determines if a path represents a source code file
#[must_use]
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
pub fn is_source_file(path: &Path) -> bool {
// Check if it has a source code extension
if !has_source_extension(path) {
return false;
}
// Exclude test and example files by path
if is_test_path(path) {
return false;
}
// Exclude test files by name pattern
if is_test_filename(path) {
return false;
}
true
}
/// Toyota Way: Extract Method - Check source extension (complexity ≤3)
fn has_source_extension(path: &Path) -> bool {
matches!(
path.extension().and_then(|s| s.to_str()),
Some(
"rs" | "js"
| "ts"
| "py"
| "java"
| "cpp"
| "c"
| "go"
| "kt"
| "swift"
| "php"
| "rb"
| "scala"
)
)
}
/// Toyota Way: Extract Method - Check if path contains test directory (complexity ≤5)
fn is_test_path(path: &Path) -> bool {
let path_str = path.to_string_lossy();
let test_patterns = [
"/tests/",
"/test/",
"/examples/",
"/benches/",
"/fixtures/",
"/testdata/",
"/test_data/",
"/debug_test/",
"/test-",
"/__tests__/",
];
test_patterns
.iter()
.any(|pattern| path_str.contains(pattern))
}
/// Toyota Way: Extract Method - Check if filename is test file (complexity ≤4)
fn is_test_filename(path: &Path) -> bool {
path.file_name()
.and_then(|name| name.to_str())
.is_some_and(|fname| {
fname.ends_with("_test.rs")
|| fname.ends_with("_tests.rs")
|| fname.starts_with("test_")
|| fname.contains("_test_")
|| fname.ends_with(".test.js")
|| fname.ends_with(".spec.js")
|| fname.ends_with("_test.py")
|| fname.ends_with("Test.java")
})
}