Lints and suggestions for the Nix programming language
1use std::collections::HashMap;
2
3use lib::{LINTS, Lint};
4use rnix::SyntaxKind;
5
6#[allow(clippy::borrowed_box)]
7pub fn lint_map_of(
8 lints: &[&'static Box<dyn Lint>],
9) -> HashMap<SyntaxKind, Vec<&'static Box<dyn Lint>>> {
10 let mut map = HashMap::new();
11 for lint in lints {
12 let lint = *lint;
13 let matches = lint.match_kind();
14 for m in matches {
15 map.entry(m)
16 .and_modify(|v: &mut Vec<_>| v.push(lint))
17 .or_insert_with(|| vec![lint]);
18 }
19 }
20 map
21}
22
23#[allow(clippy::borrowed_box)]
24pub fn lint_map() -> HashMap<SyntaxKind, Vec<&'static Box<dyn Lint>>> {
25 lint_map_of(&LINTS)
26}