Skip to content

Commit fe45bee

Browse files
committedJan 30, 2025·
refactor(oxlint): create different CliRunResult instead of passing ExitCode to it (#8777)
1 parent 2378fef commit fe45bee

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed
 

Diff for: ‎apps/oxlint/src/lint.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::{
22
env, fs,
33
io::{ErrorKind, Write},
44
path::{Path, PathBuf},
5-
process::ExitCode,
65
time::Instant,
76
};
87

@@ -79,8 +78,7 @@ impl Runner for LintRunner {
7978
// If explicit paths were provided, but all have been
8079
// filtered, return early.
8180
if provided_path_count > 0 {
82-
// ToDo: when oxc_linter (config) validates the configuration, we can use exit_code = 1 to fail
83-
return CliRunResult::LintResult(ExitCode::SUCCESS);
81+
return CliRunResult::LintNoFilesFound;
8482
}
8583

8684
paths.push(self.cwd.clone());
@@ -218,10 +216,6 @@ impl Runner for LintRunner {
218216

219217
let diagnostic_result = diagnostic_service.run(stdout);
220218

221-
let diagnostic_failed = diagnostic_result.max_warnings_exceeded()
222-
|| diagnostic_result.errors_count() > 0
223-
|| (warning_options.deny_warnings && diagnostic_result.warnings_count() > 0);
224-
225219
if let Some(end) = output_formatter.lint_command_info(&LintCommandInfo {
226220
number_of_files,
227221
number_of_rules: lint_service.linter().number_of_rules(),
@@ -232,7 +226,15 @@ impl Runner for LintRunner {
232226
stdout.flush().unwrap();
233227
};
234228

235-
CliRunResult::LintResult(ExitCode::from(u8::from(diagnostic_failed)))
229+
if diagnostic_result.errors_count() > 0 {
230+
CliRunResult::LintFoundErrors
231+
} else if warning_options.deny_warnings && diagnostic_result.warnings_count() > 0 {
232+
CliRunResult::LintNoWarningsAllowed
233+
} else if diagnostic_result.max_warnings_exceeded() {
234+
CliRunResult::LintMaxWarningsExceeded
235+
} else {
236+
CliRunResult::LintSucceeded
237+
}
236238
}
237239
}
238240

Diff for: ‎apps/oxlint/src/result.rs

+16-10
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ use std::process::{ExitCode, Termination};
33
#[derive(Debug)]
44
pub enum CliRunResult {
55
None,
6-
InvalidOptions {
7-
message: String,
8-
},
9-
/// The exit unix code for, in general 0 or 1 (from `--deny-warnings` or `--max-warnings` for example)
10-
LintResult(ExitCode),
6+
InvalidOptions { message: String },
7+
LintSucceeded,
8+
LintFoundErrors,
9+
LintMaxWarningsExceeded,
10+
LintNoWarningsAllowed,
11+
LintNoFilesFound,
1112
PrintConfigResult,
1213
ConfigFileInitFailed,
1314
ConfigFileInitSucceeded,
@@ -17,15 +18,20 @@ impl Termination for CliRunResult {
1718
#[allow(clippy::print_stdout, clippy::print_stderr)]
1819
fn report(self) -> ExitCode {
1920
match self {
20-
Self::None | Self::PrintConfigResult | Self::ConfigFileInitSucceeded => {
21-
ExitCode::SUCCESS
22-
}
23-
Self::ConfigFileInitFailed => ExitCode::FAILURE,
21+
Self::None
22+
| Self::PrintConfigResult
23+
| Self::ConfigFileInitSucceeded
24+
| Self::LintSucceeded
25+
// ToDo: when oxc_linter (config) validates the configuration, we can use exit_code = 1 to fail
26+
| Self::LintNoFilesFound => ExitCode::SUCCESS,
27+
Self::ConfigFileInitFailed
28+
| Self::LintFoundErrors
29+
| Self::LintNoWarningsAllowed
30+
| Self::LintMaxWarningsExceeded => ExitCode::FAILURE,
2431
Self::InvalidOptions { message } => {
2532
println!("Invalid Options: {message}");
2633
ExitCode::FAILURE
2734
}
28-
Self::LintResult(exit_code) => exit_code,
2935
}
3036
}
3137
}

0 commit comments

Comments
 (0)
Please sign in to comment.