diff --git a/crates/oxc_cli/src/lint/mod.rs b/crates/oxc_cli/src/lint/mod.rs index 8b63afe94..321ef693c 100644 --- a/crates/oxc_cli/src/lint/mod.rs +++ b/crates/oxc_cli/src/lint/mod.rs @@ -145,6 +145,7 @@ impl Runner for LintRunner { number_of_errors: diagnostic_service.errors_count(), max_warnings_exceeded: diagnostic_service.max_warnings_exceeded(), deny_warnings: warning_options.deny_warnings, + print_summary: diagnostic_service.is_graphical_output(), }) } } diff --git a/crates/oxc_cli/src/result.rs b/crates/oxc_cli/src/result.rs index e8334652d..1b23d1657 100644 --- a/crates/oxc_cli/src/result.rs +++ b/crates/oxc_cli/src/result.rs @@ -23,6 +23,7 @@ pub struct LintResult { pub number_of_errors: usize, pub max_warnings_exceeded: bool, pub deny_warnings: bool, + pub print_summary: bool, } #[derive(Debug)] @@ -51,31 +52,36 @@ impl Termination for CliRunResult { number_of_errors, max_warnings_exceeded, deny_warnings, + print_summary, }) => { - let threads = rayon::current_num_threads(); - let number_of_diagnostics = number_of_warnings + number_of_errors; + if print_summary { + let threads = rayon::current_num_threads(); + let number_of_diagnostics = number_of_warnings + number_of_errors; - if number_of_diagnostics > 0 { - println!(); + if number_of_diagnostics > 0 { + println!(); + } + + let time = Self::get_execution_time(&duration); + let s = if number_of_files == 1 { "" } else { "s" }; + println!( + "Finished in {time} on {number_of_files} file{s} with {number_of_rules} rules using {threads} threads." + ); + + if max_warnings_exceeded { + println!( + "Exceeded maximum number of warnings. Found {number_of_warnings}." + ); + return ExitCode::from(1); + } + + println!( + "Found {number_of_warnings} warning{} and {number_of_errors} error{}.", + if number_of_warnings == 1 { "" } else { "s" }, + if number_of_errors == 1 { "" } else { "s" } + ); } - let time = Self::get_execution_time(&duration); - let s = if number_of_files == 1 { "" } else { "s" }; - println!( - "Finished in {time} on {number_of_files} file{s} with {number_of_rules} rules using {threads} threads." - ); - - if max_warnings_exceeded { - println!("Exceeded maximum number of warnings. Found {number_of_warnings}."); - return ExitCode::from(1); - } - - println!( - "Found {number_of_warnings} warning{} and {number_of_errors} error{}.", - if number_of_warnings == 1 { "" } else { "s" }, - if number_of_errors == 1 { "" } else { "s" } - ); - let exit_code = u8::from((number_of_warnings > 0 && deny_warnings) || number_of_errors > 0); ExitCode::from(exit_code) diff --git a/crates/oxc_diagnostics/src/service.rs b/crates/oxc_diagnostics/src/service.rs index 06d5ebd3c..0e9190be6 100644 --- a/crates/oxc_diagnostics/src/service.rs +++ b/crates/oxc_diagnostics/src/service.rs @@ -52,6 +52,10 @@ impl DiagnosticService { self.reporter = DiagnosticReporter::new_json(); } + pub fn is_graphical_output(&self) -> bool { + matches!(self.reporter, DiagnosticReporter::Graphical { .. }) + } + #[must_use] pub fn with_quiet(mut self, yes: bool) -> Self { self.quiet = yes;