clippy dev crater: add option to only check a single one of the listed crates with --only crate

This commit is contained in:
Matthias Krüger 2020-12-27 16:13:42 +01:00
parent d257101109
commit b6ef1e282e
2 changed files with 32 additions and 10 deletions

View file

@ -12,6 +12,7 @@ use std::collections::HashMap;
use std::process::Command;
use std::{fmt, fs::write, path::PathBuf};
use clap::ArgMatches;
use serde::{Deserialize, Serialize};
use serde_json::Value;
@ -200,7 +201,7 @@ fn parse_json_message(json_message: &str, krate: &Crate) -> ClippyWarning {
}
// the main fn
pub fn run() {
pub fn run(clap_config: &ArgMatches) {
let cargo_clippy_path: PathBuf = PathBuf::from("target/debug/cargo-clippy");
println!("Compiling clippy...");
@ -217,12 +218,23 @@ pub fn run() {
// download and extract the crates, then run clippy on them and collect clippys warnings
// flatten into one big list of warnings
let clippy_warnings: Vec<ClippyWarning> = read_crates()
.into_iter()
.map(|krate| krate.download_and_extract())
.map(|krate| krate.run_clippy_lints(&cargo_clippy_path))
.flatten()
.collect();
let clippy_warnings: Vec<ClippyWarning> = if let Some(only_one_crate) = clap_config.value_of("only") {
// only check a single
read_crates()
.into_iter()
.map(|krate| krate.download_and_extract())
.filter(|krate| krate.name == only_one_crate)
.map(|krate| krate.run_clippy_lints(&cargo_clippy_path))
.flatten()
.collect()
} else {
read_crates()
.into_iter()
.map(|krate| krate.download_and_extract())
.map(|krate| krate.run_clippy_lints(&cargo_clippy_path))
.flatten()
.collect()
};
// generate some stats:

View file

@ -10,8 +10,8 @@ fn main() {
("bless", Some(matches)) => {
bless::bless(matches.is_present("ignore-timestamp"));
},
("crater", Some(_)) => {
crater::run();
("crater", Some(matches)) => {
crater::run(&matches);
},
("fmt", Some(matches)) => {
fmt::run(matches.is_present("check"), matches.is_present("verbose"));
@ -59,7 +59,17 @@ fn get_clap_config<'a>() -> ArgMatches<'a> {
.help("Include files updated before clippy was built"),
),
)
.subcommand(SubCommand::with_name("crater").about("run clippy on a set of crates and check output"))
.subcommand(
SubCommand::with_name("crater")
.about("run clippy on a set of crates and check output")
.arg(
Arg::with_name("only")
.takes_value(true)
.value_name("CRATE")
.long("only")
.help("only process a single crate of the list"),
),
)
.subcommand(
SubCommand::with_name("fmt")
.about("Run rustfmt on all projects and tests")