From 23f1a1b4d6fd98e846432af99d167b5effeb4fb7 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Tue, 17 Feb 2026 09:34:06 +0000 Subject: [PATCH 1/5] fix(cli): use github reporter in github actions env --- .changeset/cool-snails-wave.md | 5 + Cargo.lock | 52 ++ crates/biome_cli/Cargo.toml | 2 + crates/biome_cli/src/commands/ci.rs | 15 +- crates/biome_cli/src/runner/execution.rs | 7 +- crates/biome_cli/src/runner/finalizer.rs | 1 - .../src/runner/impls/finalizers/default.rs | 497 +++++++++--------- crates/biome_cli/src/runner/mod.rs | 1 - crates/biome_cli/tests/cases/help.rs | 214 ++++++++ crates/biome_cli/tests/cases/mod.rs | 1 + crates/biome_cli/tests/commands/check.rs | 18 - crates/biome_cli/tests/commands/ci.rs | 18 - crates/biome_cli/tests/commands/explain.rs | 22 - crates/biome_cli/tests/commands/format.rs | 22 - crates/biome_cli/tests/commands/init.rs | 18 - crates/biome_cli/tests/commands/lint.rs | 18 - crates/biome_cli/tests/commands/lsp_proxy.rs | 27 - crates/biome_cli/tests/commands/migrate.rs | 22 - crates/biome_cli/tests/commands/mod.rs | 2 - crates/biome_cli/tests/commands/rage.rs | 36 +- crates/biome_cli/tests/commands/start.rs | 23 - crates/biome_cli/tests/main.rs | 19 - .../check_help.snap | 0 .../ci_help.snap | 0 .../explain_help.snap | 0 .../format_help.snap | 0 .../init_help.snap | 0 .../lint_help.snap | 0 .../lsp_proxy_help.snap | 0 .../migrate_help.snap | 0 .../rage_help.snap | 0 .../start_help.snap | 0 32 files changed, 540 insertions(+), 500 deletions(-) create mode 100644 .changeset/cool-snails-wave.md create mode 100644 crates/biome_cli/tests/cases/help.rs delete mode 100644 crates/biome_cli/tests/commands/lsp_proxy.rs delete mode 100644 crates/biome_cli/tests/commands/start.rs rename crates/biome_cli/tests/snapshots/{main_commands_check => main_cases_help}/check_help.snap (100%) rename crates/biome_cli/tests/snapshots/{main_commands_ci => main_cases_help}/ci_help.snap (100%) rename crates/biome_cli/tests/snapshots/{main_commands_explain => main_cases_help}/explain_help.snap (100%) rename crates/biome_cli/tests/snapshots/{main_commands_format => main_cases_help}/format_help.snap (100%) rename crates/biome_cli/tests/snapshots/{main_commands_init => main_cases_help}/init_help.snap (100%) rename crates/biome_cli/tests/snapshots/{main_commands_lint => main_cases_help}/lint_help.snap (100%) rename crates/biome_cli/tests/snapshots/{main_commands_lsp_proxy => main_cases_help}/lsp_proxy_help.snap (100%) rename crates/biome_cli/tests/snapshots/{main_commands_migrate => main_cases_help}/migrate_help.snap (100%) rename crates/biome_cli/tests/snapshots/{main_commands_rage => main_cases_help}/rage_help.snap (100%) rename crates/biome_cli/tests/snapshots/{main_commands_start => main_cases_help}/start_help.snap (100%) diff --git a/.changeset/cool-snails-wave.md b/.changeset/cool-snails-wave.md new file mode 100644 index 000000000000..13c523b9a2b2 --- /dev/null +++ b/.changeset/cool-snails-wave.md @@ -0,0 +1,5 @@ +--- +"@biomejs/biome": patch +--- + +Fixed [#9109](https://github.com/biomejs/biome/issues/9109), where the GitHub reporter wasn't correctly enabled when `biome ci` runs on GitHub Actions. diff --git a/Cargo.lock b/Cargo.lock index e1c6235abc65..c6ab38dbae48 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -225,7 +225,9 @@ dependencies = [ "rustc-hash 2.1.1", "serde", "serde_json", + "serial_test", "smallvec", + "temp-env", "terminal_size 0.4.3", "tikv-jemallocator", "tokio", @@ -4799,6 +4801,15 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "scc" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46e6f046b7fef48e2660c57ed794263155d713de679057f2d0c169bfc6e756cc" +dependencies = [ + "sdd", +] + [[package]] name = "schemars" version = "1.2.1" @@ -4838,6 +4849,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "sdd" +version = "3.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "490dcfcbfef26be6800d11870ff2df8774fa6e86d047e3e8c8a76b25655e41ca" + [[package]] name = "seize" version = "0.5.0" @@ -4959,6 +4976,32 @@ dependencies = [ "unsafe-libyaml", ] +[[package]] +name = "serial_test" +version = "3.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d0b343e184fc3b7bb44dff0705fffcf4b3756ba6aff420dddd8b24ca145e555" +dependencies = [ + "futures-executor", + "futures-util", + "log", + "once_cell", + "parking_lot", + "scc", + "serial_test_derive", +] + +[[package]] +name = "serial_test_derive" +version = "3.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f50427f258fb77356e4cd4aa0e87e2bd2c66dbcee41dc405282cae2bfc26c83" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.106", +] + [[package]] name = "sharded-slab" version = "0.1.4" @@ -5168,6 +5211,15 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "591ef38edfb78ca4771ee32cf494cb8771944bee237a9b91fc9c1424ac4b777b" +[[package]] +name = "temp-env" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96374855068f47402c3121c6eed88d29cb1de8f3ab27090e273e420bdabcf050" +dependencies = [ + "parking_lot", +] + [[package]] name = "tempfile" version = "3.23.0" diff --git a/crates/biome_cli/Cargo.toml b/crates/biome_cli/Cargo.toml index 51dfd3949008..8887856fa6d2 100644 --- a/crates/biome_cli/Cargo.toml +++ b/crates/biome_cli/Cargo.toml @@ -88,6 +88,8 @@ biome_json_parser = { workspace = true } directories = { workspace = true } insta = { workspace = true } regex = { workspace = true } +serial_test = "3.3.1" +temp-env = "0.3.6" tokio = { workspace = true, features = ["io-util"] } [target.'cfg(all(target_family="unix", not(all(target_arch = "aarch64", target_env = "musl"))))'.dependencies] diff --git a/crates/biome_cli/src/commands/ci.rs b/crates/biome_cli/src/commands/ci.rs index 73132335d6e7..0be2fe39fce4 100644 --- a/crates/biome_cli/src/commands/ci.rs +++ b/crates/biome_cli/src/commands/ci.rs @@ -1,6 +1,6 @@ use crate::CliDiagnostic; use crate::changed::get_changed_files; -use crate::cli_options::CliOptions; +use crate::cli_options::{CliOptions, CliReporter, CliReporterKind}; use crate::runner::execution::{AnalyzerSelectors, Execution, ExecutionEnvironment, VcsTargeted}; use crate::runner::impls::commands::traversal::{LoadEditorConfig, TraversalCommand}; use crate::runner::impls::executions::summary_verb::SummaryVerbExecution; @@ -44,7 +44,7 @@ pub(crate) struct CiCommandPayload { struct CiExecution { /// Whether the CI is running in a specific environment, e.g. GitHub, GitLab, etc. - _environment: Option, + environment: Option, /// A flag to know vcs integrated options such as `--staged` or `--changed` are enabled vcs_targeted: VcsTargeted, /// Whether assist diagnostics should be promoted to error, and fail the CLI @@ -115,6 +115,15 @@ impl Execution for CiExecution { fn summary_phrase(&self, files: usize, duration: &Duration) -> MarkupBuf { SummaryVerbExecution.summary_verb("Checked", files, duration) } + + fn environment_to_reporter(&self) -> Option { + self.environment.map(|e| match e { + ExecutionEnvironment::GitHub => CliReporter { + kind: CliReporterKind::GitHub, + destination: None, + }, + }) + } } impl LoadEditorConfig for CiCommandPayload { @@ -149,7 +158,7 @@ impl TraversalCommand for CiCommandPayload { .is_some_and(|value| value == "true"); Ok(Box::new(CiExecution { - _environment: if is_github { + environment: if is_github { Some(ExecutionEnvironment::GitHub) } else { None diff --git a/crates/biome_cli/src/runner/execution.rs b/crates/biome_cli/src/runner/execution.rs index 933cc1623d21..efaac3fa3628 100644 --- a/crates/biome_cli/src/runner/execution.rs +++ b/crates/biome_cli/src/runner/execution.rs @@ -1,4 +1,4 @@ -use crate::cli_options::CliOptions; +use crate::cli_options::{CliOptions, CliReporter}; use biome_configuration::analyzer::AnalyzerSelector; use biome_console::MarkupBuf; use biome_diagnostics::Category; @@ -161,6 +161,11 @@ pub(crate) trait Execution: Send + Sync + std::panic::RefUnwindSafe { /// Used when printing summary fn summary_phrase(&self, files: usize, duration: &Duration) -> MarkupBuf; + + /// Uses additional reporters based on the environment execution + fn environment_to_reporter(&self) -> Option { + None + } } #[derive(Debug, Default, Clone)] diff --git a/crates/biome_cli/src/runner/finalizer.rs b/crates/biome_cli/src/runner/finalizer.rs index f6952969b2f7..44e81e4fed26 100644 --- a/crates/biome_cli/src/runner/finalizer.rs +++ b/crates/biome_cli/src/runner/finalizer.rs @@ -29,7 +29,6 @@ pub trait Finalizer { pub(crate) struct FinalizePayload<'a, I> { pub(crate) fs: &'a dyn FileSystem, - pub(crate) workspace: &'a dyn Workspace, pub(crate) scan_duration: Option, pub(crate) console: &'a mut dyn Console, pub(crate) cli_options: &'a CliOptions, diff --git a/crates/biome_cli/src/runner/impls/finalizers/default.rs b/crates/biome_cli/src/runner/impls/finalizers/default.rs index 3dd0df01e162..7177a3188807 100644 --- a/crates/biome_cli/src/runner/impls/finalizers/default.rs +++ b/crates/biome_cli/src/runner/impls/finalizers/default.rs @@ -1,4 +1,4 @@ -use crate::cli_options::CliReporterKind; +use crate::cli_options::{CliOptions, CliReporter, CliReporterKind}; use crate::reporter::checkstyle::CheckstyleReporter; use crate::reporter::github::{GithubReporter, GithubReporterVisitor}; use crate::reporter::gitlab::{GitLabReporter, GitLabReporterVisitor}; @@ -9,15 +9,17 @@ use crate::reporter::sarif::{SarifReporter, SarifReporterVisitor}; use crate::reporter::summary::{SummaryReporter, SummaryReporterVisitor}; use crate::reporter::terminal::{ConsoleReporter, ConsoleReporterVisitor}; use crate::reporter::{ConsoleReporterWriter, FileReporterWriter, Reporter, ReporterWriter}; +use crate::runner::execution::Execution; use crate::runner::finalizer::{FinalizePayload, Finalizer}; use crate::runner::impls::commands::traversal::TraverseResult; -use crate::{CliDiagnostic, DiagnosticsPayload}; -use biome_console::markup; +use crate::{CliDiagnostic, DiagnosticsPayload, TraversalSummary}; +use biome_console::{Console, markup}; use biome_diagnostics::{PrintDiagnostic, Resource}; -use biome_fs::OpenOptions; +use biome_fs::{BiomePath, FileSystem, OpenOptions}; use biome_json_formatter::context::JsonFormatOptions; use biome_rowan::AstNode; use std::cmp::Ordering; +use std::collections::BTreeSet; pub(crate) struct DefaultFinalizer; @@ -27,7 +29,6 @@ impl Finalizer for DefaultFinalizer { fn finalize(payload: FinalizePayload<'_, Self::Input>) -> Result<(), CliDiagnostic> { let FinalizePayload { fs, - workspace, scan_duration, console, cli_options, @@ -68,218 +69,44 @@ impl Finalizer for DefaultFinalizer { max_diagnostics: cli_options.max_diagnostics, }; - let mut console_reporter_writer = ConsoleReporterWriter(console); let mut file_reporter_writer = FileReporterWriter::default(); if !cli_options.cli_reporter.is_empty() { for cli_reporter in &cli_options.cli_reporter { - match cli_reporter.kind { - CliReporterKind::Default => { - let reporter = ConsoleReporter { - summary, - diagnostics_payload: &diagnostics_payload, - execution, - verbose: cli_options.verbose, - working_directory: fs.working_directory().clone(), - evaluated_paths: evaluated_paths.clone(), - }; - if cli_reporter.is_file_report() { - reporter - .write(&mut file_reporter_writer, &mut ConsoleReporterVisitor)?; - } else { - reporter - .write(&mut console_reporter_writer, &mut ConsoleReporterVisitor)?; - } - } - CliReporterKind::Summary => { - let reporter = SummaryReporter { - summary, - diagnostics_payload: &diagnostics_payload, - execution, - verbose: cli_options.verbose, - working_directory: fs.working_directory().clone(), - evaluated_paths: evaluated_paths.clone(), - }; - if cli_reporter.is_file_report() { - reporter - .write(&mut file_reporter_writer, &mut SummaryReporterVisitor)?; - } else { - reporter - .write(&mut console_reporter_writer, &mut SummaryReporterVisitor)?; - } - } - CliReporterKind::Json | CliReporterKind::JsonPretty => { - console_reporter_writer.error(markup! { - "The ""--json"" option is ""unstable/experimental"" and its output might change between patches/minor releases." - }); - let reporter = JsonReporter { - summary, - diagnostics_payload: &diagnostics_payload, - execution, - verbose: cli_options.verbose, - working_directory: fs.working_directory().clone(), - }; - let mut buffer = JsonReporterVisitor::new(summary); - reporter.write(&mut console_reporter_writer, &mut buffer)?; - let root = buffer.to_json(); - if cli_reporter.kind == CliReporterKind::JsonPretty { - let formatted = biome_json_formatter::format_node( - JsonFormatOptions::default(), - root.syntax(), - ) - .expect("To format the JSON report") - .print() - .expect("To print the JSON report"); - - console_reporter_writer.log(markup! { - {formatted.as_code()} - }); - } else { - let code = root.to_string(); - console_reporter_writer.log(markup! { - {code} - }); - } - } - CliReporterKind::GitHub => { - let reporter = GithubReporter { - diagnostics_payload: &diagnostics_payload, - execution, - verbose: cli_options.verbose, - working_directory: fs.working_directory().clone(), - }; - if cli_reporter.is_file_report() { - reporter - .write(&mut file_reporter_writer, &mut GithubReporterVisitor)?; - } else { - reporter - .write(&mut console_reporter_writer, &mut GithubReporterVisitor)?; - } - } - CliReporterKind::GitLab => { - let reporter = GitLabReporter { - diagnostics_payload: &diagnostics_payload, - execution, - verbose: cli_options.verbose, - working_directory: fs.working_directory().clone(), - }; - if cli_reporter.is_file_report() { - reporter.write( - &mut file_reporter_writer, - &mut GitLabReporterVisitor::new(workspace.fs().working_directory()), - )?; - } else { - reporter.write( - &mut console_reporter_writer, - &mut GitLabReporterVisitor::new(workspace.fs().working_directory()), - )?; - } - } - CliReporterKind::Junit => { - let reporter = JunitReporter { - summary, - diagnostics_payload: &diagnostics_payload, - execution, - verbose: cli_options.verbose, - working_directory: fs.working_directory().clone(), - }; - - if cli_reporter.is_file_report() { - reporter.write( - &mut file_reporter_writer, - &mut JunitReporterVisitor::new(), - )?; - } else { - reporter.write( - &mut console_reporter_writer, - &mut JunitReporterVisitor::new(), - )?; - } - } - CliReporterKind::Checkstyle => { - let reporter = CheckstyleReporter { - summary, - diagnostics_payload: &diagnostics_payload, - execution, - verbose: cli_options.verbose, - working_directory: fs.working_directory().clone(), - }; - if cli_reporter.is_file_report() { - reporter.write( - &mut file_reporter_writer, - &mut crate::reporter::checkstyle::CheckstyleReporterVisitor, - )?; - } else { - reporter.write( - &mut console_reporter_writer, - &mut crate::reporter::checkstyle::CheckstyleReporterVisitor, - )?; - } - } - CliReporterKind::RdJson => { - let reporter = RdJsonReporter { - diagnostics_payload: &diagnostics_payload, - execution, - verbose: cli_options.verbose, - working_directory: fs.working_directory().clone(), - }; - if cli_reporter.is_file_report() { - reporter - .write(&mut file_reporter_writer, &mut RdJsonReporterVisitor)?; - } else { - reporter - .write(&mut console_reporter_writer, &mut RdJsonReporterVisitor)?; - } - } - CliReporterKind::Sarif => { - let reporter = SarifReporter { - diagnostics_payload: &diagnostics_payload, - execution, - verbose: cli_options.verbose, - working_directory: fs.working_directory().clone(), - }; - - if cli_reporter.is_file_report() { - reporter.write( - &mut file_reporter_writer, - &mut SarifReporterVisitor::new(), - )?; - } else { - reporter.write( - &mut console_reporter_writer, - &mut SarifReporterVisitor::new(), - )?; - } - } - } - - if let Some(destination) = cli_reporter.destination.as_deref() - && let Some(output) = file_reporter_writer.dump() - { - let open_options = OpenOptions::default().write(true).create(true); - let mut file = match fs.open_with_options(destination, open_options) { - Ok(file) => file, - Err(err) => { - let diagnostics = CliDiagnostic::from(err); - console_reporter_writer.error(markup! { - {PrintDiagnostic::simple(&diagnostics)} - }); - continue; - } - }; - - let result = file.set_content(output.as_bytes()); - if let Err(err) = result { - let diagnostics = CliDiagnostic::from(err); - console_reporter_writer.error(markup! { - {PrintDiagnostic::simple(&diagnostics)} - }) - } + print_to_reporter( + cli_reporter, + cli_options, + &diagnostics_payload, + summary, + evaluated_paths.clone(), + &mut file_reporter_writer, + console, + fs, + execution, + )?; + } + } else { + if let Some(reporter) = execution.environment_to_reporter() { + let contains_current_reporter = cli_options + .cli_reporter + .iter() + .any(|r| &r.kind == &reporter.kind); - file_reporter_writer.clear(); + if !contains_current_reporter { + print_to_reporter( + &reporter, + cli_options, + &diagnostics_payload, + summary, + evaluated_paths.clone(), + &mut file_reporter_writer, + console, + fs, + execution, + )?; } } - } else { + let mut console_reporter_writer = ConsoleReporterWriter(console); let reporter = ConsoleReporter { summary, diagnostics_payload: &diagnostics_payload, @@ -324,52 +151,206 @@ impl Finalizer for () { } } -// -// /// Tells to the execution of the traversal how the information should be reported -// #[derive(Copy, Clone, Debug)] -// pub enum ReportMode { -// /// Reports information straight to the console, it's the default mode -// Terminal { with_summary: bool }, -// /// Reports information in JSON format -// Json { pretty: bool }, -// /// Reports information for GitHub -// GitHub, -// /// JUnit output -// /// Ref: https://github.com/testmoapp/junitxml?tab=readme-ov-file#basic-junit-xml-structure -// Junit, -// /// Reports information in the [GitLab Code Quality](https://docs.gitlab.com/ee/ci/testing/code_quality.html#implement-a-custom-tool) format. -// GitLab, -// /// Reports diagnostics in [Checkstyle XML format](https://checkstyle.org/). -// Checkstyle, -// /// Reports information in [reviewdog JSON format](https://deepwiki.com/reviewdog/reviewdog/3.2-reviewdog-diagnostic-format) -// RdJson, -// /// Reports diagnostics using the SARIF format -// Sarif, -// } +fn print_to_reporter<'a, 'b>( + cli_reporter: &'a CliReporter, + cli_options: &'a CliOptions, + diagnostics_payload: &'a DiagnosticsPayload, + summary: TraversalSummary, + evaluated_paths: BTreeSet, + file_reporter_writer: &'b mut FileReporterWriter, + console: &'a mut dyn Console, + fs: &'a dyn FileSystem, + execution: &'a dyn Execution, +) -> Result<(), CliDiagnostic> { + let mut console_reporter_writer = ConsoleReporterWriter(console); + match cli_reporter.kind { + CliReporterKind::Default => { + let reporter = ConsoleReporter { + summary, + diagnostics_payload: &diagnostics_payload, + execution, + verbose: cli_options.verbose, + working_directory: fs.working_directory().clone(), + evaluated_paths: evaluated_paths.clone(), + }; + if cli_reporter.is_file_report() { + reporter.write(file_reporter_writer, &mut ConsoleReporterVisitor)?; + } else { + reporter.write(&mut console_reporter_writer, &mut ConsoleReporterVisitor)?; + } + } + CliReporterKind::Summary => { + let reporter = SummaryReporter { + summary, + diagnostics_payload: &diagnostics_payload, + execution, + verbose: cli_options.verbose, + working_directory: fs.working_directory().clone(), + evaluated_paths: evaluated_paths.clone(), + }; + if cli_reporter.is_file_report() { + reporter.write(file_reporter_writer, &mut SummaryReporterVisitor)?; + } else { + reporter.write(&mut console_reporter_writer, &mut SummaryReporterVisitor)?; + } + } + CliReporterKind::Json | CliReporterKind::JsonPretty => { + console_reporter_writer.error(markup! { + "The ""--json"" option is ""unstable/experimental"" and its output might change between patches/minor releases." + }); + let reporter = JsonReporter { + summary, + diagnostics_payload: &diagnostics_payload, + execution, + verbose: cli_options.verbose, + working_directory: fs.working_directory().clone(), + }; + let mut buffer = JsonReporterVisitor::new(summary); + reporter.write(&mut console_reporter_writer, &mut buffer)?; + let root = buffer.to_json(); + if cli_reporter.kind == CliReporterKind::JsonPretty { + let formatted = + biome_json_formatter::format_node(JsonFormatOptions::default(), root.syntax()) + .expect("To format the JSON report") + .print() + .expect("To print the JSON report"); + + console_reporter_writer.log(markup! { + {formatted.as_code()} + }); + } else { + let code = root.to_string(); + console_reporter_writer.log(markup! { + {code} + }); + } + } + CliReporterKind::GitHub => { + let reporter = GithubReporter { + diagnostics_payload: &diagnostics_payload, + execution, + verbose: cli_options.verbose, + working_directory: fs.working_directory().clone(), + }; + if cli_reporter.is_file_report() { + reporter.write(file_reporter_writer, &mut GithubReporterVisitor)?; + } else { + reporter.write(&mut console_reporter_writer, &mut GithubReporterVisitor)?; + } + } + CliReporterKind::GitLab => { + let reporter = GitLabReporter { + diagnostics_payload: &diagnostics_payload, + execution, + verbose: cli_options.verbose, + working_directory: fs.working_directory().clone(), + }; + if cli_reporter.is_file_report() { + reporter.write( + file_reporter_writer, + &mut GitLabReporterVisitor::new(fs.working_directory()), + )?; + } else { + reporter.write( + &mut console_reporter_writer, + &mut GitLabReporterVisitor::new(fs.working_directory()), + )?; + } + } + CliReporterKind::Junit => { + let reporter = JunitReporter { + summary, + diagnostics_payload: &diagnostics_payload, + execution, + verbose: cli_options.verbose, + working_directory: fs.working_directory().clone(), + }; + + if cli_reporter.is_file_report() { + reporter.write(file_reporter_writer, &mut JunitReporterVisitor::new())?; + } else { + reporter.write( + &mut console_reporter_writer, + &mut JunitReporterVisitor::new(), + )?; + } + } + CliReporterKind::Checkstyle => { + let reporter = CheckstyleReporter { + summary, + diagnostics_payload: &diagnostics_payload, + execution, + verbose: cli_options.verbose, + working_directory: fs.working_directory().clone(), + }; + if cli_reporter.is_file_report() { + reporter.write( + file_reporter_writer, + &mut crate::reporter::checkstyle::CheckstyleReporterVisitor, + )?; + } else { + reporter.write( + &mut console_reporter_writer, + &mut crate::reporter::checkstyle::CheckstyleReporterVisitor, + )?; + } + } + CliReporterKind::RdJson => { + let reporter = RdJsonReporter { + diagnostics_payload: &diagnostics_payload, + execution, + verbose: cli_options.verbose, + working_directory: fs.working_directory().clone(), + }; + if cli_reporter.is_file_report() { + reporter.write(file_reporter_writer, &mut RdJsonReporterVisitor)?; + } else { + reporter.write(&mut console_reporter_writer, &mut RdJsonReporterVisitor)?; + } + } + CliReporterKind::Sarif => { + let reporter = SarifReporter { + diagnostics_payload: &diagnostics_payload, + execution, + verbose: cli_options.verbose, + working_directory: fs.working_directory().clone(), + }; + + if cli_reporter.is_file_report() { + reporter.write(file_reporter_writer, &mut SarifReporterVisitor::new())?; + } else { + reporter.write( + &mut console_reporter_writer, + &mut SarifReporterVisitor::new(), + )?; + } + } + } -// impl Default for ReportMode { -// fn default() -> Self { -// Self::Terminal { -// with_summary: false, -// } -// } -// } -// -// impl From<&CliReporterKind> for ReportMode { -// fn from(value: &CliReporterKind) -> Self { -// match value { -// CliReporterKind::Default => Self::Terminal { -// with_summary: false, -// }, -// CliReporterKind::Summary => Self::Terminal { with_summary: true }, -// CliReporterKind::Json => Self::Json { pretty: false }, -// CliReporterKind::JsonPretty => Self::Json { pretty: true }, -// CliReporterKind::GitHub => Self::GitHub, -// CliReporterKind::Junit => Self::Junit, -// CliReporterKind::GitLab => Self::GitLab {}, -// CliReporterKind::Checkstyle => Self::Checkstyle, -// CliReporterKind::RdJson => Self::RdJson, -// CliReporterKind::Sarif => Self::Sarif, -// } -// } -// } + if let Some(destination) = cli_reporter.destination.as_deref() + && let Some(output) = file_reporter_writer.dump() + { + let open_options = OpenOptions::default().write(true).create(true); + let mut file = match fs.open_with_options(destination, open_options) { + Ok(file) => file, + Err(err) => { + let diagnostics = CliDiagnostic::from(err); + console_reporter_writer.error(markup! { + {PrintDiagnostic::simple(&diagnostics)} + }); + return Ok(()); + } + }; + + let result = file.set_content(output.as_bytes()); + if let Err(err) = result { + let diagnostics = CliDiagnostic::from(err); + console_reporter_writer.error(markup! { + {PrintDiagnostic::simple(&diagnostics)} + }) + } + + file_reporter_writer.clear(); + } + Ok(()) +} diff --git a/crates/biome_cli/src/runner/mod.rs b/crates/biome_cli/src/runner/mod.rs index 5b6119b93134..cd1f3730a1c9 100644 --- a/crates/biome_cli/src/runner/mod.rs +++ b/crates/biome_cli/src/runner/mod.rs @@ -318,7 +318,6 @@ pub(crate) trait CommandRunner { execution: execution.as_ref(), fs, console, - workspace, scan_duration: duration, crawler_output: output, paths, diff --git a/crates/biome_cli/tests/cases/help.rs b/crates/biome_cli/tests/cases/help.rs new file mode 100644 index 000000000000..ad04ab6b6c33 --- /dev/null +++ b/crates/biome_cli/tests/cases/help.rs @@ -0,0 +1,214 @@ +use crate::run_cli; +use crate::snap_test::{SnapshotPayload, assert_cli_snapshot}; +use biome_console::BufferConsole; +use biome_fs::MemoryFileSystem; +use bpaf::Args; +#[test] +fn unknown_command() { + let mut console = BufferConsole::default(); + let fs = MemoryFileSystem::default(); + + let (_, result) = run_cli( + fs, + &mut console, + Args::from(["unknown", "--help"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); +} + +#[test] +fn check_help() { + let fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let (fs, result) = run_cli(fs, &mut console, Args::from(["check", "--help"].as_slice())); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "check_help", + fs, + console, + result, + )); +} + +#[test] +fn ci_help() { + let fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let (fs, result) = run_cli(fs, &mut console, Args::from(["ci", "--help"].as_slice())); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "ci_help", + fs, + console, + result, + )); +} + +#[test] +fn explain_help() { + let fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let (fs, result) = run_cli( + fs, + &mut console, + Args::from(["explain", "--help"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "explain_help", + fs, + console, + result, + )); +} + +#[test] +fn format_help() { + let fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let (fs, result) = run_cli( + fs, + &mut console, + Args::from(["format", "--help"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "format_help", + fs, + console, + result, + )); +} + +#[test] +fn init_help() { + let fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let (fs, result) = run_cli(fs, &mut console, Args::from(["init", "--help"].as_slice())); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "init_help", + fs, + console, + result, + )); +} + +#[test] +fn lint_help() { + let fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let (fs, result) = run_cli(fs, &mut console, Args::from(["lint", "--help"].as_slice())); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "lint_help", + fs, + console, + result, + )); +} + +#[test] +fn lsp_proxy_help() { + let fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let (fs, result) = run_cli( + fs, + &mut console, + Args::from(["lsp-proxy", "--help"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "lsp_proxy_help", + fs, + console, + result, + )); +} + +#[test] +fn migrate_help() { + let fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let (fs, result) = run_cli( + fs, + &mut console, + Args::from(["migrate", "--help"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "migrate_help", + fs, + console, + result, + )); +} + +#[test] +fn rage_help() { + let fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let (fs, result) = run_cli(fs, &mut console, Args::from(["rage", "--help"].as_slice())); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "rage_help", + fs, + console, + result, + )); +} + +#[test] +fn start_help() { + let fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let (fs, result) = run_cli(fs, &mut console, Args::from(["start", "--help"].as_slice())); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "start_help", + fs, + console, + result, + )); +} diff --git a/crates/biome_cli/tests/cases/mod.rs b/crates/biome_cli/tests/cases/mod.rs index e0f45961440f..7b6b71cb5c59 100644 --- a/crates/biome_cli/tests/cases/mod.rs +++ b/crates/biome_cli/tests/cases/mod.rs @@ -16,6 +16,7 @@ mod handle_astro_files; mod handle_css_files; mod handle_svelte_files; mod handle_vue_files; +mod help; mod html; mod included_files; mod indent_script_and_style; diff --git a/crates/biome_cli/tests/commands/check.rs b/crates/biome_cli/tests/commands/check.rs index f9d5eb08c32a..aa40310e6d9a 100644 --- a/crates/biome_cli/tests/commands/check.rs +++ b/crates/biome_cli/tests/commands/check.rs @@ -56,24 +56,6 @@ const UPGRADE_SEVERITY_CODE: &str = r#"if(!cond) { exprA(); } else { exprB() }"# const NURSERY_UNSTABLE: &str = r#"if(a = b) {}"#; -#[test] -fn check_help() { - let fs = MemoryFileSystem::default(); - let mut console = BufferConsole::default(); - - let (fs, result) = run_cli(fs, &mut console, Args::from(["check", "--help"].as_slice())); - - assert!(result.is_ok(), "run_cli returned {result:?}"); - - assert_cli_snapshot(SnapshotPayload::new( - module_path!(), - "check_help", - fs, - console, - result, - )); -} - #[test] fn ok() { let fs = MemoryFileSystem::default(); diff --git a/crates/biome_cli/tests/commands/ci.rs b/crates/biome_cli/tests/commands/ci.rs index 60cda82dec17..82fc0bd59dc7 100644 --- a/crates/biome_cli/tests/commands/ci.rs +++ b/crates/biome_cli/tests/commands/ci.rs @@ -30,24 +30,6 @@ const CI_CONFIGURATION: &str = r#" } "#; -#[test] -fn ci_help() { - let fs = MemoryFileSystem::default(); - let mut console = BufferConsole::default(); - - let (fs, result) = run_cli(fs, &mut console, Args::from(["ci", "--help"].as_slice())); - - assert!(result.is_ok(), "run_cli returned {result:?}"); - - assert_cli_snapshot(SnapshotPayload::new( - module_path!(), - "ci_help", - fs, - console, - result, - )); -} - #[test] fn ok() { let fs = MemoryFileSystem::default(); diff --git a/crates/biome_cli/tests/commands/explain.rs b/crates/biome_cli/tests/commands/explain.rs index d3e42155eb3e..027c626b7016 100644 --- a/crates/biome_cli/tests/commands/explain.rs +++ b/crates/biome_cli/tests/commands/explain.rs @@ -5,28 +5,6 @@ use crate::{assert_cli_snapshot, run_cli}; use biome_console::BufferConsole; use biome_fs::MemoryFileSystem; -#[test] -fn explain_help() { - let fs = MemoryFileSystem::default(); - let mut console = BufferConsole::default(); - - let (fs, result) = run_cli( - fs, - &mut console, - Args::from(["explain", "--help"].as_slice()), - ); - - assert!(result.is_ok(), "run_cli returned {result:?}"); - - assert_cli_snapshot(SnapshotPayload::new( - module_path!(), - "explain_help", - fs, - console, - result, - )); -} - #[test] fn explain_valid_rule() { let fs = MemoryFileSystem::default(); diff --git a/crates/biome_cli/tests/commands/format.rs b/crates/biome_cli/tests/commands/format.rs index 51d821706bcd..994c47a0580f 100644 --- a/crates/biome_cli/tests/commands/format.rs +++ b/crates/biome_cli/tests/commands/format.rs @@ -198,28 +198,6 @@ const CUSTOM_CONFIGURATION_AFTER: &str = "function f() { } "; -#[test] -fn format_help() { - let fs = MemoryFileSystem::default(); - let mut console = BufferConsole::default(); - - let (fs, result) = run_cli( - fs, - &mut console, - Args::from(["format", "--help"].as_slice()), - ); - - assert!(result.is_ok(), "run_cli returned {result:?}"); - - assert_cli_snapshot(SnapshotPayload::new( - module_path!(), - "format_help", - fs, - console, - result, - )); -} - #[test] fn print() { let fs = MemoryFileSystem::default(); diff --git a/crates/biome_cli/tests/commands/init.rs b/crates/biome_cli/tests/commands/init.rs index 3e3ad81ec205..34ad2ccc7f5d 100644 --- a/crates/biome_cli/tests/commands/init.rs +++ b/crates/biome_cli/tests/commands/init.rs @@ -5,24 +5,6 @@ use biome_fs::MemoryFileSystem; use bpaf::Args; use camino::Utf8Path; -#[test] -fn init_help() { - let fs = MemoryFileSystem::default(); - let mut console = BufferConsole::default(); - - let (fs, result) = run_cli(fs, &mut console, Args::from(["init", "--help"].as_slice())); - - assert!(result.is_ok(), "run_cli returned {result:?}"); - - assert_cli_snapshot(SnapshotPayload::new( - module_path!(), - "init_help", - fs, - console, - result, - )); -} - #[test] fn creates_config_file() { let fs = MemoryFileSystem::default(); diff --git a/crates/biome_cli/tests/commands/lint.rs b/crates/biome_cli/tests/commands/lint.rs index cd7205495063..d2b075169dcb 100644 --- a/crates/biome_cli/tests/commands/lint.rs +++ b/crates/biome_cli/tests/commands/lint.rs @@ -54,24 +54,6 @@ const UPGRADE_SEVERITY_CODE: &str = r#"if(!cond) { exprA(); } else { exprB() }"# const NURSERY_UNSTABLE: &str = r#"if(a = b) {}"#; -#[test] -fn lint_help() { - let fs = MemoryFileSystem::default(); - let mut console = BufferConsole::default(); - - let (fs, result) = run_cli(fs, &mut console, Args::from(["lint", "--help"].as_slice())); - - assert!(result.is_ok(), "run_cli returned {result:?}"); - - assert_cli_snapshot(SnapshotPayload::new( - module_path!(), - "lint_help", - fs, - console, - result, - )); -} - #[test] fn ok() { let fs = MemoryFileSystem::default(); diff --git a/crates/biome_cli/tests/commands/lsp_proxy.rs b/crates/biome_cli/tests/commands/lsp_proxy.rs deleted file mode 100644 index d04add934ea8..000000000000 --- a/crates/biome_cli/tests/commands/lsp_proxy.rs +++ /dev/null @@ -1,27 +0,0 @@ -use crate::run_cli; -use crate::snap_test::{SnapshotPayload, assert_cli_snapshot}; -use biome_console::BufferConsole; -use biome_fs::MemoryFileSystem; -use bpaf::Args; - -#[test] -fn lsp_proxy_help() { - let fs = MemoryFileSystem::default(); - let mut console = BufferConsole::default(); - - let (fs, result) = run_cli( - fs, - &mut console, - Args::from(["lsp-proxy", "--help"].as_slice()), - ); - - assert!(result.is_ok(), "run_cli returned {result:?}"); - - assert_cli_snapshot(SnapshotPayload::new( - module_path!(), - "lsp_proxy_help", - fs, - console, - result, - )); -} diff --git a/crates/biome_cli/tests/commands/migrate.rs b/crates/biome_cli/tests/commands/migrate.rs index b9e830a67344..70dbf0d6ebdf 100644 --- a/crates/biome_cli/tests/commands/migrate.rs +++ b/crates/biome_cli/tests/commands/migrate.rs @@ -5,28 +5,6 @@ use biome_fs::{MemoryFileSystem, TemporaryFs}; use bpaf::Args; use camino::Utf8Path; -#[test] -fn migrate_help() { - let fs = MemoryFileSystem::default(); - let mut console = BufferConsole::default(); - - let (fs, result) = run_cli( - fs, - &mut console, - Args::from(["migrate", "--help"].as_slice()), - ); - - assert!(result.is_ok(), "run_cli returned {result:?}"); - - assert_cli_snapshot(SnapshotPayload::new( - module_path!(), - "migrate_help", - fs, - console, - result, - )); -} - #[test] fn migrate_config_up_to_date() { let fs = MemoryFileSystem::default(); diff --git a/crates/biome_cli/tests/commands/mod.rs b/crates/biome_cli/tests/commands/mod.rs index e7d09fc8d4ef..bb03c672e4e7 100644 --- a/crates/biome_cli/tests/commands/mod.rs +++ b/crates/biome_cli/tests/commands/mod.rs @@ -4,11 +4,9 @@ mod explain; mod format; mod init; mod lint; -mod lsp_proxy; mod migrate; mod migrate_eslint; mod migrate_prettier; mod rage; mod search; -mod start; mod version; diff --git a/crates/biome_cli/tests/commands/rage.rs b/crates/biome_cli/tests/commands/rage.rs index 5d190cdff6c4..3d6f565a4484 100644 --- a/crates/biome_cli/tests/commands/rage.rs +++ b/crates/biome_cli/tests/commands/rage.rs @@ -1,32 +1,15 @@ use crate::run_cli; -use crate::snap_test::{CliSnapshot, SnapshotPayload, assert_cli_snapshot}; +use crate::snap_test::{CliSnapshot, SnapshotPayload}; use biome_cli::CliDiagnostic; use biome_console::{BufferConsole, Console}; use biome_fs::MemoryFileSystem; use bpaf::Args; use camino::{Utf8Path, Utf8PathBuf}; -use std::sync::{Mutex, MutexGuard}; +use serial_test::serial; use std::{env, fs}; #[test] -fn rage_help() { - let fs = MemoryFileSystem::default(); - let mut console = BufferConsole::default(); - - let (fs, result) = run_cli(fs, &mut console, Args::from(["rage", "--help"].as_slice())); - - assert!(result.is_ok(), "run_cli returned {result:?}"); - - assert_cli_snapshot(SnapshotPayload::new( - module_path!(), - "rage_help", - fs, - console, - result, - )); -} - -#[test] +#[serial] fn ok() { let fs = MemoryFileSystem::default(); let mut console = BufferConsole::default(); @@ -45,6 +28,7 @@ fn ok() { } #[test] +#[serial] fn with_configuration() { let fs = MemoryFileSystem::default(); let mut console = BufferConsole::default(); @@ -71,6 +55,7 @@ fn with_configuration() { } #[test] +#[serial] fn with_no_configuration() { let fs = MemoryFileSystem::default(); let mut console = BufferConsole::default(); @@ -89,6 +74,7 @@ fn with_no_configuration() { } #[test] +#[serial] fn with_jsonc_configuration() { let fs = MemoryFileSystem::default(); let mut console = BufferConsole::default(); @@ -116,6 +102,7 @@ fn with_jsonc_configuration() { } #[test] +#[serial] fn with_malformed_configuration() { let fs = MemoryFileSystem::default(); let mut console = BufferConsole::default(); @@ -142,6 +129,7 @@ fn with_malformed_configuration() { } #[test] +#[serial] fn with_formatter_configuration() { let fs = MemoryFileSystem::default(); let mut console = BufferConsole::default(); @@ -209,6 +197,7 @@ fn with_formatter_configuration() { } #[test] +#[serial] fn with_linter_configuration() { let fs = MemoryFileSystem::default(); let mut console = BufferConsole::default(); @@ -302,25 +291,18 @@ fn assert_rage_snapshot(payload: SnapshotPayload<'_>) { }); } -/// Mutex to guarantee that the `rage` tests run sequentially. Necessary to avoid race conditions -/// when reading the server logs. -static RAGE_GUARD: Mutex<()> = Mutex::new(()); - /// Mocks out the directory from which `rage` reads the server logs. Ensures that the test directory /// gets removed at the end of the test. struct TestLogDir { path: Utf8PathBuf, - _guard: MutexGuard<'static, ()>, } impl TestLogDir { fn new(name: &str) -> Self { - let guard = RAGE_GUARD.lock().unwrap(); let path = env::temp_dir().join(name); Self { path: Utf8PathBuf::from_path_buf(path).unwrap(), - _guard: guard, } } } diff --git a/crates/biome_cli/tests/commands/start.rs b/crates/biome_cli/tests/commands/start.rs deleted file mode 100644 index c809f95e1233..000000000000 --- a/crates/biome_cli/tests/commands/start.rs +++ /dev/null @@ -1,23 +0,0 @@ -use crate::run_cli; -use crate::snap_test::{SnapshotPayload, assert_cli_snapshot}; -use biome_console::BufferConsole; -use biome_fs::MemoryFileSystem; -use bpaf::Args; - -#[test] -fn start_help() { - let fs = MemoryFileSystem::default(); - let mut console = BufferConsole::default(); - - let (fs, result) = run_cli(fs, &mut console, Args::from(["start", "--help"].as_slice())); - - assert!(result.is_ok(), "run_cli returned {result:?}"); - - assert_cli_snapshot(SnapshotPayload::new( - module_path!(), - "start_help", - fs, - console, - result, - )); -} diff --git a/crates/biome_cli/tests/main.rs b/crates/biome_cli/tests/main.rs index 7064a9925d1c..6e883db3a81f 100644 --- a/crates/biome_cli/tests/main.rs +++ b/crates/biome_cli/tests/main.rs @@ -27,25 +27,6 @@ return { something } } "#; -mod help { - use super::*; - use bpaf::Args; - - #[test] - fn unknown_command() { - let mut console = BufferConsole::default(); - let fs = MemoryFileSystem::default(); - - let (_, result) = run_cli( - fs, - &mut console, - Args::from(["unknown", "--help"].as_slice()), - ); - - assert!(result.is_ok(), "run_cli returned {result:?}"); - } -} - mod main { use super::*; use bpaf::Args; diff --git a/crates/biome_cli/tests/snapshots/main_commands_check/check_help.snap b/crates/biome_cli/tests/snapshots/main_cases_help/check_help.snap similarity index 100% rename from crates/biome_cli/tests/snapshots/main_commands_check/check_help.snap rename to crates/biome_cli/tests/snapshots/main_cases_help/check_help.snap diff --git a/crates/biome_cli/tests/snapshots/main_commands_ci/ci_help.snap b/crates/biome_cli/tests/snapshots/main_cases_help/ci_help.snap similarity index 100% rename from crates/biome_cli/tests/snapshots/main_commands_ci/ci_help.snap rename to crates/biome_cli/tests/snapshots/main_cases_help/ci_help.snap diff --git a/crates/biome_cli/tests/snapshots/main_commands_explain/explain_help.snap b/crates/biome_cli/tests/snapshots/main_cases_help/explain_help.snap similarity index 100% rename from crates/biome_cli/tests/snapshots/main_commands_explain/explain_help.snap rename to crates/biome_cli/tests/snapshots/main_cases_help/explain_help.snap diff --git a/crates/biome_cli/tests/snapshots/main_commands_format/format_help.snap b/crates/biome_cli/tests/snapshots/main_cases_help/format_help.snap similarity index 100% rename from crates/biome_cli/tests/snapshots/main_commands_format/format_help.snap rename to crates/biome_cli/tests/snapshots/main_cases_help/format_help.snap diff --git a/crates/biome_cli/tests/snapshots/main_commands_init/init_help.snap b/crates/biome_cli/tests/snapshots/main_cases_help/init_help.snap similarity index 100% rename from crates/biome_cli/tests/snapshots/main_commands_init/init_help.snap rename to crates/biome_cli/tests/snapshots/main_cases_help/init_help.snap diff --git a/crates/biome_cli/tests/snapshots/main_commands_lint/lint_help.snap b/crates/biome_cli/tests/snapshots/main_cases_help/lint_help.snap similarity index 100% rename from crates/biome_cli/tests/snapshots/main_commands_lint/lint_help.snap rename to crates/biome_cli/tests/snapshots/main_cases_help/lint_help.snap diff --git a/crates/biome_cli/tests/snapshots/main_commands_lsp_proxy/lsp_proxy_help.snap b/crates/biome_cli/tests/snapshots/main_cases_help/lsp_proxy_help.snap similarity index 100% rename from crates/biome_cli/tests/snapshots/main_commands_lsp_proxy/lsp_proxy_help.snap rename to crates/biome_cli/tests/snapshots/main_cases_help/lsp_proxy_help.snap diff --git a/crates/biome_cli/tests/snapshots/main_commands_migrate/migrate_help.snap b/crates/biome_cli/tests/snapshots/main_cases_help/migrate_help.snap similarity index 100% rename from crates/biome_cli/tests/snapshots/main_commands_migrate/migrate_help.snap rename to crates/biome_cli/tests/snapshots/main_cases_help/migrate_help.snap diff --git a/crates/biome_cli/tests/snapshots/main_commands_rage/rage_help.snap b/crates/biome_cli/tests/snapshots/main_cases_help/rage_help.snap similarity index 100% rename from crates/biome_cli/tests/snapshots/main_commands_rage/rage_help.snap rename to crates/biome_cli/tests/snapshots/main_cases_help/rage_help.snap diff --git a/crates/biome_cli/tests/snapshots/main_commands_start/start_help.snap b/crates/biome_cli/tests/snapshots/main_cases_help/start_help.snap similarity index 100% rename from crates/biome_cli/tests/snapshots/main_commands_start/start_help.snap rename to crates/biome_cli/tests/snapshots/main_cases_help/start_help.snap From 4164ae7944f97573678e2162afbcadf74327c2ee Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Tue, 17 Feb 2026 09:34:06 +0000 Subject: [PATCH 2/5] fix(cli): use github reporter in github actions env --- crates/biome_cli/src/commands/ci.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/biome_cli/src/commands/ci.rs b/crates/biome_cli/src/commands/ci.rs index 0be2fe39fce4..be98372de0e6 100644 --- a/crates/biome_cli/src/commands/ci.rs +++ b/crates/biome_cli/src/commands/ci.rs @@ -152,10 +152,16 @@ impl TraversalCommand for CiCommandPayload { _console: &mut dyn Console, _workspace: &dyn Workspace, ) -> Result, CliDiagnostic> { + // This is funny, but we need to disable this at the moment, otherwise + // all our tests that run `biome ci` IN OUR CI, will get false positives. Call it CI-ception + let is_github = if cfg!(debug_assertions) { + false + } else { // Ref: https://docs.github.com/actions/learn-github-actions/variables#default-environment-variables - let is_github = std::env::var("GITHUB_ACTIONS") - .ok() - .is_some_and(|value| value == "true"); + std::env::var("GITHUB_ACTIONS") + .ok() + .is_some_and(|value| value == "true") + }; Ok(Box::new(CiExecution { environment: if is_github { From 80e0f4d41f4ae566f4b65e88f8b017ed81801ac7 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Tue, 17 Feb 2026 09:53:33 +0000 Subject: [PATCH 3/5] fix CI --- crates/biome_cli/src/commands/ci.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/biome_cli/src/commands/ci.rs b/crates/biome_cli/src/commands/ci.rs index be98372de0e6..666af29e7680 100644 --- a/crates/biome_cli/src/commands/ci.rs +++ b/crates/biome_cli/src/commands/ci.rs @@ -157,7 +157,7 @@ impl TraversalCommand for CiCommandPayload { let is_github = if cfg!(debug_assertions) { false } else { - // Ref: https://docs.github.com/actions/learn-github-actions/variables#default-environment-variables + // Ref: https://docs.github.com/actions/learn-github-actions/variables#default-environment-variables std::env::var("GITHUB_ACTIONS") .ok() .is_some_and(|value| value == "true") From 816d4642894ea9b23437fc5da4c44840db865a49 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Tue, 17 Feb 2026 09:55:05 +0000 Subject: [PATCH 4/5] linting --- Cargo.lock | 10 ---------- crates/biome_cli/Cargo.toml | 1 - .../src/runner/impls/finalizers/default.rs | 20 +++++++++---------- 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c6ab38dbae48..6e7d1a42f553 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -227,7 +227,6 @@ dependencies = [ "serde_json", "serial_test", "smallvec", - "temp-env", "terminal_size 0.4.3", "tikv-jemallocator", "tokio", @@ -5211,15 +5210,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "591ef38edfb78ca4771ee32cf494cb8771944bee237a9b91fc9c1424ac4b777b" -[[package]] -name = "temp-env" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96374855068f47402c3121c6eed88d29cb1de8f3ab27090e273e420bdabcf050" -dependencies = [ - "parking_lot", -] - [[package]] name = "tempfile" version = "3.23.0" diff --git a/crates/biome_cli/Cargo.toml b/crates/biome_cli/Cargo.toml index 8887856fa6d2..73d6589827ad 100644 --- a/crates/biome_cli/Cargo.toml +++ b/crates/biome_cli/Cargo.toml @@ -89,7 +89,6 @@ directories = { workspace = true } insta = { workspace = true } regex = { workspace = true } serial_test = "3.3.1" -temp-env = "0.3.6" tokio = { workspace = true, features = ["io-util"] } [target.'cfg(all(target_family="unix", not(all(target_arch = "aarch64", target_env = "musl"))))'.dependencies] diff --git a/crates/biome_cli/src/runner/impls/finalizers/default.rs b/crates/biome_cli/src/runner/impls/finalizers/default.rs index 7177a3188807..95bc76a4e026 100644 --- a/crates/biome_cli/src/runner/impls/finalizers/default.rs +++ b/crates/biome_cli/src/runner/impls/finalizers/default.rs @@ -109,7 +109,7 @@ impl Finalizer for DefaultFinalizer { let mut console_reporter_writer = ConsoleReporterWriter(console); let reporter = ConsoleReporter { summary, - diagnostics_payload: &diagnostics_payload, + diagnostics_payload, execution, verbose: cli_options.verbose, working_directory: fs.working_directory().clone(), @@ -167,7 +167,7 @@ fn print_to_reporter<'a, 'b>( CliReporterKind::Default => { let reporter = ConsoleReporter { summary, - diagnostics_payload: &diagnostics_payload, + diagnostics_payload, execution, verbose: cli_options.verbose, working_directory: fs.working_directory().clone(), @@ -182,7 +182,7 @@ fn print_to_reporter<'a, 'b>( CliReporterKind::Summary => { let reporter = SummaryReporter { summary, - diagnostics_payload: &diagnostics_payload, + diagnostics_payload, execution, verbose: cli_options.verbose, working_directory: fs.working_directory().clone(), @@ -200,7 +200,7 @@ fn print_to_reporter<'a, 'b>( }); let reporter = JsonReporter { summary, - diagnostics_payload: &diagnostics_payload, + diagnostics_payload, execution, verbose: cli_options.verbose, working_directory: fs.working_directory().clone(), @@ -227,7 +227,7 @@ fn print_to_reporter<'a, 'b>( } CliReporterKind::GitHub => { let reporter = GithubReporter { - diagnostics_payload: &diagnostics_payload, + diagnostics_payload, execution, verbose: cli_options.verbose, working_directory: fs.working_directory().clone(), @@ -240,7 +240,7 @@ fn print_to_reporter<'a, 'b>( } CliReporterKind::GitLab => { let reporter = GitLabReporter { - diagnostics_payload: &diagnostics_payload, + diagnostics_payload, execution, verbose: cli_options.verbose, working_directory: fs.working_directory().clone(), @@ -260,7 +260,7 @@ fn print_to_reporter<'a, 'b>( CliReporterKind::Junit => { let reporter = JunitReporter { summary, - diagnostics_payload: &diagnostics_payload, + diagnostics_payload, execution, verbose: cli_options.verbose, working_directory: fs.working_directory().clone(), @@ -278,7 +278,7 @@ fn print_to_reporter<'a, 'b>( CliReporterKind::Checkstyle => { let reporter = CheckstyleReporter { summary, - diagnostics_payload: &diagnostics_payload, + diagnostics_payload, execution, verbose: cli_options.verbose, working_directory: fs.working_directory().clone(), @@ -297,7 +297,7 @@ fn print_to_reporter<'a, 'b>( } CliReporterKind::RdJson => { let reporter = RdJsonReporter { - diagnostics_payload: &diagnostics_payload, + diagnostics_payload, execution, verbose: cli_options.verbose, working_directory: fs.working_directory().clone(), @@ -310,7 +310,7 @@ fn print_to_reporter<'a, 'b>( } CliReporterKind::Sarif => { let reporter = SarifReporter { - diagnostics_payload: &diagnostics_payload, + diagnostics_payload, execution, verbose: cli_options.verbose, working_directory: fs.working_directory().clone(), From 941f0e0ed32e45260c4fabadf9115d09f8138cb7 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Tue, 17 Feb 2026 10:21:47 +0000 Subject: [PATCH 5/5] fix linting and compilation issue --- .../src/runner/impls/finalizers/default.rs | 46 ++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/crates/biome_cli/src/runner/impls/finalizers/default.rs b/crates/biome_cli/src/runner/impls/finalizers/default.rs index 95bc76a4e026..6615935c6360 100644 --- a/crates/biome_cli/src/runner/impls/finalizers/default.rs +++ b/crates/biome_cli/src/runner/impls/finalizers/default.rs @@ -73,43 +73,43 @@ impl Finalizer for DefaultFinalizer { if !cli_options.cli_reporter.is_empty() { for cli_reporter in &cli_options.cli_reporter { - print_to_reporter( + print_to_reporter(PrintToReporter { cli_reporter, cli_options, - &diagnostics_payload, + diagnostics_payload: &diagnostics_payload, summary, - evaluated_paths.clone(), - &mut file_reporter_writer, + evaluated_paths: evaluated_paths.clone(), + file_reporter_writer: &mut file_reporter_writer, console, fs, execution, - )?; + })?; } } else { if let Some(reporter) = execution.environment_to_reporter() { let contains_current_reporter = cli_options .cli_reporter .iter() - .any(|r| &r.kind == &reporter.kind); + .any(|r| r.kind == reporter.kind); if !contains_current_reporter { - print_to_reporter( - &reporter, + print_to_reporter(PrintToReporter { + cli_reporter: &reporter, cli_options, - &diagnostics_payload, + diagnostics_payload: &diagnostics_payload, summary, - evaluated_paths.clone(), - &mut file_reporter_writer, + evaluated_paths: evaluated_paths.clone(), + file_reporter_writer: &mut file_reporter_writer, console, fs, execution, - )?; + })?; } } let mut console_reporter_writer = ConsoleReporterWriter(console); let reporter = ConsoleReporter { summary, - diagnostics_payload, + diagnostics_payload: &diagnostics_payload, execution, verbose: cli_options.verbose, working_directory: fs.working_directory().clone(), @@ -151,17 +151,31 @@ impl Finalizer for () { } } -fn print_to_reporter<'a, 'b>( +struct PrintToReporter<'a> { cli_reporter: &'a CliReporter, cli_options: &'a CliOptions, diagnostics_payload: &'a DiagnosticsPayload, summary: TraversalSummary, evaluated_paths: BTreeSet, - file_reporter_writer: &'b mut FileReporterWriter, + file_reporter_writer: &'a mut FileReporterWriter, console: &'a mut dyn Console, fs: &'a dyn FileSystem, execution: &'a dyn Execution, -) -> Result<(), CliDiagnostic> { +} + +fn print_to_reporter(params: PrintToReporter) -> Result<(), CliDiagnostic> { + let PrintToReporter { + cli_reporter, + cli_options, + diagnostics_payload, + summary, + evaluated_paths, + file_reporter_writer, + console, + fs, + execution, + } = params; + let mut console_reporter_writer = ConsoleReporterWriter(console); match cli_reporter.kind { CliReporterKind::Default => {