From 96b60c11d9efbfbf97faa5394fc3f7cb0a5c40c5 Mon Sep 17 00:00:00 2001 From: Brent Westbrook <36778786+ntBre@users.noreply.github.com> Date: Mon, 27 Oct 2025 12:04:55 -0400 Subject: [PATCH] Respect `--output-format` with `--watch` (#21097) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary -- Fixes #19550 This PR copies our non-watch diagnostic rendering code into `Printer::write_continuously` in preview mode, allowing it to use whatever output format is passed in. I initially marked this as also fixing #19552, but I guess that's not true currently but will be true once this is stabilized and we can remove the warning. Test Plan -- Existing tests, but I don't think we have any `watch` tests, so some manual testing as well. The default with just `ruff check --watch` is still `concise`, adding just `--preview` still gives the `full` output, and then specifying any other output format works, with JSON as one example: Screenshot 2025-10-27 at 9 21 41 AM --- crates/ruff/src/printer.rs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/crates/ruff/src/printer.rs b/crates/ruff/src/printer.rs index 5c1b1d0e6a..1de440ac6e 100644 --- a/crates/ruff/src/printer.rs +++ b/crates/ruff/src/printer.rs @@ -9,9 +9,7 @@ use itertools::{Itertools, iterate}; use ruff_linter::linter::FixTable; use serde::Serialize; -use ruff_db::diagnostic::{ - Diagnostic, DiagnosticFormat, DisplayDiagnosticConfig, DisplayDiagnostics, SecondaryCode, -}; +use ruff_db::diagnostic::{Diagnostic, DisplayDiagnosticConfig, SecondaryCode}; use ruff_linter::fs::relativize_path; use ruff_linter::logging::LogLevel; use ruff_linter::message::{EmitterContext, render_diagnostics}; @@ -390,21 +388,18 @@ impl Printer { let context = EmitterContext::new(&diagnostics.notebook_indexes); let format = if preview { - DiagnosticFormat::Full + self.format } else { - DiagnosticFormat::Concise + OutputFormat::Concise }; let config = DisplayDiagnosticConfig::default() + .preview(preview) .hide_severity(true) .color(!cfg!(test) && colored::control::SHOULD_COLORIZE.should_colorize()) .with_show_fix_status(show_fix_status(self.fix_mode, fixables.as_ref())) - .format(format) - .with_fix_applicability(self.unsafe_fixes.required_applicability()); - write!( - writer, - "{}", - DisplayDiagnostics::new(&context, &config, &diagnostics.inner) - )?; + .with_fix_applicability(self.unsafe_fixes.required_applicability()) + .show_fix_diff(preview); + render_diagnostics(writer, format, config, &context, &diagnostics.inner)?; } writer.flush()?;