diff options
author | Akshay <[email protected]> | 2021-11-20 13:26:26 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2021-11-28 07:55:23 +0000 |
commit | 2b6012a79cb092e5d88c050cb494057efef28fc2 (patch) | |
tree | cd31973c32431a5cbf8c12ce574f799d065852be /bin/src/lint.rs | |
parent | 4e063b2abc402ac4d6902647e821978269025c7d (diff) |
introduce --config flag
Diffstat (limited to 'bin/src/lint.rs')
-rw-r--r-- | bin/src/lint.rs | 17 |
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 @@ | |||
1 | use lib::{Report, LINTS}; | 1 | use crate::{utils, LintMap}; |
2 | |||
3 | use lib::Report; | ||
2 | use rnix::WalkEvent; | 4 | use rnix::WalkEvent; |
3 | use vfs::{FileId, VfsEntry}; | 5 | use 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 | ||
11 | pub fn lint(vfs_entry: VfsEntry) -> LintResult { | 13 | pub 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 | ||
38 | pub fn lint(vfs_entry: VfsEntry) -> LintResult { | ||
39 | lint_with(vfs_entry, &utils::lint_map()) | ||
40 | } | ||
41 | |||
37 | pub mod main { | 42 | pub 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 | }); |