Skip to content

Commit 96b60c1

Browse files
authored
Respect --output-format with --watch (#21097)
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: <img width="695" height="719" alt="Screenshot 2025-10-27 at 9 21 41 AM" src="https://github.com/user-attachments/assets/98957911-d216-4fc4-8b6c-22c56c963b3f" />
1 parent fffbe5a commit 96b60c1

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

crates/ruff/src/printer.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ use itertools::{Itertools, iterate};
99
use ruff_linter::linter::FixTable;
1010
use serde::Serialize;
1111

12-
use ruff_db::diagnostic::{
13-
Diagnostic, DiagnosticFormat, DisplayDiagnosticConfig, DisplayDiagnostics, SecondaryCode,
14-
};
12+
use ruff_db::diagnostic::{Diagnostic, DisplayDiagnosticConfig, SecondaryCode};
1513
use ruff_linter::fs::relativize_path;
1614
use ruff_linter::logging::LogLevel;
1715
use ruff_linter::message::{EmitterContext, render_diagnostics};
@@ -390,21 +388,18 @@ impl Printer {
390388

391389
let context = EmitterContext::new(&diagnostics.notebook_indexes);
392390
let format = if preview {
393-
DiagnosticFormat::Full
391+
self.format
394392
} else {
395-
DiagnosticFormat::Concise
393+
OutputFormat::Concise
396394
};
397395
let config = DisplayDiagnosticConfig::default()
396+
.preview(preview)
398397
.hide_severity(true)
399398
.color(!cfg!(test) && colored::control::SHOULD_COLORIZE.should_colorize())
400399
.with_show_fix_status(show_fix_status(self.fix_mode, fixables.as_ref()))
401-
.format(format)
402-
.with_fix_applicability(self.unsafe_fixes.required_applicability());
403-
write!(
404-
writer,
405-
"{}",
406-
DisplayDiagnostics::new(&context, &config, &diagnostics.inner)
407-
)?;
400+
.with_fix_applicability(self.unsafe_fixes.required_applicability())
401+
.show_fix_diff(preview);
402+
render_diagnostics(writer, format, config, &context, &diagnostics.inner)?;
408403
}
409404
writer.flush()?;
410405

0 commit comments

Comments
 (0)