Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/shy-ants-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@biomejs/biome": patch
---

Fixed [#3824](https://github.com/biomejs/biome/issues/3824). Now the option CLI `--color` is correctly applied to logging too.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Correct the flag name and wording; match changeset style.

It’s --colors in the CLI, not --color. Also prefer the project voice and mention non‑TTY behaviour fixed by this PR.

-Fixed [#3824](https://github.com/biomejs/biome/issues/3824). Now the option CLI `--color` is correctly applied to logging too.
+Fixed #3824: Apply the CLI `--colors` option to logging. Biome now disables ANSI when output is not a TTY (for example when piped), unless `--colors=force` is set.
+
+```bash
+# colours disabled when piped
+biome check | cat
+# force colours
+biome check --colors=force
+```
🤖 Prompt for AI Agents
.changeset/shy-ants-buy.md around line 5: update the changelog sentence to use
the correct CLI flag name `--colors` (not `--color`), rewrite in the project
voice and style, and mention the non‑TTY behaviour fix with the provided
examples; specifically, change the line to say that the `--colors` option is now
correctly applied to logging (including when output is piped), and add the two
example shells showing colours disabled when piped (`biome check | cat`) and
forcing colours (`biome check --colors=force`) formatted consistently with
existing changeset code blocks.

9 changes: 9 additions & 0 deletions crates/biome_cli/src/cli_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ pub enum ColorsArg {
Force,
}

impl ColorsArg {
pub fn is_enabled(&self) -> bool {
matches!(self, Self::Force)
}
pub fn is_disabled(&self) -> bool {
matches!(self, Self::Off)
}
}

impl FromStr for ColorsArg {
type Err = String;

Expand Down
1 change: 1 addition & 0 deletions crates/biome_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,7 @@ pub(crate) trait CommandRunner: Sized {
cli_options.log_file.as_deref(),
cli_options.log_level,
cli_options.log_kind,
cli_options.colors.as_ref(),
);
Comment on lines +853 to 854
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Colour preference not applied: get_color() is ignored.

You compute CI/GitHub overrides in get_color() but pass cli_options.colors.as_ref() here, so the overrides never take effect.

Align with the updated logging signature:

-        setup_cli_subscriber(
-            cli_options.log_file.as_deref(),
-            cli_options.log_level,
-            cli_options.log_kind,
-            cli_options.colors.as_ref(),
-        );
+        let colors = self.get_color();
+        setup_cli_subscriber(
+            cli_options.log_file.as_deref(),
+            cli_options.log_level,
+            cli_options.log_kind,
+            colors,
+        );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
cli_options.colors.as_ref(),
);
let colors = self.get_color();
setup_cli_subscriber(
cli_options.log_file.as_deref(),
cli_options.log_level,
cli_options.log_kind,
colors,
);
🤖 Prompt for AI Agents
In crates/biome_cli/src/commands/mod.rs around lines 853-854, the call is
passing cli_options.colors.as_ref() which ignores CI/GitHub overrides computed
by get_color(); update the call to pass the result of get_color() (e.g.,
get_color(&cli_options)) or otherwise call the new logging signature that
accepts the computed Color preference so the CI/GitHub override is applied
instead of the raw CLI option.

let console = &mut *session.app.console;
let workspace = &*session.app.workspace;
Expand Down
10 changes: 8 additions & 2 deletions crates/biome_cli/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::fmt::{Display, Formatter};
use std::fs::File;
use std::str::FromStr;

use crate::cli_options::ColorsArg;
use tracing::Metadata;
use tracing::subscriber::Interest;
use tracing_subscriber::filter::LevelFilter;
Expand All @@ -10,7 +11,12 @@ use tracing_subscriber::layer::{Context, Filter, SubscriberExt};
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::{Layer as _, registry};

pub fn setup_cli_subscriber(file: Option<&str>, level: LoggingLevel, kind: LoggingKind) {
pub fn setup_cli_subscriber(
file: Option<&str>,
level: LoggingLevel,
kind: LoggingKind,
colors: Option<&ColorsArg>,
) {
Comment on lines +14 to +19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Accept colour preference by value to avoid lifetime foot‑guns.

Change setup_cli_subscriber to take Option<ColorsArg> (by value). This plays nicely with a value‑returning get_color() and avoids dangling refs.

-pub fn setup_cli_subscriber(
+pub fn setup_cli_subscriber(
     file: Option<&str>,
     level: LoggingLevel,
     kind: LoggingKind,
-    colors: Option<&ColorsArg>,
+    colors: Option<ColorsArg>,
 ) {
🤖 Prompt for AI Agents
In crates/biome_cli/src/logging.rs around lines 14 to 19, the function signature
currently takes colors: Option<&ColorsArg>, which can lead to lifetime issues;
change the signature to accept colors: Option<ColorsArg> (by value). Inside the
function, update any use of colors to consume or clone the owned value (e.g.,
call get_color() that returns a ColorsArg) rather than borrowing, adjust call
sites to pass an owned ColorsArg or None, and remove any unnecessary lifetime
annotations related to colors; ensure all places that previously passed a
reference now pass the value (or call .cloned()/.to_owned() where appropriate).

if level == LoggingLevel::None {
return;
}
Expand All @@ -20,7 +26,7 @@ pub fn setup_cli_subscriber(file: Option<&str>, level: LoggingLevel, kind: Loggi
.with_target(false)
.with_thread_names(true)
.with_file(true)
.with_ansi(true);
.with_ansi(colors.is_none_or(|c| c.is_enabled()));

if level == LoggingLevel::Tracing {
format = format.with_span_events(FmtSpan::CLOSE);
Expand Down
Loading