suppress summary messages for structured formats

This commit is contained in:
Brent Westbrook 2025-07-03 14:54:33 -04:00
parent a4093e4b54
commit 9b1519e0a4
3 changed files with 23 additions and 8 deletions

View file

@ -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

View file

@ -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() {
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());
}
if should_print_summary {
writeln!(
stdout,
"Found {} diagnostic{}",
diagnostics_count,
if diagnostics_count > 1 { "s" } else { "" }
)?;
}
if max_severity.is_fatal() {
tracing::warn!(

View file

@ -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.