Skip to content

Conversation

ematipico
Copy link
Member

Summary

Closes #3824

Test Plan

Manually tested with and without --colors option. IT works as expected

Docs

Copy link

changeset-bot bot commented Sep 8, 2025

🦋 Changeset detected

Latest commit: b938b6c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

coderabbitai bot commented Sep 8, 2025

Walkthrough

Adds colour handling to CLI logging. Introduces ColorsArg helpers (is_enabled/is_disabled). Propagates an optional colour argument from command execution to logging initialisation by extending setup_cli_subscriber’s signature. Logging now toggles ANSI based on ColorsArg: enabled when None or Force; disabled when Off. Includes a changeset referencing #3824.

Assessment against linked issues

Objective Addressed Explanation
--colors=off disables colours in CLI logging (#3824)
Autodetect disables colours when output is piped (e.g., cat) (#3824)

Possibly related PRs

  • fix(cli): pretty logger #7264 — Also modifies crates/biome_cli/src/logging.rs for the Pretty formatter; interacts with the same logging initialisation.

Suggested labels

A-CLI

Suggested reviewers

  • siketyan
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/log-colors

Comment @coderabbitai help to get the list of available commands and usage tips.

@ematipico ematipico requested review from a team September 8, 2025 08:34
@github-actions github-actions bot added the A-CLI Area: CLI label Sep 8, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
crates/biome_cli/src/logging.rs (1)

24-31: Defaulting to ANSI when colors is None breaks piped output. Autodetect TTY and disable for files.

This currently enables colours even when output is piped or redirected, contradicting #3824. Compute ANSI as:

  • Force → on.
  • Off → off.
  • None → on only if stdout is a TTY; if writing to a file, off.

Apply:

-    let mut format = tracing_subscriber::fmt::layer()
+    let use_ansi = match (file.is_some(), colors.map(|c| c.is_enabled())) {
+        // Explicit user choice wins
+        (_, Some(true)) => true,
+        (_, Some(false)) => false,
+        // No explicit choice: disable for files, autodetect for stdout
+        (true, None) => false,
+        (false, None) => std::io::stdout().is_terminal(),
+    };
+
+    let mut format = tracing_subscriber::fmt::layer()
         .with_level(true)
         .with_target(false)
         .with_thread_names(true)
         .with_file(true)
-        .with_ansi(colors.is_none_or(|c| c.is_enabled()));
+        .with_ansi(use_ansi);

Add (outside this hunk) the import for detection:

use std::io::IsTerminal as _;

Also, to keep MSRV flexible, prefer map_or/is_some_and over newer is_none_or.

crates/biome_cli/src/commands/mod.rs (1)

605-622: Borrowed temporaries: returning Option<&ColorsArg> risks dangling refs. Return by value.

Some(&ColorsArg::Off/Force) creates references to temporaries. Return Option<ColorsArg> and clone the existing flag when present.

-    pub const fn get_color(&self) -> Option<&ColorsArg> {
+    pub fn get_color(&self) -> Option<ColorsArg> {
         match self.cli_options() {
             Some(cli_options) => {
                 // To properly display GitHub annotations we need to disable colors
-                if matches!(cli_options.reporter, CliReporter::GitHub) {
-                    return Some(&ColorsArg::Off);
+                if matches!(cli_options.reporter, CliReporter::GitHub) {
+                    return Some(ColorsArg::Off);
                 }
                 // We want force colors in CI, to give e better UX experience
                 // Unless users explicitly set the colors flag
-                if matches!(self, Self::Ci { .. }) && cli_options.colors.is_none() {
-                    return Some(&ColorsArg::Force);
+                if matches!(self, Self::Ci { .. }) && cli_options.colors.is_none() {
+                    return Some(ColorsArg::Force);
                 }
                 // Normal behaviors
-                cli_options.colors.as_ref()
+                cli_options.colors.clone()
             }
             None => None,
         }
     }

Nit: comment typo “give e better UX experience” → “give a better UX experience”.

🧹 Nitpick comments (1)
crates/biome_cli/src/cli_options.rs (1)

121-128: Helpers read clean; consider making ColorsArg trivially copyable.

is_enabled/is_disabled are fine. Returning/passing colours by value elsewhere will be simpler if ColorsArg is Copy.

Outside this hunk, add Copy:

// at line 115
#[derive(Debug, Clone, Copy)]
pub enum ColorsArg {
    Off,
    Force,
}
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9686f98 and b938b6c.

📒 Files selected for processing (4)
  • .changeset/shy-ants-buy.md (1 hunks)
  • crates/biome_cli/src/cli_options.rs (1 hunks)
  • crates/biome_cli/src/commands/mod.rs (1 hunks)
  • crates/biome_cli/src/logging.rs (3 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
.changeset/*.md

📄 CodeRabbit inference engine (CONTRIBUTING.md)

.changeset/*.md: In changeset files, only use #### or ##### headers; avoid other header levels
Changeset descriptions should use past tense for what you did (e.g., "Added...")
Describe current Biome behavior in present tense within changesets (e.g., "Biome now supports...")
For bug fixes in changesets, start with a link to the issue (e.g., "Fixed #1234: ...")
When referencing rules or assists in changesets, include links to their documentation pages
Include a minimal code block in the changeset when applicable to demonstrate the change
End every sentence in the changeset description with a period

Files:

  • .changeset/shy-ants-buy.md
crates/biome_*/**

📄 CodeRabbit inference engine (CLAUDE.md)

Place core crates under /crates/biome_*/

Files:

  • crates/biome_cli/src/commands/mod.rs
  • crates/biome_cli/src/logging.rs
  • crates/biome_cli/src/cli_options.rs
**/*.rs

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Format all Rust source files before committing (just f)

Files:

  • crates/biome_cli/src/commands/mod.rs
  • crates/biome_cli/src/logging.rs
  • crates/biome_cli/src/cli_options.rs
🧠 Learnings (1)
📚 Learning: 2025-09-07T17:35:00.490Z
Learnt from: CR
PR: biomejs/biome#0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-09-07T17:35:00.490Z
Learning: Applies to .changeset/*.md : Describe current Biome behavior in present tense within changesets (e.g., "Biome now supports...")

Applied to files:

  • .changeset/shy-ants-buy.md
🧬 Code graph analysis (1)
crates/biome_cli/src/cli_options.rs (1)
crates/biome_cli/src/logging.rs (1)
  • is_enabled (154-166)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Check Dependencies
  • GitHub Check: Documentation
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Test Node.js API
  • GitHub Check: autofix

"@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.

Comment on lines +853 to 854
cli_options.colors.as_ref(),
);
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.

Comment on lines +14 to +19
pub fn setup_cli_subscriber(
file: Option<&str>,
level: LoggingLevel,
kind: LoggingKind,
colors: Option<&ColorsArg>,
) {
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).

@ematipico ematipico merged commit 733828c into main Sep 8, 2025
13 checks passed
@ematipico ematipico deleted the fix/log-colors branch September 8, 2025 08:44
@github-actions github-actions bot mentioned this pull request Sep 8, 2025
kedevked pushed a commit to kedevked/biome that referenced this pull request Sep 22, 2025
Co-authored-by: siketyan <[email protected]>
Co-authored-by: mdevils <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-CLI Area: CLI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 --colors option broken
3 participants