From 165091a31c3ce99732cdeff22e1cde00abd592ad Mon Sep 17 00:00:00 2001 From: Brent Westbrook <36778786+ntBre@users.noreply.github.com> Date: Fri, 25 Jul 2025 15:47:49 -0400 Subject: [PATCH] Add `TextEmitter::with_color` and disable colors in `unreadable_files` test (#19562) Summary -- I looked at other uses of `TextEmitter`, and I think this should be the only one affected by this. The other integration tests must work properly since they're run with `assert_cmd_snapshot!`, which I assume triggers the `SHOULD_COLORIZE` case, and the `cfg!(test)` check will work for uses in `ruff_linter`. https://github.com/astral-sh/ruff/blob/4a4dc38b5b5055601dcb8da4ad07720e47d451fa/crates/ruff_linter/src/message/text.rs#L36-L44 Alternatively, we could probably move this to a CLI test instead. Test Plan -- `cargo test -p ruff`, which was failing on `main` with color codes in the output before this --- crates/ruff/src/commands/check.rs | 1 + crates/ruff_linter/src/message/text.rs | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/crates/ruff/src/commands/check.rs b/crates/ruff/src/commands/check.rs index b33dcfe8cb..0c0ed5995b 100644 --- a/crates/ruff/src/commands/check.rs +++ b/crates/ruff/src/commands/check.rs @@ -279,6 +279,7 @@ mod test { TextEmitter::default() .with_show_fix_status(true) + .with_color(false) .emit( &mut output, &diagnostics.inner, diff --git a/crates/ruff_linter/src/message/text.rs b/crates/ruff_linter/src/message/text.rs index 5659306d81..265f717b27 100644 --- a/crates/ruff_linter/src/message/text.rs +++ b/crates/ruff_linter/src/message/text.rs @@ -76,6 +76,12 @@ impl TextEmitter { self.config = self.config.preview(preview); self } + + #[must_use] + pub fn with_color(mut self, color: bool) -> Self { + self.config = self.config.color(color); + self + } } impl Emitter for TextEmitter {