aboutsummaryrefslogtreecommitdiff
path: root/bin/src/lint.rs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-10-29 13:50:54 +0100
committerAkshay <[email protected]>2021-10-29 14:14:14 +0100
commit1a97cce01f8e49b33bf28cbcdfeb3c8aefd809a5 (patch)
tree62613f193d84ea8b0c0aa94d09758fee19a6042d /bin/src/lint.rs
parentd510714ed5a1eae0f6e5e435e4cff4875b06751d (diff)
report syntax errors as statix errors
- statix now reports errors also, not just warnings - all diagnostics are available on stderr stream - non-utf8 files are skipped, does not eject early
Diffstat (limited to 'bin/src/lint.rs')
-rw-r--r--bin/src/lint.rs22
1 files changed, 12 insertions, 10 deletions
diff --git a/bin/src/lint.rs b/bin/src/lint.rs
index 65ae824..e889d31 100644
--- a/bin/src/lint.rs
+++ b/bin/src/lint.rs
@@ -1,5 +1,3 @@
1use crate::err::LintErr;
2
3use lib::{Report, LINTS}; 1use lib::{Report, LINTS};
4use rnix::WalkEvent; 2use rnix::WalkEvent;
5use vfs::{FileId, VfsEntry}; 3use vfs::{FileId, VfsEntry};
@@ -10,11 +8,16 @@ pub struct LintResult {
10 pub reports: Vec<Report>, 8 pub reports: Vec<Report>,
11} 9}
12 10
13pub fn lint(vfs_entry: VfsEntry) -> Result<LintResult, LintErr> { 11pub fn lint(vfs_entry: VfsEntry) -> LintResult {
12 let file_id = vfs_entry.file_id;
14 let source = vfs_entry.contents; 13 let source = vfs_entry.contents;
15 let parsed = rnix::parse(source) 14 let parsed = rnix::parse(source);
16 .as_result() 15
17 .map_err(|e| LintErr::Parse(vfs_entry.file_path.to_path_buf(), e))?; 16 let error_reports = parsed
17 .errors()
18 .into_iter()
19 .map(|e| Report::from_parse_err(e));
20
18 let reports = parsed 21 let reports = parsed
19 .node() 22 .node()
20 .preorder_with_tokens() 23 .preorder_with_tokens()
@@ -28,9 +31,8 @@ pub fn lint(vfs_entry: VfsEntry) -> Result<LintResult, LintErr> {
28 _ => None, 31 _ => None,
29 }) 32 })
30 .flatten() 33 .flatten()
34 .chain(error_reports)
31 .collect(); 35 .collect();
32 Ok(LintResult { 36
33 file_id: vfs_entry.file_id, 37 LintResult { file_id, reports }
34 reports,
35 })
36} 38}