From 1d2eaca6b4b836c39f0c4090f08856daa5d08d6e Mon Sep 17 00:00:00 2001 From: camc314 <18101008+camc314@users.noreply.github.com> Date: Tue, 8 Jul 2025 17:08:14 +0000 Subject: [PATCH] refactor(oxlint2): introduce `force_test_reporter` feature for consistent graphical outputs (#12133) --- apps/oxlint/Cargo.toml | 1 + apps/oxlint/src/lint.rs | 6 +++++- apps/oxlint/src/output_formatter/default.rs | 6 +++--- crates/oxc_linter/Cargo.toml | 1 + napi/oxlint2/Cargo.toml | 1 + napi/oxlint2/package.json | 2 +- 6 files changed, 12 insertions(+), 5 deletions(-) diff --git a/apps/oxlint/Cargo.toml b/apps/oxlint/Cargo.toml index 6719e3570181b..5a4cc9c84dc7f 100644 --- a/apps/oxlint/Cargo.toml +++ b/apps/oxlint/Cargo.toml @@ -62,3 +62,4 @@ default = [] allocator = ["dep:mimalloc-safe"] oxlint2 = ["oxc_linter/oxlint2"] disable_oxlint2 = ["oxc_linter/disable_oxlint2"] +force_test_reporter = ["oxc_linter/force_test_reporter"] diff --git a/apps/oxlint/src/lint.rs b/apps/oxlint/src/lint.rs index 469db72120826..4058b8f1a4c07 100644 --- a/apps/oxlint/src/lint.rs +++ b/apps/oxlint/src/lint.rs @@ -172,7 +172,11 @@ impl Runner for LintRunner { let paths = walker.paths(); let number_of_files = paths.len(); - let handler = GraphicalReportHandler::new(); + let handler = if cfg!(any(test, feature = "force_test_reporter")) { + GraphicalReportHandler::new_themed(miette::GraphicalTheme::none()) + } else { + GraphicalReportHandler::new() + }; let search_for_nested_configs = !disable_nested_config && // If the `--config` option is explicitly passed, we should not search for nested config files diff --git a/apps/oxlint/src/output_formatter/default.rs b/apps/oxlint/src/output_formatter/default.rs index 6e4c6ac77d3cb..551c7c3aece92 100644 --- a/apps/oxlint/src/output_formatter/default.rs +++ b/apps/oxlint/src/output_formatter/default.rs @@ -40,12 +40,12 @@ impl InternalFormatter for DefaultOutputFormatter { } } - #[cfg(not(test))] + #[cfg(not(any(test, feature = "force_test_reporter")))] fn get_diagnostic_reporter(&self) -> Box { Box::new(GraphicalReporter::default()) } - #[cfg(test)] + #[cfg(any(test, feature = "force_test_reporter"))] fn get_diagnostic_reporter(&self) -> Box { use crate::output_formatter::default::test_implementation::GraphicalReporterTester; @@ -113,7 +113,7 @@ fn get_diagnostic_result_output(result: &DiagnosticResult) -> String { output } -#[cfg(test)] +#[cfg(any(test, feature = "force_test_reporter"))] mod test_implementation { use oxc_diagnostics::{ Error, GraphicalReportHandler, GraphicalTheme, diff --git a/crates/oxc_linter/Cargo.toml b/crates/oxc_linter/Cargo.toml index eed1e62183ba7..bb4265e17ca9e 100644 --- a/crates/oxc_linter/Cargo.toml +++ b/crates/oxc_linter/Cargo.toml @@ -19,6 +19,7 @@ ruledocs = ["oxc_macros/ruledocs"] # Enables the `ruledocs` feature for conditio language_server = ["oxc_data_structures/rope"] # For the Runtime to support needed information for the language server oxlint2 = [] disable_oxlint2 = [] +force_test_reporter = [] [lints] workspace = true diff --git a/napi/oxlint2/Cargo.toml b/napi/oxlint2/Cargo.toml index b50e1314aabfc..d6c02e945db31 100644 --- a/napi/oxlint2/Cargo.toml +++ b/napi/oxlint2/Cargo.toml @@ -42,3 +42,4 @@ napi-build = { workspace = true } [features] default = [] +force_test_reporter = ["oxlint/force_test_reporter"] diff --git a/napi/oxlint2/package.json b/napi/oxlint2/package.json index b892bd153b49a..48e1aafee8633 100644 --- a/napi/oxlint2/package.json +++ b/napi/oxlint2/package.json @@ -5,7 +5,7 @@ "type": "module", "scripts": { "build-dev": "napi build --platform --js ./bindings.js --dts ./bindings.d.ts --output-dir src --no-dts-cache --esm", - "build-test": "pnpm run build-dev --release", + "build-test": "pnpm run build-dev --release --features force_test_reporter", "build": "pnpm run build-dev --release", "test": "vitest" },