mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 20:28:58 +00:00
refactor(oxlint): create different CliRunResult instead of passing ExitCode to it (#8777)
This commit is contained in:
parent
2378fef3cf
commit
fe45bee0c2
2 changed files with 26 additions and 18 deletions
|
|
@ -2,7 +2,6 @@ use std::{
|
|||
env, fs,
|
||||
io::{ErrorKind, Write},
|
||||
path::{Path, PathBuf},
|
||||
process::ExitCode,
|
||||
time::Instant,
|
||||
};
|
||||
|
||||
|
|
@ -79,8 +78,7 @@ impl Runner for LintRunner {
|
|||
// If explicit paths were provided, but all have been
|
||||
// filtered, return early.
|
||||
if provided_path_count > 0 {
|
||||
// ToDo: when oxc_linter (config) validates the configuration, we can use exit_code = 1 to fail
|
||||
return CliRunResult::LintResult(ExitCode::SUCCESS);
|
||||
return CliRunResult::LintNoFilesFound;
|
||||
}
|
||||
|
||||
paths.push(self.cwd.clone());
|
||||
|
|
@ -218,10 +216,6 @@ impl Runner for LintRunner {
|
|||
|
||||
let diagnostic_result = diagnostic_service.run(stdout);
|
||||
|
||||
let diagnostic_failed = diagnostic_result.max_warnings_exceeded()
|
||||
|| diagnostic_result.errors_count() > 0
|
||||
|| (warning_options.deny_warnings && diagnostic_result.warnings_count() > 0);
|
||||
|
||||
if let Some(end) = output_formatter.lint_command_info(&LintCommandInfo {
|
||||
number_of_files,
|
||||
number_of_rules: lint_service.linter().number_of_rules(),
|
||||
|
|
@ -232,7 +226,15 @@ impl Runner for LintRunner {
|
|||
stdout.flush().unwrap();
|
||||
};
|
||||
|
||||
CliRunResult::LintResult(ExitCode::from(u8::from(diagnostic_failed)))
|
||||
if diagnostic_result.errors_count() > 0 {
|
||||
CliRunResult::LintFoundErrors
|
||||
} else if warning_options.deny_warnings && diagnostic_result.warnings_count() > 0 {
|
||||
CliRunResult::LintNoWarningsAllowed
|
||||
} else if diagnostic_result.max_warnings_exceeded() {
|
||||
CliRunResult::LintMaxWarningsExceeded
|
||||
} else {
|
||||
CliRunResult::LintSucceeded
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,11 +3,12 @@ use std::process::{ExitCode, Termination};
|
|||
#[derive(Debug)]
|
||||
pub enum CliRunResult {
|
||||
None,
|
||||
InvalidOptions {
|
||||
message: String,
|
||||
},
|
||||
/// The exit unix code for, in general 0 or 1 (from `--deny-warnings` or `--max-warnings` for example)
|
||||
LintResult(ExitCode),
|
||||
InvalidOptions { message: String },
|
||||
LintSucceeded,
|
||||
LintFoundErrors,
|
||||
LintMaxWarningsExceeded,
|
||||
LintNoWarningsAllowed,
|
||||
LintNoFilesFound,
|
||||
PrintConfigResult,
|
||||
ConfigFileInitFailed,
|
||||
ConfigFileInitSucceeded,
|
||||
|
|
@ -17,15 +18,20 @@ impl Termination for CliRunResult {
|
|||
#[allow(clippy::print_stdout, clippy::print_stderr)]
|
||||
fn report(self) -> ExitCode {
|
||||
match self {
|
||||
Self::None | Self::PrintConfigResult | Self::ConfigFileInitSucceeded => {
|
||||
ExitCode::SUCCESS
|
||||
}
|
||||
Self::ConfigFileInitFailed => ExitCode::FAILURE,
|
||||
Self::None
|
||||
| Self::PrintConfigResult
|
||||
| Self::ConfigFileInitSucceeded
|
||||
| Self::LintSucceeded
|
||||
// ToDo: when oxc_linter (config) validates the configuration, we can use exit_code = 1 to fail
|
||||
| Self::LintNoFilesFound => ExitCode::SUCCESS,
|
||||
Self::ConfigFileInitFailed
|
||||
| Self::LintFoundErrors
|
||||
| Self::LintNoWarningsAllowed
|
||||
| Self::LintMaxWarningsExceeded => ExitCode::FAILURE,
|
||||
Self::InvalidOptions { message } => {
|
||||
println!("Invalid Options: {message}");
|
||||
ExitCode::FAILURE
|
||||
}
|
||||
Self::LintResult(exit_code) => exit_code,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue