1
1
use std:: {
2
2
env, fs,
3
- io:: { BufWriter , ErrorKind , Write } ,
3
+ io:: { ErrorKind , Write } ,
4
4
path:: { Path , PathBuf } ,
5
5
process:: ExitCode ,
6
6
time:: Instant ,
@@ -34,16 +34,14 @@ impl Runner for LintRunner {
34
34
Self { options, cwd : env:: current_dir ( ) . expect ( "Failed to get current working directory" ) }
35
35
}
36
36
37
- fn run ( self ) -> CliRunResult {
37
+ fn run ( self , stdout : & mut dyn Write ) -> CliRunResult {
38
38
let format_str = self . options . output_options . format ;
39
- let mut output_formatter = OutputFormatter :: new ( format_str) ;
40
-
41
- // stdio is blocked by LineWriter, use a BufWriter to reduce syscalls.
42
- // See `https://github.com/rust-lang/rust/issues/60673`.
43
- let mut stdout = BufWriter :: new ( std:: io:: stdout ( ) ) ;
39
+ let output_formatter = OutputFormatter :: new ( format_str) ;
44
40
45
41
if self . options . list_rules {
46
- output_formatter. all_rules ( & mut stdout) ;
42
+ if let Some ( output) = output_formatter. all_rules ( ) {
43
+ stdout. write_all ( output. as_bytes ( ) ) . or_else ( Self :: check_for_writer_error) . unwrap ( ) ;
44
+ }
47
45
stdout. flush ( ) . unwrap ( ) ;
48
46
return CliRunResult :: None ;
49
47
}
@@ -206,7 +204,7 @@ impl Runner for LintRunner {
206
204
}
207
205
} ) ;
208
206
209
- let diagnostic_result = diagnostic_service. run ( & mut stdout) ;
207
+ let diagnostic_result = diagnostic_service. run ( stdout) ;
210
208
211
209
let diagnostic_failed = diagnostic_result. max_warnings_exceeded ( )
212
210
|| diagnostic_result. errors_count ( ) > 0
@@ -334,7 +332,9 @@ mod test {
334
332
let mut new_args = vec ! [ "--silent" ] ;
335
333
new_args. extend ( args) ;
336
334
let options = lint_command ( ) . run_inner ( new_args. as_slice ( ) ) . unwrap ( ) ;
337
- match LintRunner :: new ( options) . run ( ) {
335
+ let mut output = Vec :: new ( ) ;
336
+
337
+ match LintRunner :: new ( options) . run ( & mut output) {
338
338
CliRunResult :: LintResult ( lint_result) => lint_result,
339
339
other => panic ! ( "{other:?}" ) ,
340
340
}
@@ -356,8 +356,9 @@ mod test {
356
356
} ;
357
357
358
358
current_cwd. push ( part_cwd) ;
359
+ let mut output = Vec :: new ( ) ;
359
360
360
- match LintRunner :: new ( options) . with_cwd ( current_cwd) . run ( ) {
361
+ match LintRunner :: new ( options) . with_cwd ( current_cwd) . run ( & mut output ) {
361
362
CliRunResult :: LintResult ( lint_result) => lint_result,
362
363
other => panic ! ( "{other:?}" ) ,
363
364
}
@@ -367,7 +368,9 @@ mod test {
367
368
let mut new_args = vec ! [ "--quiet" ] ;
368
369
new_args. extend ( args) ;
369
370
let options = lint_command ( ) . run_inner ( new_args. as_slice ( ) ) . unwrap ( ) ;
370
- match LintRunner :: new ( options) . run ( ) {
371
+ let mut output = Vec :: new ( ) ;
372
+
373
+ match LintRunner :: new ( options) . run ( & mut output) {
371
374
CliRunResult :: InvalidOptions { message } => message,
372
375
other => {
373
376
panic ! ( "Expected InvalidOptions, got {other:?}" ) ;
@@ -752,7 +755,8 @@ mod test {
752
755
fn test_print_config_ban_all_rules ( ) {
753
756
let args = & [ "-A" , "all" , "--print-config" ] ;
754
757
let options = lint_command ( ) . run_inner ( args) . unwrap ( ) ;
755
- let ret = LintRunner :: new ( options) . run ( ) ;
758
+ let mut output = Vec :: new ( ) ;
759
+ let ret = LintRunner :: new ( options) . run ( & mut output) ;
756
760
let CliRunResult :: PrintConfigResult { config_file : config } = ret else {
757
761
panic ! ( "Expected PrintConfigResult, got {ret:?}" )
758
762
} ;
@@ -776,7 +780,8 @@ mod test {
776
780
"--print-config" ,
777
781
] ;
778
782
let options = lint_command ( ) . run_inner ( args) . unwrap ( ) ;
779
- let ret = LintRunner :: new ( options) . run ( ) ;
783
+ let mut output = Vec :: new ( ) ;
784
+ let ret = LintRunner :: new ( options) . run ( & mut output) ;
780
785
let CliRunResult :: PrintConfigResult { config_file : config } = ret else {
781
786
panic ! ( "Expected PrintConfigResult, got {ret:?}" )
782
787
} ;
@@ -793,7 +798,8 @@ mod test {
793
798
fn test_init_config ( ) {
794
799
let args = & [ "--init" ] ;
795
800
let options = lint_command ( ) . run_inner ( args) . unwrap ( ) ;
796
- let ret = LintRunner :: new ( options) . run ( ) ;
801
+ let mut output = Vec :: new ( ) ;
802
+ let ret = LintRunner :: new ( options) . run ( & mut output) ;
797
803
let CliRunResult :: ConfigFileInitResult { message } = ret else {
798
804
panic ! ( "Expected configuration file to be created, got {ret:?}" )
799
805
} ;
0 commit comments