aboutsummaryrefslogtreecommitdiff
path: root/bin/src/lint.rs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-12-29 05:23:38 +0000
committerAkshay <[email protected]>2022-01-08 10:33:10 +0000
commitd1ff222bcf94152cd657233cffd8c14a45788c26 (patch)
treefb8c94daefe0384a48b503fdd4bfaff905d78e2f /bin/src/lint.rs
parent94a2edf57340ac3f3a2276c88a221ba3125172af (diff)
allow for version based lints
Diffstat (limited to 'bin/src/lint.rs')
-rw-r--r--bin/src/lint.rs23
1 files changed, 16 insertions, 7 deletions
diff --git a/bin/src/lint.rs b/bin/src/lint.rs
index 3482d46..c385007 100644
--- a/bin/src/lint.rs
+++ b/bin/src/lint.rs
@@ -1,6 +1,6 @@
1use crate::{utils, LintMap}; 1use crate::{utils, LintMap};
2 2
3use lib::Report; 3use lib::{session::SessionInfo, Report};
4use rnix::WalkEvent; 4use rnix::WalkEvent;
5use vfs::{FileId, VfsEntry}; 5use vfs::{FileId, VfsEntry};
6 6
@@ -10,7 +10,7 @@ pub struct LintResult {
10 pub reports: Vec<Report>, 10 pub reports: Vec<Report>,
11} 11}
12 12
13pub fn lint_with(vfs_entry: VfsEntry, lints: &LintMap) -> LintResult { 13pub fn lint_with(vfs_entry: VfsEntry, lints: &LintMap, sess: &SessionInfo) -> LintResult {
14 let file_id = vfs_entry.file_id; 14 let file_id = vfs_entry.file_id;
15 let source = vfs_entry.contents; 15 let source = vfs_entry.contents;
16 let parsed = rnix::parse(source); 16 let parsed = rnix::parse(source);
@@ -23,7 +23,7 @@ pub fn lint_with(vfs_entry: VfsEntry, lints: &LintMap) -> LintResult {
23 WalkEvent::Enter(child) => lints.get(&child.kind()).map(|rules| { 23 WalkEvent::Enter(child) => lints.get(&child.kind()).map(|rules| {
24 rules 24 rules
25 .iter() 25 .iter()
26 .filter_map(|rule| rule.validate(&child)) 26 .filter_map(|rule| rule.validate(&child, sess))
27 .collect::<Vec<_>>() 27 .collect::<Vec<_>>()
28 }), 28 }),
29 _ => None, 29 _ => None,
@@ -35,21 +35,30 @@ pub fn lint_with(vfs_entry: VfsEntry, lints: &LintMap) -> LintResult {
35 LintResult { file_id, reports } 35 LintResult { file_id, reports }
36} 36}
37 37
38pub fn lint(vfs_entry: VfsEntry) -> LintResult { 38pub fn lint(vfs_entry: VfsEntry, sess: &SessionInfo) -> LintResult {
39 lint_with(vfs_entry, &utils::lint_map()) 39 lint_with(vfs_entry, &utils::lint_map(), &sess)
40} 40}
41 41
42pub mod main { 42pub mod main {
43 use std::io; 43 use std::io;
44 44
45 use super::lint_with; 45 use super::lint_with;
46 use crate::{config::Check as CheckConfig, err::StatixErr, traits::WriteDiagnostic}; 46 use crate::{config::Check as CheckConfig, err::StatixErr, traits::WriteDiagnostic, utils};
47
48 use lib::session::{SessionInfo, Version};
47 49
48 pub fn main(check_config: CheckConfig) -> Result<(), StatixErr> { 50 pub fn main(check_config: CheckConfig) -> Result<(), StatixErr> {
49 let vfs = check_config.vfs()?; 51 let vfs = check_config.vfs()?;
50 let mut stdout = io::stdout(); 52 let mut stdout = io::stdout();
51 let lints = check_config.lints()?; 53 let lints = check_config.lints()?;
52 let lint = |vfs_entry| lint_with(vfs_entry, &lints); 54
55 let version = utils::get_version_info()
56 .unwrap()
57 .parse::<Version>()
58 .unwrap();
59 let session = SessionInfo::from_version(version);
60
61 let lint = |vfs_entry| lint_with(vfs_entry, &lints, &session);
53 vfs.iter().map(lint).for_each(|r| { 62 vfs.iter().map(lint).for_each(|r| {
54 stdout.write(&r, &vfs, check_config.format).unwrap(); 63 stdout.write(&r, &vfs, check_config.format).unwrap();
55 }); 64 });