Lintcheck: Add `--warn-all` and make it the CI default

This commit is contained in:
xFrednet 2024-07-05 16:36:24 +02:00
parent 94a000b613
commit 25bb612538
No known key found for this signature in database
GPG Key ID: F5C59D0E669E5302
3 changed files with 43 additions and 21 deletions

View File

@ -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

View File

@ -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,

View File

@ -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,
)
})