diff options
author | Akshay <[email protected]> | 2021-11-20 13:26:26 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2021-11-28 07:55:23 +0000 |
commit | 2b6012a79cb092e5d88c050cb494057efef28fc2 (patch) | |
tree | cd31973c32431a5cbf8c12ce574f799d065852be /bin/src/utils.rs | |
parent | 4e063b2abc402ac4d6902647e821978269025c7d (diff) |
introduce --config flag
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 | } | ||