oxc/crates/oxc_cli/src/result.rs
Boshen ef19895cc3
feat(cli): add -A all -D isolated-declarations (#211)
* feat(linter): add restriction category for lint rules

* feat(cli): add "--allow" and "--deny" commands

* feat(linter): use a single instance of linter

* feat(cli): derive rules from args

* feat(cli): print number of rules
2023-03-26 04:34:31 -07:00

59 lines
1.7 KiB
Rust

use std::{
path::PathBuf,
process::{ExitCode, Termination},
};
#[derive(Debug)]
pub enum CliRunResult {
None,
PathNotFound {
paths: Vec<PathBuf>,
},
LintResult {
duration: std::time::Duration,
number_of_rules: usize,
number_of_files: usize,
number_of_warnings: usize,
number_of_diagnostics: usize,
max_warnings_exceeded: bool,
},
}
impl Termination for CliRunResult {
fn report(self) -> ExitCode {
match self {
Self::None => ExitCode::from(0),
Self::PathNotFound { paths } => {
println!("Path {paths:?} does not exist.");
ExitCode::from(1)
}
Self::LintResult {
duration,
number_of_rules,
number_of_files,
number_of_warnings,
number_of_diagnostics,
max_warnings_exceeded,
} => {
let ms = duration.as_millis();
let cpus = num_cpus::get();
println!(
"Finished in {ms}ms on {number_of_files} files with {number_of_rules} rules using {cpus} cores."
);
if max_warnings_exceeded {
println!("Exceeded maximum number of warnings. Found {number_of_warnings}.");
return ExitCode::from(1);
}
if number_of_diagnostics > 0 {
println!("Found {number_of_diagnostics} errors.");
return ExitCode::from(1);
}
println!("Found no errors.");
ExitCode::from(0)
}
}
}
}