diff options
Diffstat (limited to 'bin/src/utils.rs')
-rw-r--r-- | bin/src/utils.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/bin/src/utils.rs b/bin/src/utils.rs new file mode 100644 index 0000000..747a761 --- /dev/null +++ b/bin/src/utils.rs | |||
@@ -0,0 +1,24 @@ | |||
1 | use std::collections::HashMap; | ||
2 | |||
3 | use lib::{Lint, LINTS}; | ||
4 | use rnix::SyntaxKind; | ||
5 | |||
6 | pub fn lint_map_of( | ||
7 | lints: &[&'static Box<dyn Lint>], | ||
8 | ) -> HashMap<SyntaxKind, Vec<&'static Box<dyn Lint>>> { | ||
9 | let mut map = HashMap::new(); | ||
10 | for lint in lints.iter() { | ||
11 | let lint = *lint; | ||
12 | let matches = lint.match_kind(); | ||
13 | for m in matches { | ||
14 | map.entry(m) | ||
15 | .and_modify(|v: &mut Vec<_>| v.push(lint)) | ||
16 | .or_insert_with(|| vec![lint]); | ||
17 | } | ||
18 | } | ||
19 | map | ||
20 | } | ||
21 | |||
22 | pub fn lint_map() -> HashMap<SyntaxKind, Vec<&'static Box<dyn Lint>>> { | ||
23 | lint_map_of(&*LINTS) | ||
24 | } | ||