From 74cdaa04129a4a3b5f33c5277bfd303b98b50719 Mon Sep 17 00:00:00 2001 From: Hideyasu-Ozawa <40753657+Hideyasu-Ozawa@users.noreply.github.com> Date: Sun, 15 Mar 2026 11:41:50 +0000 Subject: [PATCH] fix(oxlint): add summary output to GitHub formatter --- apps/oxlint/src/output_formatter/default.rs | 2 +- apps/oxlint/src/output_formatter/github.rs | 16 +++++++++++++--- ...e-directives disable-directive.js@oxlint.snap | 2 ++ ..._diagnostic_--format=github ok.js@oxlint.snap | 1 + ...c_--format=github parser-error.js@oxlint.snap | 2 ++ ...iagnostic_--format=github test.js@oxlint.snap | 2 ++ 6 files changed, 21 insertions(+), 4 deletions(-) diff --git a/apps/oxlint/src/output_formatter/default.rs b/apps/oxlint/src/output_formatter/default.rs index fe9113f720eb7..35c78e7df3115 100644 --- a/apps/oxlint/src/output_formatter/default.rs +++ b/apps/oxlint/src/output_formatter/default.rs @@ -87,7 +87,7 @@ impl DiagnosticReporter for GraphicalReporter { } } -fn get_diagnostic_result_output(result: &DiagnosticResult) -> String { +pub(super) fn get_diagnostic_result_output(result: &DiagnosticResult) -> String { let mut output = String::new(); if result.warnings_count() + result.errors_count() > 0 { diff --git a/apps/oxlint/src/output_formatter/github.rs b/apps/oxlint/src/output_formatter/github.rs index aa5438faaed4d..112c4a8ff2414 100644 --- a/apps/oxlint/src/output_formatter/github.rs +++ b/apps/oxlint/src/output_formatter/github.rs @@ -5,6 +5,7 @@ use oxc_diagnostics::{ reporter::{DiagnosticReporter, DiagnosticResult, Info}, }; +use super::default::get_diagnostic_result_output; use crate::output_formatter::InternalFormatter; #[derive(Debug)] @@ -21,8 +22,8 @@ impl InternalFormatter for GithubOutputFormatter { struct GithubReporter; impl DiagnosticReporter for GithubReporter { - fn finish(&mut self, _: &DiagnosticResult) -> Option { - None + fn finish(&mut self, result: &DiagnosticResult) -> Option { + Some(get_diagnostic_result_output(result)) } fn render_error(&mut self, error: Error) -> Option { @@ -95,7 +96,16 @@ mod test { let result = reporter.finish(&DiagnosticResult::default()); - assert!(result.is_none()); + assert_eq!(result.unwrap(), "Found 0 warnings and 0 errors.\n"); + } + + #[test] + fn reporter_finish_with_errors() { + let mut reporter = GithubReporter; + + let result = reporter.finish(&DiagnosticResult::new(2, 1, false)); + + assert_eq!(result.unwrap(), "\nFound 2 warnings and 1 error.\n"); } #[test] diff --git a/apps/oxlint/src/snapshots/fixtures__cli__output_formatter_diagnostic_--format=github --report-unused-disable-directives disable-directive.js@oxlint.snap b/apps/oxlint/src/snapshots/fixtures__cli__output_formatter_diagnostic_--format=github --report-unused-disable-directives disable-directive.js@oxlint.snap index 8472737b12bdc..8e806541cab83 100644 --- a/apps/oxlint/src/snapshots/fixtures__cli__output_formatter_diagnostic_--format=github --report-unused-disable-directives disable-directive.js@oxlint.snap +++ b/apps/oxlint/src/snapshots/fixtures__cli__output_formatter_diagnostic_--format=github --report-unused-disable-directives disable-directive.js@oxlint.snap @@ -8,6 +8,8 @@ working directory: fixtures/cli/output_formatter_diagnostic ::warning file=disable-directive.js,line=9,endLine=9,col=3,endColumn=40,title=oxlint::Unused eslint-disable directive (no problems were reported). ::warning file=disable-directive.js,line=12,endLine=12,col=3,endColumn=40,title=oxlint::Unused eslint-disable directive (no problems were reported). ::warning file=disable-directive.js,line=15,endLine=15,col=3,endColumn=47,title=oxlint::Unused eslint-disable directive (no problems were reported). + +Found 3 warnings and 0 errors. ---------- CLI result: LintSucceeded ---------- diff --git a/apps/oxlint/src/snapshots/fixtures__cli__output_formatter_diagnostic_--format=github ok.js@oxlint.snap b/apps/oxlint/src/snapshots/fixtures__cli__output_formatter_diagnostic_--format=github ok.js@oxlint.snap index d937814341576..db4d86c123ef5 100644 --- a/apps/oxlint/src/snapshots/fixtures__cli__output_formatter_diagnostic_--format=github ok.js@oxlint.snap +++ b/apps/oxlint/src/snapshots/fixtures__cli__output_formatter_diagnostic_--format=github ok.js@oxlint.snap @@ -5,6 +5,7 @@ source: apps/oxlint/src/tester.rs arguments: --format=github ok.js working directory: fixtures/cli/output_formatter_diagnostic ---------- +Found 0 warnings and 0 errors. ---------- CLI result: LintSucceeded ---------- diff --git a/apps/oxlint/src/snapshots/fixtures__cli__output_formatter_diagnostic_--format=github parser-error.js@oxlint.snap b/apps/oxlint/src/snapshots/fixtures__cli__output_formatter_diagnostic_--format=github parser-error.js@oxlint.snap index 38e660d014c78..65f7d24e64740 100644 --- a/apps/oxlint/src/snapshots/fixtures__cli__output_formatter_diagnostic_--format=github parser-error.js@oxlint.snap +++ b/apps/oxlint/src/snapshots/fixtures__cli__output_formatter_diagnostic_--format=github parser-error.js@oxlint.snap @@ -6,6 +6,8 @@ arguments: --format=github parser-error.js working directory: fixtures/cli/output_formatter_diagnostic ---------- ::error file=parser-error.js,line=3,endLine=3,col=9,endColumn=10,title=oxlint::Expected `;` but found `:` + +Found 0 warnings and 1 error. ---------- CLI result: LintFoundErrors ---------- diff --git a/apps/oxlint/src/snapshots/fixtures__cli__output_formatter_diagnostic_--format=github test.js@oxlint.snap b/apps/oxlint/src/snapshots/fixtures__cli__output_formatter_diagnostic_--format=github test.js@oxlint.snap index f1f6a5f0124bf..4236ea56e8676 100644 --- a/apps/oxlint/src/snapshots/fixtures__cli__output_formatter_diagnostic_--format=github test.js@oxlint.snap +++ b/apps/oxlint/src/snapshots/fixtures__cli__output_formatter_diagnostic_--format=github test.js@oxlint.snap @@ -8,6 +8,8 @@ working directory: fixtures/cli/output_formatter_diagnostic ::error file=test.js,line=5,endLine=5,col=1,endColumn=10,title=eslint(no-debugger)::`debugger` statement is not allowed ::warning file=test.js,line=1,endLine=1,col=10,endColumn=13,title=eslint(no-unused-vars)::Function 'foo' is declared but never used. ::warning file=test.js,line=1,endLine=1,col=17,endColumn=18,title=eslint(no-unused-vars)::Parameter 'b' is declared but never used. Unused parameters should start with a '_'. + +Found 2 warnings and 1 error. ---------- CLI result: LintFoundErrors ----------