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
use crate::types;
use crate::CONFIG;
use crate::COPS;
use globwalk;
use std::collections::HashMap;
use std::collections::HashSet;
pub fn scan() -> types::TargetFilesMap {
let cops = COPS.lock().unwrap();
let mut target_files: types::TargetFilesMap = HashMap::new();
for cop in cops.iter() {
if CONFIG.is_enabled(cop) {
let mut patterns = CONFIG.get_array(cop, "Include");
for exclude in CONFIG.get_array(cop, "Exclude") {
let string = String::from("!") + &exclude;
patterns.push(string);
}
let walker = globwalk::GlobWalkerBuilder::from_patterns(".", &patterns)
.file_type(globwalk::FileType::FILE)
.build()
.unwrap()
.into_iter()
.filter_map(Result::ok);
for file in walker {
let entry = target_files
.entry(file.path().display().to_string())
.or_insert(HashSet::new());
entry.insert(cop);
}
}
}
target_files
}