blob: 1adac4a5af0d80351d69bb0bd764bc7faadc2284 (
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
36
37
38
39
40
41
|
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()?
.split(' ')
.nth(2)
.map(ToOwned::to_owned)
}
pub fn default_nix_version() -> String {
String::from("2.4")
}
|