|
5 | 5 | // When a new lint is introduced, we can search the results for new warnings and check for false
|
6 | 6 | // positives.
|
7 | 7 |
|
| 8 | +#![feature(iter_collect_into)] |
8 | 9 | #![warn(
|
9 | 10 | trivial_casts,
|
10 | 11 | trivial_numeric_casts,
|
@@ -352,7 +353,7 @@ impl Crate {
|
352 | 353 | target_dir_index: &AtomicUsize,
|
353 | 354 | total_crates_to_lint: usize,
|
354 | 355 | config: &LintcheckConfig,
|
355 |
| - lint_filter: &[String], |
| 356 | + lint_levels_args: &[String], |
356 | 357 | server: &Option<LintcheckServer>,
|
357 | 358 | ) -> Vec<ClippyCheckOutput> {
|
358 | 359 | // advance the atomic index by one
|
@@ -398,16 +399,9 @@ impl Crate {
|
398 | 399 | for opt in options {
|
399 | 400 | clippy_args.push(opt);
|
400 | 401 | }
|
401 |
| - } else { |
402 |
| - clippy_args.extend(["-Wclippy::pedantic", "-Wclippy::cargo"]); |
403 | 402 | }
|
404 | 403 |
|
405 |
| - if lint_filter.is_empty() { |
406 |
| - clippy_args.push("--cap-lints=warn"); |
407 |
| - } else { |
408 |
| - clippy_args.push("--cap-lints=allow"); |
409 |
| - clippy_args.extend(lint_filter.iter().map(String::as_str)); |
410 |
| - } |
| 404 | + clippy_args.extend(lint_levels_args.iter().map(String::as_str)); |
411 | 405 |
|
412 | 406 | let mut cmd = Command::new("cargo");
|
413 | 407 | cmd.arg(if config.fix { "fix" } else { "check" })
|
@@ -638,15 +632,39 @@ fn lintcheck(config: LintcheckConfig) {
|
638 | 632 | let (crates, recursive_options) = read_crates(&config.sources_toml_path);
|
639 | 633 |
|
640 | 634 | let counter = AtomicUsize::new(1);
|
641 |
| - let lint_filter: Vec<String> = config |
642 |
| - .lint_filter |
643 |
| - .iter() |
644 |
| - .map(|filter| { |
645 |
| - let mut filter = filter.clone(); |
646 |
| - filter.insert_str(0, "--force-warn="); |
647 |
| - filter |
648 |
| - }) |
649 |
| - .collect(); |
| 635 | + let mut lint_level_args: Vec<String> = vec![]; |
| 636 | + if config.lint_filter.is_empty() { |
| 637 | + lint_level_args.push("--cap-lints=warn".to_string()); |
| 638 | + |
| 639 | + // Set allow-by-default to warn |
| 640 | + if config.warn_all { |
| 641 | + [ |
| 642 | + "clippy::cargo", |
| 643 | + "clippy::nursery", |
| 644 | + "clippy::pedantic", |
| 645 | + "clippy::restriction", |
| 646 | + ] |
| 647 | + .iter() |
| 648 | + .map(|group| format!("--warn={group}")) |
| 649 | + .collect_into(&mut lint_level_args); |
| 650 | + } else { |
| 651 | + ["clippy::cargo", "clippy::pedantic"] |
| 652 | + .iter() |
| 653 | + .map(|group| format!("--warn={group}")) |
| 654 | + .collect_into(&mut lint_level_args); |
| 655 | + } |
| 656 | + } else { |
| 657 | + lint_level_args.push("--cap-lints=allow".to_string()); |
| 658 | + config |
| 659 | + .lint_filter |
| 660 | + .iter() |
| 661 | + .map(|filter| { |
| 662 | + let mut filter = filter.clone(); |
| 663 | + filter.insert_str(0, "--force-warn="); |
| 664 | + filter |
| 665 | + }) |
| 666 | + .collect_into(&mut lint_level_args); |
| 667 | + }; |
650 | 668 |
|
651 | 669 | let crates: Vec<Crate> = crates
|
652 | 670 | .into_iter()
|
@@ -698,7 +716,7 @@ fn lintcheck(config: LintcheckConfig) {
|
698 | 716 | &counter,
|
699 | 717 | crates.len(),
|
700 | 718 | &config,
|
701 |
| - &lint_filter, |
| 719 | + &lint_level_args, |
702 | 720 | &server,
|
703 | 721 | )
|
704 | 722 | })
|
|
0 commit comments