From 9b1519e0a423d3ccadf147ae6e24bcc919a7fa1c Mon Sep 17 00:00:00 2001 From: Brent Westbrook Date: Thu, 3 Jul 2025 14:54:33 -0400 Subject: [PATCH] suppress summary messages for structured formats --- crates/ruff_db/src/diagnostic/mod.rs | 10 ++++++++++ crates/ty/src/lib.rs | 20 +++++++++++++------- crates/ty/tests/cli/main.rs | 1 - 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/crates/ruff_db/src/diagnostic/mod.rs b/crates/ruff_db/src/diagnostic/mod.rs index 8fe1c9f09f..7f3cc7f543 100644 --- a/crates/ruff_db/src/diagnostic/mod.rs +++ b/crates/ruff_db/src/diagnostic/mod.rs @@ -1238,6 +1238,16 @@ pub enum DiagnosticFormat { Azure, } +impl DiagnosticFormat { + /// Return whether or not the format is targeted at human readers. + /// + /// This excludes structured formats like JSON and indicates that summary messages like "All + /// checks passed!" should be suppressed. + pub fn is_human_readable(self) -> bool { + !matches!(self, Self::Azure) + } +} + /// A representation of the kinds of messages inside a diagnostic. pub enum ConciseMessage<'a> { /// A diagnostic contains a non-empty main message and an empty diff --git a/crates/ty/src/lib.rs b/crates/ty/src/lib.rs index a83b946ea2..31becd5d2a 100644 --- a/crates/ty/src/lib.rs +++ b/crates/ty/src/lib.rs @@ -291,6 +291,8 @@ impl MainLoop { .format(terminal_settings.output_format) .color(colored::control::SHOULD_COLORIZE.should_colorize()); + let should_print_summary = terminal_settings.output_format.is_human_readable(); + if check_revision == revision { if db.project().files(db).is_empty() { tracing::warn!("No python files found under the given path(s)"); @@ -299,7 +301,9 @@ impl MainLoop { let mut stdout = stdout().lock(); if result.is_empty() { - writeln!(stdout, "{}", "All checks passed!".green().bold())?; + if should_print_summary { + writeln!(stdout, "{}", "All checks passed!".green().bold())?; + } if self.watcher.is_none() { return Ok(ExitStatus::Success); @@ -314,12 +318,14 @@ impl MainLoop { max_severity = max_severity.max(diagnostic.severity()); } - writeln!( - stdout, - "Found {} diagnostic{}", - diagnostics_count, - if diagnostics_count > 1 { "s" } else { "" } - )?; + if should_print_summary { + writeln!( + stdout, + "Found {} diagnostic{}", + diagnostics_count, + if diagnostics_count > 1 { "s" } else { "" } + )?; + } if max_severity.is_fatal() { tracing::warn!( diff --git a/crates/ty/tests/cli/main.rs b/crates/ty/tests/cli/main.rs index c14d498090..ea963168bc 100644 --- a/crates/ty/tests/cli/main.rs +++ b/crates/ty/tests/cli/main.rs @@ -542,7 +542,6 @@ fn azure_diagnostics() -> anyhow::Result<()> { ----- stdout ----- ##vso[task.logissue type=warning;sourcepath=test.py;linenumber=2;columnnumber=7;]Name `x` used when not defined ##vso[task.logissue type=error;sourcepath=test.py;linenumber=3;columnnumber=7;]Cannot subscript object of type `Literal[4]` with no `__getitem__` method - Found 2 diagnostics ----- stderr ----- WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors.