mirror of https://github.com/astral-sh/ruff
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" />
This commit is contained in:
parent
fffbe5a879
commit
96b60c11d9
|
|
@ -9,9 +9,7 @@ use itertools::{Itertools, iterate};
|
||||||
use ruff_linter::linter::FixTable;
|
use ruff_linter::linter::FixTable;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use ruff_db::diagnostic::{
|
use ruff_db::diagnostic::{Diagnostic, DisplayDiagnosticConfig, SecondaryCode};
|
||||||
Diagnostic, DiagnosticFormat, DisplayDiagnosticConfig, DisplayDiagnostics, SecondaryCode,
|
|
||||||
};
|
|
||||||
use ruff_linter::fs::relativize_path;
|
use ruff_linter::fs::relativize_path;
|
||||||
use ruff_linter::logging::LogLevel;
|
use ruff_linter::logging::LogLevel;
|
||||||
use ruff_linter::message::{EmitterContext, render_diagnostics};
|
use ruff_linter::message::{EmitterContext, render_diagnostics};
|
||||||
|
|
@ -390,21 +388,18 @@ impl Printer {
|
||||||
|
|
||||||
let context = EmitterContext::new(&diagnostics.notebook_indexes);
|
let context = EmitterContext::new(&diagnostics.notebook_indexes);
|
||||||
let format = if preview {
|
let format = if preview {
|
||||||
DiagnosticFormat::Full
|
self.format
|
||||||
} else {
|
} else {
|
||||||
DiagnosticFormat::Concise
|
OutputFormat::Concise
|
||||||
};
|
};
|
||||||
let config = DisplayDiagnosticConfig::default()
|
let config = DisplayDiagnosticConfig::default()
|
||||||
|
.preview(preview)
|
||||||
.hide_severity(true)
|
.hide_severity(true)
|
||||||
.color(!cfg!(test) && colored::control::SHOULD_COLORIZE.should_colorize())
|
.color(!cfg!(test) && colored::control::SHOULD_COLORIZE.should_colorize())
|
||||||
.with_show_fix_status(show_fix_status(self.fix_mode, fixables.as_ref()))
|
.with_show_fix_status(show_fix_status(self.fix_mode, fixables.as_ref()))
|
||||||
.format(format)
|
.with_fix_applicability(self.unsafe_fixes.required_applicability())
|
||||||
.with_fix_applicability(self.unsafe_fixes.required_applicability());
|
.show_fix_diff(preview);
|
||||||
write!(
|
render_diagnostics(writer, format, config, &context, &diagnostics.inner)?;
|
||||||
writer,
|
|
||||||
"{}",
|
|
||||||
DisplayDiagnostics::new(&context, &config, &diagnostics.inner)
|
|
||||||
)?;
|
|
||||||
}
|
}
|
||||||
writer.flush()?;
|
writer.flush()?;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue