aboutsummaryrefslogtreecommitdiff
path: root/bin/src/utils.rs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-11-20 13:27:28 +0000
committerAkshay <[email protected]>2021-11-20 13:27:28 +0000
commitf27372061a0effe3b00d400f4e577b9d9e0ad4c0 (patch)
treeedb9a9644a7ce6e8c28e937cdc5e4d62d45b4cb3 /bin/src/utils.rs
parenta5c3e679b06536bb43085b1a978854a73274af10 (diff)
add config option to fix and check
Diffstat (limited to 'bin/src/utils.rs')
-rw-r--r--bin/src/utils.rs24
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 @@
1use std::collections::HashMap;
2
3use lib::{Lint, LINTS};
4use rnix::SyntaxKind;
5
6pub 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
22pub fn lint_map() -> HashMap<SyntaxKind, Vec<&'static Box<dyn Lint>>> {
23 lint_map_of(&*LINTS)
24}