Skip to content

Commit

Permalink
feat(cli): force colours when running ci command (#2943)
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico authored May 22, 2024
1 parent 5e30f76 commit 417a174
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 74 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,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
Expand Down
46 changes: 22 additions & 24 deletions crates/biome_cli/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ use biome_configuration::{
organize_imports::PartialOrganizeImports, PartialConfiguration, PartialFormatterConfiguration,
PartialLinterConfiguration,
};
use biome_console::{markup, ConsoleExt};
use biome_deserialize::Merge;
use biome_diagnostics::PrintDiagnostic;
use biome_service::configuration::{load_editorconfig, PartialConfigurationExt};
use biome_service::configuration::PartialConfigurationExt;
use biome_service::workspace::RegisterProjectFolderParams;
use biome_service::{
configuration::{load_configuration, LoadedConfiguration},
Expand Down Expand Up @@ -82,34 +80,34 @@ pub(crate) fn check(
session.app.console,
cli_options.verbose,
)?;
let fs = &session.app.fs;
let (editorconfig, editorconfig_diagnostics) = {
let search_path = loaded_configuration
.directory_path
.clone()
.unwrap_or_else(|| fs.working_directory().unwrap_or_default());
load_editorconfig(fs, search_path)?
};
for diagnostic in editorconfig_diagnostics {
session.app.console.error(markup! {
{PrintDiagnostic::simple(&diagnostic)}
})
}
// let fs = &session.app.fs;
// let (editorconfig, editorconfig_diagnostics) = {
// let search_path = loaded_configuration
// .directory_path
// .clone()
// .unwrap_or_else(|| fs.working_directory().unwrap_or_default());
// load_editorconfig(fs, search_path)?
// };
// for diagnostic in editorconfig_diagnostics {
// session.app.console.error(markup! {
// {PrintDiagnostic::simple(&diagnostic)}
// })
// }

resolve_manifest(&session)?;

let LoadedConfiguration {
configuration: biome_configuration,
configuration: mut fs_configuration,
directory_path: configuration_path,
..
} = loaded_configuration;
let mut fs_configuration = if let Some(mut fs_configuration) = editorconfig {
// this makes biome configuration take precedence over editorconfig configuration
fs_configuration.merge_with(biome_configuration);
fs_configuration
} else {
biome_configuration
};
// let mut fs_configuration = if let Some(mut fs_configuration) = editorconfig {
// // this makes biome configuration take precedence over editorconfig configuration
// fs_configuration.merge_with(biome_configuration);
// fs_configuration
// } else {
// biome_configuration
// };

let formatter = fs_configuration
.formatter
Expand Down
44 changes: 22 additions & 22 deletions crates/biome_cli/src/commands/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use biome_console::{markup, ConsoleExt};
use biome_deserialize::Merge;
use biome_diagnostics::PrintDiagnostic;
use biome_service::configuration::{
load_configuration, load_editorconfig, LoadedConfiguration, PartialConfigurationExt,
load_configuration, LoadedConfiguration, PartialConfigurationExt,
};
use biome_service::workspace::{RegisterProjectFolderParams, UpdateSettingsParams};
use std::ffi::OsString;
Expand Down Expand Up @@ -77,33 +77,33 @@ pub(crate) fn format(
session.app.console,
cli_options.verbose,
)?;
let fs = &session.app.fs;
let (editorconfig, editorconfig_diagnostics) = {
let search_path = loaded_configuration
.directory_path
.clone()
.unwrap_or_else(|| fs.working_directory().unwrap_or_default());
load_editorconfig(fs, search_path)?
};
for diagnostic in editorconfig_diagnostics {
session.app.console.error(markup! {
{PrintDiagnostic::simple(&diagnostic)}
})
}
// let fs = &session.app.fs;
// let (editorconfig, editorconfig_diagnostics) = {
// let search_path = loaded_configuration
// .directory_path
// .clone()
// .unwrap_or_else(|| fs.working_directory().unwrap_or_default());
// load_editorconfig(fs, search_path)?
// };
// for diagnostic in editorconfig_diagnostics {
// session.app.console.error(markup! {
// {PrintDiagnostic::simple(&diagnostic)}
// })
// }

resolve_manifest(&session)?;
let LoadedConfiguration {
configuration: biome_configuration,
mut configuration,
directory_path: configuration_path,
..
} = loaded_configuration;
let mut configuration = if let Some(mut configuration) = editorconfig {
// this makes biome configuration take precedence over editorconfig configuration
configuration.merge_with(biome_configuration);
configuration
} else {
biome_configuration
};
// let mut configuration = if let Some(mut configuration) = editorconfig {
// // this makes biome configuration take precedence over editorconfig configuration
// configuration.merge_with(biome_configuration);
// configuration
// } else {
// biome_configuration
// };

// TODO: remove in biome 2.0
let console = &mut *session.app.console;
Expand Down
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
1 change: 1 addition & 0 deletions crates/biome_cli/tests/cases/editorconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use bpaf::Args;
use std::path::Path;

#[test]
#[ignore = "enable once we have the configuration to turn it on"]
fn should_use_editorconfig() {
let mut fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion packages/@biomejs/js-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type {
Diagnostic,
FixFileMode,
PartialConfiguration,
PullDiagnosticsResult,
Workspace,
} from "@biomejs/wasm-nodejs";
import { Distribution, type WasmModule, loadModule, wrapError } from "./wasm";
Expand Down

0 comments on commit 417a174

Please sign in to comment.