Skip to content

Commit

Permalink
feat(cli): force colours when running ci command
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed May 22, 2024
1 parent 8f3c811 commit e9eb55b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
9 changes: 7 additions & 2 deletions crates/biome_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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);
Expand Down
36 changes: 19 additions & 17 deletions packages/@biomejs/js-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -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}.
Expand Down Expand Up @@ -196,12 +196,14 @@ 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,
});

console.log("Enforce changes to trigger the workflow");

const hasErrors = diagnostics.some(
(diag) => diag.severity === "fatal" || diag.severity === "error",
);
Expand Down Expand Up @@ -247,26 +249,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,
Expand Down

0 comments on commit e9eb55b

Please sign in to comment.