@@ -229,6 +229,7 @@ impl Crate {
229
229
target_dir_index : & AtomicUsize ,
230
230
thread_limit : usize ,
231
231
total_crates_to_lint : usize ,
232
+ fix : bool ,
232
233
) -> Vec < ClippyWarning > {
233
234
// advance the atomic index by one
234
235
let index = target_dir_index. fetch_add ( 1 , Ordering :: SeqCst ) ;
@@ -252,7 +253,18 @@ impl Crate {
252
253
253
254
let shared_target_dir = clippy_project_root ( ) . join ( "target/lintcheck/shared_target_dir" ) ;
254
255
255
- let mut args = vec ! [ "--" , "--message-format=json" , "--" , "--cap-lints=warn" ] ;
256
+ let mut args = if fix {
257
+ vec ! [
258
+ "-Zunstable-options" ,
259
+ "--fix" ,
260
+ "-Zunstable-options" ,
261
+ "--allow-no-vcs" ,
262
+ "--" ,
263
+ "--cap-lints=warn" ,
264
+ ]
265
+ } else {
266
+ vec ! [ "--" , "--message-format=json" , "--" , "--cap-lints=warn" ]
267
+ } ;
256
268
257
269
if let Some ( options) = & self . options {
258
270
for opt in options {
@@ -282,13 +294,31 @@ impl Crate {
282
294
) ;
283
295
} ) ;
284
296
let stdout = String :: from_utf8_lossy ( & all_output. stdout ) ;
297
+ let stderr = String :: from_utf8_lossy ( & all_output. stderr ) ;
298
+
299
+ if fix {
300
+ if let Some ( stderr) = stderr
301
+ . lines ( )
302
+ . find ( |line| line. contains ( "failed to automatically apply fixes suggested by rustc to crate" ) )
303
+ {
304
+ let subcrate = & stderr[ 63 ..] ;
305
+ println ! (
306
+ "ERROR: failed to apply some suggetion to {} / to (sub)crate {}" ,
307
+ self . name, subcrate
308
+ ) ;
309
+ }
310
+ // fast path, we don't need the warnings anyway
311
+ return Vec :: new ( ) ;
312
+ }
313
+
285
314
let output_lines = stdout. lines ( ) ;
286
315
let warnings: Vec < ClippyWarning > = output_lines
287
316
. into_iter ( )
288
317
// get all clippy warnings and ICEs
289
318
. filter ( |line| filter_clippy_warnings ( & line) )
290
319
. map ( |json_msg| parse_json_message ( json_msg, & self ) )
291
320
. collect ( ) ;
321
+
292
322
warnings
293
323
}
294
324
}
@@ -301,6 +331,8 @@ struct LintcheckConfig {
301
331
sources_toml_path : PathBuf ,
302
332
// we save the clippy lint results here
303
333
lintcheck_results_path : PathBuf ,
334
+ // whether to just run --fix and not collect all the warnings
335
+ fix : bool ,
304
336
}
305
337
306
338
impl LintcheckConfig {
@@ -342,11 +374,13 @@ impl LintcheckConfig {
342
374
// no -j passed, use a single thread
343
375
None => 1 ,
344
376
} ;
377
+ let fix: bool = clap_config. is_present ( "fix" ) ;
345
378
346
379
LintcheckConfig {
347
380
max_jobs,
348
381
sources_toml_path,
349
382
lintcheck_results_path,
383
+ fix,
350
384
}
351
385
}
352
386
}
@@ -598,7 +632,7 @@ pub fn run(clap_config: &ArgMatches) {
598
632
. into_iter ( )
599
633
. map ( |krate| krate. download_and_extract ( ) )
600
634
. filter ( |krate| krate. name == only_one_crate)
601
- . flat_map ( |krate| krate. run_clippy_lints ( & cargo_clippy_path, & AtomicUsize :: new ( 0 ) , 1 , 1 ) )
635
+ . flat_map ( |krate| krate. run_clippy_lints ( & cargo_clippy_path, & AtomicUsize :: new ( 0 ) , 1 , 1 , config . fix ) )
602
636
. collect ( )
603
637
} else {
604
638
if config. max_jobs > 1 {
@@ -621,19 +655,26 @@ pub fn run(clap_config: &ArgMatches) {
621
655
crates
622
656
. into_par_iter ( )
623
657
. map ( |krate| krate. download_and_extract ( ) )
624
- . flat_map ( |krate| krate. run_clippy_lints ( & cargo_clippy_path, & counter, num_cpus, num_crates) )
658
+ . flat_map ( |krate| {
659
+ krate. run_clippy_lints ( & cargo_clippy_path, & counter, num_cpus, num_crates, config. fix )
660
+ } )
625
661
. collect ( )
626
662
} else {
627
663
// run sequential
628
664
let num_crates = crates. len ( ) ;
629
665
crates
630
666
. into_iter ( )
631
667
. map ( |krate| krate. download_and_extract ( ) )
632
- . flat_map ( |krate| krate. run_clippy_lints ( & cargo_clippy_path, & counter, 1 , num_crates) )
668
+ . flat_map ( |krate| krate. run_clippy_lints ( & cargo_clippy_path, & counter, 1 , num_crates, config . fix ) )
633
669
. collect ( )
634
670
}
635
671
} ;
636
672
673
+ // if we are in --fix mode, don't change the log files, terminate here
674
+ if config. fix {
675
+ return ;
676
+ }
677
+
637
678
// generate some stats
638
679
let ( stats_formatted, new_stats) = gather_stats ( & clippy_warnings) ;
639
680
0 commit comments