Skip to content

Commit 25bb612

Browse files
committed
Lintcheck: Add --warn-all and make it the CI default
1 parent 94a000b commit 25bb612

File tree

3 files changed

+43
-21
lines changed

3 files changed

+43
-21
lines changed

.github/workflows/lintcheck.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858

5959
- name: Run lintcheck
6060
if: steps.cache-json.outputs.cache-hit != 'true'
61-
run: ./target/debug/lintcheck --format json
61+
run: ./target/debug/lintcheck --format json --warn-all
6262

6363
- name: Upload base JSON
6464
uses: actions/upload-artifact@v4
@@ -86,7 +86,7 @@ jobs:
8686
run: cargo build --manifest-path=lintcheck/Cargo.toml
8787

8888
- name: Run lintcheck
89-
run: ./target/debug/lintcheck --format json
89+
run: ./target/debug/lintcheck --format json --warn-all
9090

9191
- name: Upload head JSON
9292
uses: actions/upload-artifact@v4

lintcheck/src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ pub(crate) struct LintcheckConfig {
3636
/// Apply a filter to only collect specified lints, this also overrides `allow` attributes
3737
#[clap(long = "filter", value_name = "clippy_lint_name", use_value_delimiter = true)]
3838
pub lint_filter: Vec<String>,
39+
/// Set all lints to the "warn" lint level, even resitriction ones. Usually,
40+
/// it's better to use `--filter` instead
41+
#[clap(long, conflicts_with("lint_filter"))]
42+
pub warn_all: bool,
3943
/// Set the output format of the log file
4044
#[clap(long, short, default_value = "text")]
4145
pub format: OutputFormat,

lintcheck/src/main.rs

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// When a new lint is introduced, we can search the results for new warnings and check for false
66
// positives.
77

8+
#![feature(iter_collect_into)]
89
#![warn(
910
trivial_casts,
1011
trivial_numeric_casts,
@@ -352,7 +353,7 @@ impl Crate {
352353
target_dir_index: &AtomicUsize,
353354
total_crates_to_lint: usize,
354355
config: &LintcheckConfig,
355-
lint_filter: &[String],
356+
lint_levels_args: &[String],
356357
server: &Option<LintcheckServer>,
357358
) -> Vec<ClippyCheckOutput> {
358359
// advance the atomic index by one
@@ -398,16 +399,9 @@ impl Crate {
398399
for opt in options {
399400
clippy_args.push(opt);
400401
}
401-
} else {
402-
clippy_args.extend(["-Wclippy::pedantic", "-Wclippy::cargo"]);
403402
}
404403

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));
411405

412406
let mut cmd = Command::new("cargo");
413407
cmd.arg(if config.fix { "fix" } else { "check" })
@@ -638,15 +632,39 @@ fn lintcheck(config: LintcheckConfig) {
638632
let (crates, recursive_options) = read_crates(&config.sources_toml_path);
639633

640634
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+
};
650668

651669
let crates: Vec<Crate> = crates
652670
.into_iter()
@@ -698,7 +716,7 @@ fn lintcheck(config: LintcheckConfig) {
698716
&counter,
699717
crates.len(),
700718
&config,
701-
&lint_filter,
719+
&lint_level_args,
702720
&server,
703721
)
704722
})

0 commit comments

Comments
 (0)