From f27372061a0effe3b00d400f4e577b9d9e0ad4c0 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sat, 20 Nov 2021 18:57:28 +0530 Subject: add config option to fix and check --- bin/src/lint.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'bin/src/lint.rs') 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 @@ -use lib::{Report, LINTS}; +use crate::{utils, LintMap}; + +use lib::Report; use rnix::WalkEvent; use vfs::{FileId, VfsEntry}; @@ -8,18 +10,17 @@ pub struct LintResult { pub reports: Vec, } -pub fn lint(vfs_entry: VfsEntry) -> LintResult { +pub fn lint_with(vfs_entry: VfsEntry, lints: &LintMap) -> LintResult { let file_id = vfs_entry.file_id; let source = vfs_entry.contents; let parsed = rnix::parse(source); let error_reports = parsed.errors().into_iter().map(Report::from_parse_err); - let reports = parsed .node() .preorder_with_tokens() .filter_map(|event| match event { - WalkEvent::Enter(child) => LINTS.get(&child.kind()).map(|rules| { + WalkEvent::Enter(child) => lints.get(&child.kind()).map(|rules| { rules .iter() .filter_map(|rule| rule.validate(&child)) @@ -34,15 +35,21 @@ pub fn lint(vfs_entry: VfsEntry) -> LintResult { LintResult { file_id, reports } } +pub fn lint(vfs_entry: VfsEntry) -> LintResult { + lint_with(vfs_entry, &utils::lint_map()) +} + pub mod main { use std::io; - use super::lint; + use super::lint_with; use crate::{config::Check as CheckConfig, err::StatixErr, traits::WriteDiagnostic}; pub fn main(check_config: CheckConfig) -> Result<(), StatixErr> { let vfs = check_config.vfs()?; let mut stdout = io::stdout(); + let lints = check_config.lints()?; + let lint = |vfs_entry| lint_with(vfs_entry, &lints); vfs.iter().map(lint).for_each(|r| { stdout.write(&r, &vfs, check_config.format).unwrap(); }); -- cgit v1.2.3