Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::{
env, fs,
io::{ErrorKind, Write},
path::{Path, PathBuf},
process::ExitCode,
time::Instant,
};

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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(),
Expand All @@ -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
}
}
}

Expand Down
26 changes: 16 additions & 10 deletions apps/oxlint/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
}
}
}