mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-02 11:44:28 +00:00
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
This commit is contained in:
commit
a4132817fb
4
.github/workflows/lintcheck.yml
vendored
4
.github/workflows/lintcheck.yml
vendored
@ -58,7 +58,7 @@ jobs:
|
||||
|
||||
- name: Run lintcheck
|
||||
if: steps.cache-json.outputs.cache-hit != 'true'
|
||||
run: ./target/debug/lintcheck --format json
|
||||
run: ./target/debug/lintcheck --format json --warn-all
|
||||
|
||||
- name: Upload base JSON
|
||||
uses: actions/upload-artifact@v4
|
||||
@ -86,7 +86,7 @@ jobs:
|
||||
run: cargo build --manifest-path=lintcheck/Cargo.toml
|
||||
|
||||
- name: Run lintcheck
|
||||
run: ./target/debug/lintcheck --format json
|
||||
run: ./target/debug/lintcheck --format json --warn-all
|
||||
|
||||
- name: Upload head JSON
|
||||
uses: actions/upload-artifact@v4
|
||||
|
@ -7,13 +7,13 @@ repo. We can then check the diff and spot new or disappearing warnings.
|
||||
From the repo root, run:
|
||||
|
||||
```
|
||||
cargo run --target-dir lintcheck/target --manifest-path lintcheck/Cargo.toml
|
||||
cargo lintcheck
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```
|
||||
cargo lintcheck
|
||||
cargo run --target-dir lintcheck/target --manifest-path lintcheck/Cargo.toml
|
||||
```
|
||||
|
||||
By default, the logs will be saved into
|
||||
@ -33,6 +33,8 @@ the 200 recently most downloaded crates:
|
||||
cargo lintcheck popular -n 200 custom.toml
|
||||
```
|
||||
|
||||
> Note: Lintcheck isn't sandboxed. Only use it to check crates that you trust or
|
||||
> sandbox it manually.
|
||||
|
||||
### Configuring the Crate Sources
|
||||
|
||||
@ -65,17 +67,11 @@ sources.
|
||||
#### Command Line Options (optional)
|
||||
|
||||
```toml
|
||||
bitflags = {name = "bitflags", versions = ['1.2.1'], options = ['-Wclippy::pedantic', '-Wclippy::cargo']}
|
||||
clap = {name = "clap", versions = ['4.5.8'], options = ['-Fderive']}
|
||||
```
|
||||
|
||||
It is possible to specify command line options for each crate. This makes it
|
||||
possible to only check a crate for certain lint groups. If no options are
|
||||
specified, the lint groups `clippy::all`, `clippy::pedantic`, and
|
||||
`clippy::cargo` are checked. If an empty array is specified only `clippy::all`
|
||||
is checked.
|
||||
|
||||
**Note:** `-Wclippy::all` is always enabled by default, unless `-Aclippy::all`
|
||||
is explicitly specified in the options.
|
||||
possible to enable or disable features.
|
||||
|
||||
### Fix mode
|
||||
You can run `cargo lintcheck --fix` which will run Clippy with `--fix` and
|
||||
|
@ -36,6 +36,10 @@ pub(crate) struct LintcheckConfig {
|
||||
/// Apply a filter to only collect specified lints, this also overrides `allow` attributes
|
||||
#[clap(long = "filter", value_name = "clippy_lint_name", use_value_delimiter = true)]
|
||||
pub lint_filter: Vec<String>,
|
||||
/// Set all lints to the "warn" lint level, even resitriction ones. Usually,
|
||||
/// it's better to use `--filter` instead
|
||||
#[clap(long, conflicts_with("lint_filter"))]
|
||||
pub warn_all: bool,
|
||||
/// Set the output format of the log file
|
||||
#[clap(long, short, default_value = "text")]
|
||||
pub format: OutputFormat,
|
||||
|
@ -5,6 +5,7 @@
|
||||
// When a new lint is introduced, we can search the results for new warnings and check for false
|
||||
// positives.
|
||||
|
||||
#![feature(iter_collect_into)]
|
||||
#![warn(
|
||||
trivial_casts,
|
||||
trivial_numeric_casts,
|
||||
@ -352,7 +353,7 @@ impl Crate {
|
||||
target_dir_index: &AtomicUsize,
|
||||
total_crates_to_lint: usize,
|
||||
config: &LintcheckConfig,
|
||||
lint_filter: &[String],
|
||||
lint_levels_args: &[String],
|
||||
server: &Option<LintcheckServer>,
|
||||
) -> Vec<ClippyCheckOutput> {
|
||||
// advance the atomic index by one
|
||||
@ -398,16 +399,9 @@ impl Crate {
|
||||
for opt in options {
|
||||
clippy_args.push(opt);
|
||||
}
|
||||
} else {
|
||||
clippy_args.extend(["-Wclippy::pedantic", "-Wclippy::cargo"]);
|
||||
}
|
||||
|
||||
if lint_filter.is_empty() {
|
||||
clippy_args.push("--cap-lints=warn");
|
||||
} else {
|
||||
clippy_args.push("--cap-lints=allow");
|
||||
clippy_args.extend(lint_filter.iter().map(String::as_str));
|
||||
}
|
||||
clippy_args.extend(lint_levels_args.iter().map(String::as_str));
|
||||
|
||||
let mut cmd = Command::new("cargo");
|
||||
cmd.arg(if config.fix { "fix" } else { "check" })
|
||||
@ -638,15 +632,39 @@ fn lintcheck(config: LintcheckConfig) {
|
||||
let (crates, recursive_options) = read_crates(&config.sources_toml_path);
|
||||
|
||||
let counter = AtomicUsize::new(1);
|
||||
let lint_filter: Vec<String> = config
|
||||
.lint_filter
|
||||
.iter()
|
||||
.map(|filter| {
|
||||
let mut filter = filter.clone();
|
||||
filter.insert_str(0, "--force-warn=");
|
||||
filter
|
||||
})
|
||||
.collect();
|
||||
let mut lint_level_args: Vec<String> = vec![];
|
||||
if config.lint_filter.is_empty() {
|
||||
lint_level_args.push("--cap-lints=warn".to_string());
|
||||
|
||||
// Set allow-by-default to warn
|
||||
if config.warn_all {
|
||||
[
|
||||
"clippy::cargo",
|
||||
"clippy::nursery",
|
||||
"clippy::pedantic",
|
||||
"clippy::restriction",
|
||||
]
|
||||
.iter()
|
||||
.map(|group| format!("--warn={group}"))
|
||||
.collect_into(&mut lint_level_args);
|
||||
} else {
|
||||
["clippy::cargo", "clippy::pedantic"]
|
||||
.iter()
|
||||
.map(|group| format!("--warn={group}"))
|
||||
.collect_into(&mut lint_level_args);
|
||||
}
|
||||
} else {
|
||||
lint_level_args.push("--cap-lints=allow".to_string());
|
||||
config
|
||||
.lint_filter
|
||||
.iter()
|
||||
.map(|filter| {
|
||||
let mut filter = filter.clone();
|
||||
filter.insert_str(0, "--force-warn=");
|
||||
filter
|
||||
})
|
||||
.collect_into(&mut lint_level_args);
|
||||
};
|
||||
|
||||
let crates: Vec<Crate> = crates
|
||||
.into_iter()
|
||||
@ -698,7 +716,7 @@ fn lintcheck(config: LintcheckConfig) {
|
||||
&counter,
|
||||
crates.len(),
|
||||
&config,
|
||||
&lint_filter,
|
||||
&lint_level_args,
|
||||
&server,
|
||||
)
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user