Skip to content

Commit 165091a

Browse files
authored
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
1 parent 4a4dc38 commit 165091a

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

crates/ruff/src/commands/check.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ mod test {
279279

280280
TextEmitter::default()
281281
.with_show_fix_status(true)
282+
.with_color(false)
282283
.emit(
283284
&mut output,
284285
&diagnostics.inner,

crates/ruff_linter/src/message/text.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ impl TextEmitter {
7676
self.config = self.config.preview(preview);
7777
self
7878
}
79+
80+
#[must_use]
81+
pub fn with_color(mut self, color: bool) -> Self {
82+
self.config = self.config.color(color);
83+
self
84+
}
7985
}
8086

8187
impl Emitter for TextEmitter {

0 commit comments

Comments
 (0)