From afe30ea0f1ef47e207ad5c0b041850fe5ae81b19 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Wed, 22 May 2024 08:56:45 +0100 Subject: [PATCH] feat(cli): force colours when running `ci` command --- CHANGELOG.md | 2 ++ crates/biome_cli/src/main.rs | 9 +++++-- packages/@biomejs/js-api/src/index.ts | 34 +++++++++++++-------------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76dd395c2871..8655f98cd66f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -141,6 +141,8 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b ``` Contributed by @ematipico +- `biome ci` now enforces printing the output using colours. If you were previously using `--colors=force`, you can remove it because it's automatically set. Contributed by @ematipico + ### Configuration #### New features diff --git a/crates/biome_cli/src/main.rs b/crates/biome_cli/src/main.rs index 7f1553cfbeda..c6e6a7a20a78 100644 --- a/crates/biome_cli/src/main.rs +++ b/crates/biome_cli/src/main.rs @@ -8,7 +8,7 @@ use biome_cli::{ biome_command, open_transport, setup_panic_handler, to_color_mode, BiomeCommand, CliDiagnostic, CliSession, }; -use biome_console::{markup, ConsoleExt, EnvConsole}; +use biome_console::{markup, ColorMode, ConsoleExt, EnvConsole}; use biome_diagnostics::{set_bottom_frame, Diagnostic, PrintDiagnostic}; use biome_service::workspace; use std::process::{ExitCode, Termination}; @@ -38,7 +38,12 @@ fn main() -> ExitCode { let command = biome_command().fallback_to_usage().run(); let color_mode = to_color_mode(command.get_color()); - console.set_color(color_mode); + // we want force colours in CI, to give e better UX experience + if matches!(command, BiomeCommand::Ci { .. }) { + console.set_color(ColorMode::Enabled); + } else { + console.set_color(color_mode); + } let is_verbose = command.is_verbose(); let result = run_workspace(&mut console, command); diff --git a/packages/@biomejs/js-api/src/index.ts b/packages/@biomejs/js-api/src/index.ts index 430b70af9b16..62d5335efc8e 100644 --- a/packages/@biomejs/js-api/src/index.ts +++ b/packages/@biomejs/js-api/src/index.ts @@ -3,15 +3,14 @@ import type { Diagnostic, FixFileMode, PartialConfiguration, - PullDiagnosticsResult, Workspace, } from "@biomejs/wasm-nodejs"; -import { Distribution, type WasmModule, loadModule, wrapError } from "./wasm"; +import {Distribution, type WasmModule, loadModule, wrapError} from "./wasm"; // Re-export of some useful types for users export type Configuration = PartialConfiguration; -export type { Diagnostic }; -export { Distribution }; +export type {Diagnostic}; +export {Distribution}; export interface FormatContentDebugOptions extends FormatContentOptions { /** @@ -93,7 +92,8 @@ export class Biome { private constructor( private readonly module: WasmModule, private readonly workspace: Workspace, - ) {} + ) { + } /** * It creates a new instance of the class {Biome}. @@ -196,7 +196,7 @@ export class Biome { return this.withFile(options.filePath, content, (path) => { let code = content; - const { diagnostics } = this.workspace.pullDiagnostics({ + const {diagnostics} = this.workspace.pullDiagnostics({ path, categories: ["Syntax"], max_diagnostics: Number.MAX_SAFE_INTEGER, @@ -247,26 +247,26 @@ export class Biome { */ lintContent( content: string, - { filePath, fixFileMode }: LintContentOptions, + {filePath, fixFileMode}: LintContentOptions, ): LintResult { const maybeFixedContent = fixFileMode ? this.withFile(filePath, content, (path) => { - let code = content; + let code = content; - const result = this.workspace.fixFile({ - path, - fix_file_mode: fixFileMode, - should_format: false, - }); + const result = this.workspace.fixFile({ + path, + fix_file_mode: fixFileMode, + should_format: false, + }); - code = result.code; + code = result.code; - return code; - }) + return code; + }) : content; return this.withFile(filePath, maybeFixedContent, (path) => { - const { diagnostics } = this.workspace.pullDiagnostics({ + const {diagnostics} = this.workspace.pullDiagnostics({ path, categories: ["Syntax", "Lint"], max_diagnostics: Number.MAX_SAFE_INTEGER,