Skip to content

Commit a413281

Browse files
committed
Auto merge of #13052 - xFrednet:00000-lintcheck-warn-all, r=Alexendoo
Lintcheck: Add `--warn-all` and make it the CI default This PR adds a new `--warn-all` flag to lintcheck. This is intended for our CI, as it currently doesn't detect changes of `nursery` and `restriction` lints. I only made it the default for the CI, as `restriction` lints tend to generate A LOT of lint triggers. Looking at you [`clippy::implicit_return`](https://rust-lang.github.io/rust-clippy/master/index.html#/clippy::implicit_return) That's it. Should hopefully be easy to review. Also, a bit thanks again to `@Alexendoo` for adding this to our CI ❤️ --- r? `@Alexendoo` changelog: none
2 parents 09c07ed + 93e74a4 commit a413281

File tree

4 files changed

+49
-31
lines changed

4 files changed

+49
-31
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/README.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ repo. We can then check the diff and spot new or disappearing warnings.
77
From the repo root, run:
88

99
```
10-
cargo run --target-dir lintcheck/target --manifest-path lintcheck/Cargo.toml
10+
cargo lintcheck
1111
```
1212

1313
or
1414

1515
```
16-
cargo lintcheck
16+
cargo run --target-dir lintcheck/target --manifest-path lintcheck/Cargo.toml
1717
```
1818

1919
By default, the logs will be saved into
@@ -33,6 +33,8 @@ the 200 recently most downloaded crates:
3333
cargo lintcheck popular -n 200 custom.toml
3434
```
3535

36+
> Note: Lintcheck isn't sandboxed. Only use it to check crates that you trust or
37+
> sandbox it manually.
3638
3739
### Configuring the Crate Sources
3840

@@ -65,17 +67,11 @@ sources.
6567
#### Command Line Options (optional)
6668

6769
```toml
68-
bitflags = {name = "bitflags", versions = ['1.2.1'], options = ['-Wclippy::pedantic', '-Wclippy::cargo']}
70+
clap = {name = "clap", versions = ['4.5.8'], options = ['-Fderive']}
6971
```
7072

7173
It is possible to specify command line options for each crate. This makes it
72-
possible to only check a crate for certain lint groups. If no options are
73-
specified, the lint groups `clippy::all`, `clippy::pedantic`, and
74-
`clippy::cargo` are checked. If an empty array is specified only `clippy::all`
75-
is checked.
76-
77-
**Note:** `-Wclippy::all` is always enabled by default, unless `-Aclippy::all`
78-
is explicitly specified in the options.
74+
possible to enable or disable features.
7975

8076
### Fix mode
8177
You can run `cargo lintcheck --fix` which will run Clippy with `--fix` and

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)