@@ -264,6 +264,7 @@ impl Crate {
264
264
thread_limit: usize,
265
265
total_crates_to_lint: usize,
266
266
fix: bool,
267
+ lint_filter: &Vec<String>,
267
268
) -> Vec<ClippyWarning> {
268
269
// advance the atomic index by one
269
270
let index = target_dir_index.fetch_add(1, Ordering::SeqCst);
@@ -288,9 +289,9 @@ impl Crate {
288
289
let shared_target_dir = clippy_project_root().join("target/lintcheck/shared_target_dir");
289
290
290
291
let mut args = if fix {
291
- vec!["--fix", "--allow-no-vcs", "--", "--cap-lints=warn" ]
292
+ vec!["--fix", "--allow-no-vcs", "--"]
292
293
} else {
293
- vec!["--", "--message-format=json", "--", "--cap-lints=warn" ]
294
+ vec!["--", "--message-format=json", "--"]
294
295
};
295
296
296
297
if let Some(options) = &self.options {
@@ -301,6 +302,13 @@ impl Crate {
301
302
args.extend(&["-Wclippy::pedantic", "-Wclippy::cargo"])
302
303
}
303
304
305
+ if lint_filter.is_empty() {
306
+ args.push("--cap-lints=warn");
307
+ } else {
308
+ args.push("--cap-lints=allow");
309
+ args.extend(lint_filter.iter().map(|filter| filter.as_str()))
310
+ }
311
+
304
312
let all_output = std::process::Command::new(&cargo_clippy_path)
305
313
// use the looping index to create individual target dirs
306
314
.env(
@@ -360,14 +368,16 @@ impl Crate {
360
368
361
369
#[derive(Debug)]
362
370
struct LintcheckConfig {
363
- // max number of jobs to spawn (default 1)
371
+ /// max number of jobs to spawn (default 1)
364
372
max_jobs: usize,
365
- // we read the sources to check from here
373
+ /// we read the sources to check from here
366
374
sources_toml_path: PathBuf,
367
- // we save the clippy lint results here
375
+ /// we save the clippy lint results here
368
376
lintcheck_results_path: PathBuf,
369
- // whether to just run --fix and not collect all the warnings
377
+ /// whether to just run --fix and not collect all the warnings
370
378
fix: bool,
379
+ /// A list of lint that this lintcheck run shound focus on
380
+ lint_filter: Vec<String>,
371
381
}
372
382
373
383
impl LintcheckConfig {
@@ -410,12 +420,26 @@ impl LintcheckConfig {
410
420
None => 1,
411
421
};
412
422
let fix: bool = clap_config.is_present("fix");
423
+ let lint_filter: Vec<String> = clap_config
424
+ .values_of("filter")
425
+ .map(|iter| {
426
+ iter.map(|lint_name| {
427
+ let mut filter = lint_name.replace('_', "-");
428
+ if !filter.starts_with("clippy::") {
429
+ filter.insert_str(0, "clippy::");
430
+ }
431
+ filter
432
+ })
433
+ .collect()
434
+ })
435
+ .unwrap_or_default();
413
436
414
437
LintcheckConfig {
415
438
max_jobs,
416
439
sources_toml_path,
417
440
lintcheck_results_path,
418
441
fix,
442
+ lint_filter,
419
443
}
420
444
}
421
445
}
@@ -682,6 +706,15 @@ pub fn main() {
682
706
let old_stats = read_stats_from_file(&config.lintcheck_results_path);
683
707
684
708
let counter = AtomicUsize::new(1);
709
+ let lint_filter: Vec<String> = config
710
+ .lint_filter
711
+ .iter()
712
+ .map(|filter| {
713
+ let mut filter = filter.clone();
714
+ filter.insert_str(0, "--force-warn=");
715
+ filter
716
+ })
717
+ .collect();
685
718
686
719
let clippy_warnings: Vec<ClippyWarning> = if let Some(only_one_crate) = clap_config.value_of("only") {
687
720
// if we don't have the specified crate in the .toml, throw an error
@@ -705,7 +738,9 @@ pub fn main() {
705
738
.into_iter()
706
739
.map(|krate| krate.download_and_extract())
707
740
.filter(|krate| krate.name == only_one_crate)
708
- .flat_map(|krate| krate.run_clippy_lints(&cargo_clippy_path, &AtomicUsize::new(0), 1, 1, config.fix))
741
+ .flat_map(|krate| {
742
+ krate.run_clippy_lints(&cargo_clippy_path, &AtomicUsize::new(0), 1, 1, config.fix, &lint_filter)
743
+ })
709
744
.collect()
710
745
} else {
711
746
if config.max_jobs > 1 {
@@ -729,7 +764,14 @@ pub fn main() {
729
764
.into_par_iter()
730
765
.map(|krate| krate.download_and_extract())
731
766
.flat_map(|krate| {
732
- krate.run_clippy_lints(&cargo_clippy_path, &counter, num_cpus, num_crates, config.fix)
767
+ krate.run_clippy_lints(
768
+ &cargo_clippy_path,
769
+ &counter,
770
+ num_cpus,
771
+ num_crates,
772
+ config.fix,
773
+ &lint_filter,
774
+ )
733
775
})
734
776
.collect()
735
777
} else {
@@ -738,7 +780,9 @@ pub fn main() {
738
780
crates
739
781
.into_iter()
740
782
.map(|krate| krate.download_and_extract())
741
- .flat_map(|krate| krate.run_clippy_lints(&cargo_clippy_path, &counter, 1, num_crates, config.fix))
783
+ .flat_map(|krate| {
784
+ krate.run_clippy_lints(&cargo_clippy_path, &counter, 1, num_crates, config.fix, &lint_filter)
785
+ })
742
786
.collect()
743
787
}
744
788
};
@@ -774,7 +818,7 @@ pub fn main() {
774
818
std::fs::create_dir_all(config.lintcheck_results_path.parent().unwrap()).unwrap();
775
819
write(&config.lintcheck_results_path, text).unwrap();
776
820
777
- print_stats(old_stats, new_stats);
821
+ print_stats(old_stats, new_stats, &config.lint_filter );
778
822
}
779
823
780
824
/// read the previous stats from the lintcheck-log file
@@ -807,7 +851,7 @@ fn read_stats_from_file(file_path: &Path) -> HashMap<String, usize> {
807
851
}
808
852
809
853
/// print how lint counts changed between runs
810
- fn print_stats(old_stats: HashMap<String, usize>, new_stats: HashMap<&String, usize>) {
854
+ fn print_stats(old_stats: HashMap<String, usize>, new_stats: HashMap<&String, usize>, lint_filter: &Vec<String> ) {
811
855
let same_in_both_hashmaps = old_stats
812
856
.iter()
813
857
.filter(|(old_key, old_val)| new_stats.get::<&String>(&old_key) == Some(old_val))
@@ -846,6 +890,7 @@ fn print_stats(old_stats: HashMap<String, usize>, new_stats: HashMap<&String, us
846
890
old_stats_deduped
847
891
.iter()
848
892
.filter(|(old_key, _)| new_stats_deduped.get::<&String>(&old_key).is_none())
893
+ .filter(|(old_key, _)| lint_filter.is_empty() || lint_filter.contains(old_key))
849
894
.for_each(|(old_key, old_value)| {
850
895
println!("{} {} => 0", old_key, old_value);
851
896
});
@@ -904,6 +949,14 @@ fn get_clap_config<'a>() -> ArgMatches<'a> {
904
949
.long("--fix")
905
950
.help("runs cargo clippy --fix and checks if all suggestions apply"),
906
951
)
952
+ .arg(
953
+ Arg::with_name("filter")
954
+ .long("--filter")
955
+ .takes_value(true)
956
+ .multiple(true)
957
+ .value_name("clippy_lint_name")
958
+ .help("apply a filter to only collect specified lints, this also overrides `allow` attributes"),
959
+ )
907
960
.get_matches()
908
961
}
909
962
0 commit comments