use std::collections::HashMap;
use std::path::Path;
use crate::walk::{filter_dirs, walk};
fn filter_used_messages(
contents: &str,
msgs_not_appeared_yet: &mut HashMap<String, String>,
msgs_appeared_only_once: &mut HashMap<String, String>,
) {
let mut matches = static_regex!(r"\w+").find_iter(contents);
while let Some(name) = matches.next() {
if let Some((name, filename)) = msgs_not_appeared_yet.remove_entry(name.as_str()) {
msgs_appeared_only_once.insert(name, filename);
} else {
msgs_appeared_only_once.remove(name.as_str());
}
}
}
pub fn check(path: &Path, mut all_defined_msgs: HashMap<String, String>, bad: &mut bool) {
let mut msgs_appear_only_once = HashMap::new();
walk(path, |path, _| filter_dirs(path), &mut |_, contents| {
filter_used_messages(contents, &mut all_defined_msgs, &mut msgs_appear_only_once);
});
for (name, filename) in msgs_appear_only_once {
tidy_error!(bad, "{filename}: message `{}` is not used", name,);
}
}