-
Notifications
You must be signed in to change notification settings - Fork 107
/
lint.rs
32 lines (30 loc) · 1.06 KB
/
lint.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use anyhow::Result;
use clap::ArgMatches;
use kclvm_error::Handler;
use kclvm_runner::ExecProgramArgs;
use kclvm_tools::lint::lint_files;
use crate::settings::must_build_settings;
/// Run the KCL lint command.
pub fn lint_command(matches: &ArgMatches) -> Result<()> {
let mut files = match matches.get_many::<String>("input") {
Some(files) => files.into_iter().map(|f| f.as_str()).collect::<Vec<&str>>(),
None => vec![],
};
// Config settings building
let settings = must_build_settings(matches);
// Convert settings into execute arguments.
let args: ExecProgramArgs = settings.try_into()?;
files = if !files.is_empty() {
files
} else {
args.get_files()
};
let (mut err_handler, mut warning_handler) = (Handler::default(), Handler::default());
(err_handler.diagnostics, warning_handler.diagnostics) =
lint_files(&files, Some(args.get_load_program_options()));
if matches.get_count("emit_warning") > 0 {
warning_handler.emit()?;
}
err_handler.abort_if_any_errors();
Ok(())
}