aboutsummaryrefslogtreecommitdiff
path: root/bin/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'bin/src/main.rs')
-rw-r--r--bin/src/main.rs43
1 files changed, 6 insertions, 37 deletions
diff --git a/bin/src/main.rs b/bin/src/main.rs
index b26151d..a3f04d7 100644
--- a/bin/src/main.rs
+++ b/bin/src/main.rs
@@ -1,57 +1,26 @@
1#![feature(path_try_exists)]
2
3mod config; 1mod config;
4mod err; 2mod err;
3mod lint;
5mod traits; 4mod traits;
6 5
7use std::io; 6use std::io;
8 7
9use crate::{ 8use crate::{err::StatixErr, traits::WriteDiagnostic};
10 err::{LintErr, StatixErr},
11 traits::{LintResult, WriteDiagnostic},
12};
13 9
14use clap::Clap; 10use clap::Clap;
15use config::{LintConfig, Opts, SubCommand}; 11use config::{LintConfig, Opts, SubCommand};
16use lib::LINTS;
17use rnix::WalkEvent;
18use vfs::VfsEntry;
19
20fn analyze<'ρ>(vfs_entry: VfsEntry<'ρ>) -> Result<LintResult, LintErr> {
21 let source = vfs_entry.contents;
22 let parsed = rnix::parse(source)
23 .as_result()
24 .map_err(|e| LintErr::Parse(vfs_entry.file_path.to_path_buf(), e))?;
25 let reports = parsed
26 .node()
27 .preorder_with_tokens()
28 .filter_map(|event| match event {
29 WalkEvent::Enter(child) => LINTS.get(&child.kind()).map(|rules| {
30 rules
31 .iter()
32 .filter_map(|rule| rule.validate(&child))
33 .collect::<Vec<_>>()
34 }),
35 _ => None,
36 })
37 .flatten()
38 .collect();
39 Ok(LintResult {
40 file_id: vfs_entry.file_id,
41 reports,
42 })
43}
44 12
45fn _main() -> Result<(), StatixErr> { 13fn _main() -> Result<(), StatixErr> {
46 // TODO: accept cli args, construct a CLI config with a list of files to analyze
47 let opts = Opts::parse(); 14 let opts = Opts::parse();
48 match opts.subcmd { 15 match opts.subcmd {
49 Some(SubCommand::Fix(_)) => {} 16 Some(SubCommand::Fix(_)) => {
17 eprintln!("`fix` not yet supported");
18 }
50 None => { 19 None => {
51 let lint_config = LintConfig::from_opts(opts)?; 20 let lint_config = LintConfig::from_opts(opts)?;
52 let vfs = lint_config.vfs()?; 21 let vfs = lint_config.vfs()?;
53 let (reports, errors): (Vec<_>, Vec<_>) = 22 let (reports, errors): (Vec<_>, Vec<_>) =
54 vfs.iter().map(analyze).partition(Result::is_ok); 23 vfs.iter().map(lint::lint).partition(Result::is_ok);
55 let lint_results: Vec<_> = reports.into_iter().map(Result::unwrap).collect(); 24 let lint_results: Vec<_> = reports.into_iter().map(Result::unwrap).collect();
56 let errors: Vec<_> = errors.into_iter().map(Result::unwrap_err).collect(); 25 let errors: Vec<_> = errors.into_iter().map(Result::unwrap_err).collect();
57 26