-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a tidy check that checks whether the fluent slugs only appear once
- Loading branch information
Showing
8 changed files
with
56 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//! Checks that all Fluent messages appear at least twice | ||
|
||
use crate::walk::{filter_dirs, walk}; | ||
use regex::Regex; | ||
use std::collections::HashMap; | ||
use std::path::Path; | ||
|
||
lazy_static::lazy_static! { | ||
static ref WORD: Regex = Regex::new(r"\w+").unwrap(); | ||
} | ||
|
||
fn filter_used_messages( | ||
contents: &str, | ||
msgs: &mut HashMap<String, String>, | ||
unused_msgs: &mut HashMap<String, String>, | ||
) { | ||
let mut matches = WORD.find_iter(contents); | ||
while let Some(name) = matches.next() { | ||
if let Some((name, filename)) = msgs.remove_entry(name.as_str()) { | ||
unused_msgs.insert(name, filename); | ||
} else { | ||
unused_msgs.remove(name.as_str()); | ||
} | ||
} | ||
} | ||
|
||
pub fn check(path: &Path, msgs: &mut HashMap<String, String>, bad: &mut bool) { | ||
let mut unused_msgs = HashMap::new(); | ||
walk(path, |path, _| filter_dirs(path), &mut |_, contents| { | ||
filter_used_messages(contents, msgs, &mut unused_msgs); | ||
}); | ||
|
||
for (name, filename) in unused_msgs { | ||
tidy_error!(bad, "{filename}: message `{}` is not used", name,); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters