aboutsummaryrefslogtreecommitdiff
path: root/bin/src/lint.rs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-11-20 13:26:26 +0000
committerAkshay <[email protected]>2021-11-28 07:55:23 +0000
commit2b6012a79cb092e5d88c050cb494057efef28fc2 (patch)
treecd31973c32431a5cbf8c12ce574f799d065852be /bin/src/lint.rs
parent4e063b2abc402ac4d6902647e821978269025c7d (diff)
introduce --config flag
Diffstat (limited to 'bin/src/lint.rs')
-rw-r--r--bin/src/lint.rs17
1 files changed, 12 insertions, 5 deletions
diff --git a/bin/src/lint.rs b/bin/src/lint.rs
index 1138c23..3482d46 100644
--- a/bin/src/lint.rs
+++ b/bin/src/lint.rs
@@ -1,4 +1,6 @@
1use lib::{Report, LINTS}; 1use crate::{utils, LintMap};
2
3use lib::Report;
2use rnix::WalkEvent; 4use rnix::WalkEvent;
3use vfs::{FileId, VfsEntry}; 5use vfs::{FileId, VfsEntry};
4 6
@@ -8,18 +10,17 @@ pub struct LintResult {
8 pub reports: Vec<Report>, 10 pub reports: Vec<Report>,
9} 11}
10 12
11pub fn lint(vfs_entry: VfsEntry) -> LintResult { 13pub fn lint_with(vfs_entry: VfsEntry, lints: &LintMap) -> LintResult {
12 let file_id = vfs_entry.file_id; 14 let file_id = vfs_entry.file_id;
13 let source = vfs_entry.contents; 15 let source = vfs_entry.contents;
14 let parsed = rnix::parse(source); 16 let parsed = rnix::parse(source);
15 17
16 let error_reports = parsed.errors().into_iter().map(Report::from_parse_err); 18 let error_reports = parsed.errors().into_iter().map(Report::from_parse_err);
17
18 let reports = parsed 19 let reports = parsed
19 .node() 20 .node()
20 .preorder_with_tokens() 21 .preorder_with_tokens()
21 .filter_map(|event| match event { 22 .filter_map(|event| match event {
22 WalkEvent::Enter(child) => LINTS.get(&child.kind()).map(|rules| { 23 WalkEvent::Enter(child) => lints.get(&child.kind()).map(|rules| {
23 rules 24 rules
24 .iter() 25 .iter()
25 .filter_map(|rule| rule.validate(&child)) 26 .filter_map(|rule| rule.validate(&child))
@@ -34,15 +35,21 @@ pub fn lint(vfs_entry: VfsEntry) -> LintResult {
34 LintResult { file_id, reports } 35 LintResult { file_id, reports }
35} 36}
36 37
38pub fn lint(vfs_entry: VfsEntry) -> LintResult {
39 lint_with(vfs_entry, &utils::lint_map())
40}
41
37pub mod main { 42pub mod main {
38 use std::io; 43 use std::io;
39 44
40 use super::lint; 45 use super::lint_with;
41 use crate::{config::Check as CheckConfig, err::StatixErr, traits::WriteDiagnostic}; 46 use crate::{config::Check as CheckConfig, err::StatixErr, traits::WriteDiagnostic};
42 47
43 pub fn main(check_config: CheckConfig) -> Result<(), StatixErr> { 48 pub fn main(check_config: CheckConfig) -> Result<(), StatixErr> {
44 let vfs = check_config.vfs()?; 49 let vfs = check_config.vfs()?;
45 let mut stdout = io::stdout(); 50 let mut stdout = io::stdout();
51 let lints = check_config.lints()?;
52 let lint = |vfs_entry| lint_with(vfs_entry, &lints);
46 vfs.iter().map(lint).for_each(|r| { 53 vfs.iter().map(lint).for_each(|r| {
47 stdout.write(&r, &vfs, check_config.format).unwrap(); 54 stdout.write(&r, &vfs, check_config.format).unwrap();
48 }); 55 });