11use std:: { env, io:: BufWriter , path:: PathBuf , sync:: mpsc, time:: Instant } ;
22
3- use oxc_diagnostics:: DiagnosticService ;
3+ use oxc_diagnostics:: { DiagnosticService , reporter :: DiagnosticReporter } ;
44
55use super :: {
66 command:: { FormatCommand , Mode , OutputMode } ,
7- reporter:: DefaultReporter ,
7+ reporter:: { DefaultReporter , MinimalReporter } ,
88 resolve:: resolve_ignore_paths,
99 result:: CliRunResult ,
1010 service:: { FormatService , SuccessResult } ,
@@ -69,13 +69,20 @@ impl WalkRunner {
6969 let start_time = Instant :: now ( ) ;
7070
7171 let cwd = self . cwd ;
72- let FormatCommand { paths, mode, config_options, ignore_options, runtime_options } =
73- self . options ;
72+ let FormatCommand {
73+ paths,
74+ mode,
75+ output_options,
76+ config_options,
77+ ignore_options,
78+ runtime_options,
79+ } = self . options ;
7480 // If `napi` feature is disabled, there is no other mode.
7581 #[ cfg_attr( not( feature = "napi" ) , expect( irrefutable_let_patterns) ) ]
7682 let Mode :: Cli ( format_mode) = mode else {
7783 unreachable ! ( "`WalkRunner` should only be called with Mode::Cli" ) ;
7884 } ;
85+ let minimal_output = output_options. minimal ;
7986 let num_of_threads = rayon:: current_num_threads ( ) ;
8087
8188 // Find and load root config file
@@ -140,10 +147,14 @@ impl WalkRunner {
140147 // Collect format results (changed paths or unchanged count)
141148 let ( tx_success, rx_success) = mpsc:: channel ( ) ;
142149 // Diagnostic from formatting service
143- let ( mut diagnostic_service, tx_error) =
144- DiagnosticService :: new ( Box :: new ( DefaultReporter :: default ( ) ) ) ;
150+ let reporter: Box < dyn DiagnosticReporter > = if minimal_output {
151+ Box :: new ( MinimalReporter )
152+ } else {
153+ Box :: new ( DefaultReporter :: default ( ) )
154+ } ;
155+ let ( mut diagnostic_service, tx_error) = DiagnosticService :: new ( reporter) ;
145156
146- if matches ! ( format_mode, OutputMode :: Check ) {
157+ if matches ! ( format_mode, OutputMode :: Check ) && !minimal_output {
147158 utils:: print_and_flush ( stdout, "Checking formatting...\n " ) ;
148159 utils:: print_and_flush ( stdout, "\n " ) ;
149160 }
@@ -161,7 +172,8 @@ impl WalkRunner {
161172 // Spawn formatting service on a dedicated thread so it doesn't occupy the rayon pool.
162173 // It just blocks on `rx_entry` waiting for entries; `par_bridge()` inside still uses rayon.
163174 std:: thread:: spawn ( move || {
164- let format_service = FormatService :: new ( cwd, format_mode, source_formatter) ;
175+ let format_service =
176+ FormatService :: new ( cwd, format_mode, source_formatter, minimal_output) ;
165177 format_service. run_streaming ( rx_entry, & tx_error_for_format, & tx_success) ;
166178 } ) ;
167179
@@ -206,7 +218,11 @@ impl WalkRunner {
206218 // Print sorted changed file paths to stdout
207219 if !changed_paths. is_empty ( ) {
208220 changed_paths. sort_unstable ( ) ;
209- utils:: print_and_flush ( stdout, & changed_paths. join ( "\n " ) ) ;
221+ if minimal_output {
222+ utils:: print_and_flush ( stdout, & format ! ( "{}\n " , changed_paths. join( "\n " ) ) ) ;
223+ } else {
224+ utils:: print_and_flush ( stdout, & changed_paths. join ( "\n " ) ) ;
225+ }
210226 }
211227
212228 // Then, output diagnostics errors to stderr
@@ -218,6 +234,10 @@ impl WalkRunner {
218234 // Count the processed files
219235 let total_target_files_count = changed_paths. len ( ) + unchanged_count + error_count;
220236 let print_stats = |stdout, stderr| {
237+ if minimal_output {
238+ return ;
239+ }
240+
221241 utils:: print_and_flush (
222242 stdout,
223243 & format ! (
@@ -239,24 +259,32 @@ impl WalkRunner {
239259 // Check if no files were found
240260 if total_target_files_count == 0 {
241261 if runtime_options. no_error_on_unmatched_pattern {
242- utils:: print_and_flush ( stderr, "No files found matching the given patterns.\n " ) ;
243- print_stats ( stdout, stderr) ;
262+ if !minimal_output {
263+ utils:: print_and_flush ( stderr, "No files found matching the given patterns.\n " ) ;
264+ print_stats ( stdout, stderr) ;
265+ }
244266 return CliRunResult :: None ;
245267 }
246268
247- utils:: print_and_flush (
248- stderr,
249- "Expected at least one target file. All matched files may have been excluded by ignore rules.\n " ,
250- ) ;
269+ if minimal_output {
270+ utils:: print_and_flush ( stderr, "No files found.\n " ) ;
271+ } else {
272+ utils:: print_and_flush (
273+ stderr,
274+ "Expected at least one target file. All matched files may have been excluded by ignore rules.\n " ,
275+ ) ;
276+ }
251277 return CliRunResult :: NoFilesFound ;
252278 }
253279
254280 if 0 < error_count {
255281 // Each error is already printed in reporter
256- utils:: print_and_flush (
257- stderr,
258- "Error occurred when checking code style in the above files.\n " ,
259- ) ;
282+ if !minimal_output {
283+ utils:: print_and_flush (
284+ stderr,
285+ "Error occurred when checking code style in the above files.\n " ,
286+ ) ;
287+ }
260288 return CliRunResult :: FormatFailed ;
261289 }
262290
@@ -266,19 +294,23 @@ impl WalkRunner {
266294 ( OutputMode :: ListDifferent , _) => CliRunResult :: FormatMismatch ,
267295 // `--check` outputs friendly summary
268296 ( OutputMode :: Check , 0 ) => {
269- utils:: print_and_flush ( stdout, "All matched files use the correct format.\n " ) ;
270- print_stats ( stdout, stderr) ;
297+ if !minimal_output {
298+ utils:: print_and_flush ( stdout, "All matched files use the correct format.\n " ) ;
299+ print_stats ( stdout, stderr) ;
300+ }
271301 CliRunResult :: FormatSucceeded
272302 }
273303 ( OutputMode :: Check , changed_count) => {
274- utils:: print_and_flush ( stdout, "\n \n " ) ;
275- utils:: print_and_flush (
276- stdout,
277- & format ! (
278- "Format issues found in above {changed_count} files. Run without `--check` to fix.\n " ,
279- ) ,
280- ) ;
281- print_stats ( stdout, stderr) ;
304+ if !minimal_output {
305+ utils:: print_and_flush ( stdout, "\n \n " ) ;
306+ utils:: print_and_flush (
307+ stdout,
308+ & format ! (
309+ "Format issues found in above {changed_count} files. Run without `--check` to fix.\n " ,
310+ ) ,
311+ ) ;
312+ print_stats ( stdout, stderr) ;
313+ }
282314 CliRunResult :: FormatMismatch
283315 }
284316 // Default (write) outputs only stats
0 commit comments