blob: d374b4b91b274fefad2ea0d005b2ed584058ab6b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
use std::collections::HashMap;
use lib::{Lint, LINTS};
use rnix::SyntaxKind;
pub fn lint_map_of(
lints: &[&'static Box<dyn Lint>],
) -> HashMap<SyntaxKind, Vec<&'static Box<dyn Lint>>> {
let mut map = HashMap::new();
for lint in lints.iter() {
let lint = *lint;
let matches = lint.match_kind();
for m in matches {
map.entry(m)
.and_modify(|v: &mut Vec<_>| v.push(lint))
.or_insert_with(|| vec![lint]);
}
}
map
}
pub fn lint_map() -> HashMap<SyntaxKind, Vec<&'static Box<dyn Lint>>> {
lint_map_of(&*LINTS)
}
pub fn get_version_info() -> Option<String> {
use std::process::Command;
let program = Command::new("nix")
.arg("--version")
.output()
.expect("failed to execute");
std::str::from_utf8(&program.stdout)
.ok()
.map(ToOwned::to_owned)
}
|