mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(cli): add --deny-warnings flag (#1452)
See #1403 Terminates linting with an exit code of 1 if the `--deny-warnings` flag is provided _and_ there is 1 or more warnings produced from the linting.
This commit is contained in:
parent
10be84a07a
commit
0b6b0b4854
3 changed files with 9 additions and 1 deletions
|
|
@ -235,6 +235,10 @@ pub struct WarningOptions {
|
|||
#[bpaf(switch, hide_usage)]
|
||||
pub quiet: bool,
|
||||
|
||||
/// Ensure warnings produce a non-zero exit code
|
||||
#[bpaf(switch, hide_usage)]
|
||||
pub deny_warnings: bool,
|
||||
|
||||
/// Specify a warning threshold,
|
||||
/// which can be used to force exit with an error status if there are too many warning-level rule violations in your project
|
||||
#[bpaf(argument("INT"), hide_usage)]
|
||||
|
|
|
|||
|
|
@ -93,6 +93,7 @@ impl Runner for LintRunner {
|
|||
number_of_warnings: diagnostic_service.warnings_count(),
|
||||
number_of_errors: diagnostic_service.errors_count(),
|
||||
max_warnings_exceeded: diagnostic_service.max_warnings_exceeded(),
|
||||
deny_warnings: warning_options.deny_warnings,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ pub struct LintResult {
|
|||
pub number_of_warnings: usize,
|
||||
pub number_of_errors: usize,
|
||||
pub max_warnings_exceeded: bool,
|
||||
pub deny_warnings: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
@ -49,6 +50,7 @@ impl Termination for CliRunResult {
|
|||
number_of_warnings,
|
||||
number_of_errors,
|
||||
max_warnings_exceeded,
|
||||
deny_warnings,
|
||||
}) => {
|
||||
let threads = rayon::current_num_threads();
|
||||
let number_of_diagnostics = number_of_warnings + number_of_errors;
|
||||
|
|
@ -74,7 +76,8 @@ impl Termination for CliRunResult {
|
|||
if number_of_errors == 1 { "" } else { "s" }
|
||||
);
|
||||
|
||||
let exit_code = u8::from(number_of_errors > 0);
|
||||
let exit_code =
|
||||
u8::from((number_of_warnings > 0 && deny_warnings) || number_of_errors > 0);
|
||||
ExitCode::from(exit_code)
|
||||
}
|
||||
Self::FormatResult(FormatResult { duration, number_of_files }) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue