Merge commit 'd7b5cbf065' into clippyup
This commit is contained in:
parent
bd071bf5b2
commit
f8f9d01c2a
199 changed files with 4158 additions and 1931 deletions
|
|
@ -1,50 +1,40 @@
|
|||
use clap::{Arg, ArgMatches, Command};
|
||||
use clap::{Arg, ArgAction, ArgMatches, Command};
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn get_clap_config() -> ArgMatches {
|
||||
Command::new("lintcheck")
|
||||
.about("run clippy on a set of crates and check output")
|
||||
.arg(
|
||||
.args([
|
||||
Arg::new("only")
|
||||
.takes_value(true)
|
||||
.action(ArgAction::Set)
|
||||
.value_name("CRATE")
|
||||
.long("only")
|
||||
.help("Only process a single crate of the list"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("crates-toml")
|
||||
.takes_value(true)
|
||||
.action(ArgAction::Set)
|
||||
.value_name("CRATES-SOURCES-TOML-PATH")
|
||||
.long("crates-toml")
|
||||
.help("Set the path for a crates.toml where lintcheck should read the sources from"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("threads")
|
||||
.takes_value(true)
|
||||
.action(ArgAction::Set)
|
||||
.value_name("N")
|
||||
.value_parser(clap::value_parser!(usize))
|
||||
.short('j')
|
||||
.long("jobs")
|
||||
.help("Number of threads to use, 0 automatic choice"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("fix")
|
||||
.long("--fix")
|
||||
.long("fix")
|
||||
.help("Runs cargo clippy --fix and checks if all suggestions apply"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("filter")
|
||||
.long("--filter")
|
||||
.takes_value(true)
|
||||
.multiple_occurrences(true)
|
||||
.long("filter")
|
||||
.action(ArgAction::Append)
|
||||
.value_name("clippy_lint_name")
|
||||
.help("Apply a filter to only collect specified lints, this also overrides `allow` attributes"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("markdown")
|
||||
.long("--markdown")
|
||||
.long("markdown")
|
||||
.help("Change the reports table to use markdown links"),
|
||||
)
|
||||
])
|
||||
.get_matches()
|
||||
}
|
||||
|
||||
|
|
@ -75,13 +65,13 @@ impl LintcheckConfig {
|
|||
// if not, use the default "lintcheck/lintcheck_crates.toml"
|
||||
let sources_toml = env::var("LINTCHECK_TOML").unwrap_or_else(|_| {
|
||||
clap_config
|
||||
.value_of("crates-toml")
|
||||
.clone()
|
||||
.get_one::<String>("crates-toml")
|
||||
.map(|s| &**s)
|
||||
.unwrap_or("lintcheck/lintcheck_crates.toml")
|
||||
.to_string()
|
||||
.into()
|
||||
});
|
||||
|
||||
let markdown = clap_config.is_present("markdown");
|
||||
let markdown = clap_config.contains_id("markdown");
|
||||
let sources_toml_path = PathBuf::from(sources_toml);
|
||||
|
||||
// for the path where we save the lint results, get the filename without extension (so for
|
||||
|
|
@ -96,25 +86,19 @@ impl LintcheckConfig {
|
|||
// look at the --threads arg, if 0 is passed, ask rayon rayon how many threads it would spawn and
|
||||
// use half of that for the physical core count
|
||||
// by default use a single thread
|
||||
let max_jobs = match clap_config.value_of("threads") {
|
||||
Some(threads) => {
|
||||
let threads: usize = threads
|
||||
.parse()
|
||||
.unwrap_or_else(|_| panic!("Failed to parse '{}' to a digit", threads));
|
||||
if threads == 0 {
|
||||
// automatic choice
|
||||
// Rayon seems to return thread count so half that for core count
|
||||
(rayon::current_num_threads() / 2) as usize
|
||||
} else {
|
||||
threads
|
||||
}
|
||||
let max_jobs = match clap_config.get_one::<usize>("threads") {
|
||||
Some(&0) => {
|
||||
// automatic choice
|
||||
// Rayon seems to return thread count so half that for core count
|
||||
(rayon::current_num_threads() / 2) as usize
|
||||
},
|
||||
Some(&threads) => threads,
|
||||
// no -j passed, use a single thread
|
||||
None => 1,
|
||||
};
|
||||
|
||||
let lint_filter: Vec<String> = clap_config
|
||||
.values_of("filter")
|
||||
.get_many::<String>("filter")
|
||||
.map(|iter| {
|
||||
iter.map(|lint_name| {
|
||||
let mut filter = lint_name.replace('_', "-");
|
||||
|
|
@ -131,8 +115,8 @@ impl LintcheckConfig {
|
|||
max_jobs,
|
||||
sources_toml_path,
|
||||
lintcheck_results_path,
|
||||
only: clap_config.value_of("only").map(String::from),
|
||||
fix: clap_config.is_present("fix"),
|
||||
only: clap_config.get_one::<String>("only").map(String::from),
|
||||
fix: clap_config.contains_id("fix"),
|
||||
lint_filter,
|
||||
markdown,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue