Rollup merge of #97210 - Milo123459:clippy-args, r=jyn514
Support `-A`, `-W`, `-D` and `-F` when running `./x.py clippy` Resolves #97059 This PR adds support for `-A`, `-W`, `-D` and `-F` when running `./x.py clippy`.
This commit is contained in:
commit
601c5a2087
@ -20,7 +20,15 @@ fn strings<'a>(arr: &'a [&str]) -> impl Iterator<Item = String> + 'a {
|
|||||||
arr.iter().copied().map(String::from)
|
arr.iter().copied().map(String::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Subcommand::Clippy { fix, .. } = builder.config.cmd {
|
if let Subcommand::Clippy {
|
||||||
|
fix,
|
||||||
|
clippy_lint_allow,
|
||||||
|
clippy_lint_deny,
|
||||||
|
clippy_lint_warn,
|
||||||
|
clippy_lint_forbid,
|
||||||
|
..
|
||||||
|
} = &builder.config.cmd
|
||||||
|
{
|
||||||
// disable the most spammy clippy lints
|
// disable the most spammy clippy lints
|
||||||
let ignored_lints = vec![
|
let ignored_lints = vec![
|
||||||
"many_single_char_names", // there are a lot in stdarch
|
"many_single_char_names", // there are a lot in stdarch
|
||||||
@ -32,7 +40,7 @@ fn strings<'a>(arr: &'a [&str]) -> impl Iterator<Item = String> + 'a {
|
|||||||
"wrong_self_convention",
|
"wrong_self_convention",
|
||||||
];
|
];
|
||||||
let mut args = vec![];
|
let mut args = vec![];
|
||||||
if fix {
|
if *fix {
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
args.extend(strings(&[
|
args.extend(strings(&[
|
||||||
"--fix", "-Zunstable-options",
|
"--fix", "-Zunstable-options",
|
||||||
@ -44,6 +52,12 @@ fn strings<'a>(arr: &'a [&str]) -> impl Iterator<Item = String> + 'a {
|
|||||||
}
|
}
|
||||||
args.extend(strings(&["--", "--cap-lints", "warn"]));
|
args.extend(strings(&["--", "--cap-lints", "warn"]));
|
||||||
args.extend(ignored_lints.iter().map(|lint| format!("-Aclippy::{}", lint)));
|
args.extend(ignored_lints.iter().map(|lint| format!("-Aclippy::{}", lint)));
|
||||||
|
let mut clippy_lint_levels: Vec<String> = Vec::new();
|
||||||
|
clippy_lint_allow.iter().for_each(|v| clippy_lint_levels.push(format!("-A{}", v)));
|
||||||
|
clippy_lint_deny.iter().for_each(|v| clippy_lint_levels.push(format!("-D{}", v)));
|
||||||
|
clippy_lint_warn.iter().for_each(|v| clippy_lint_levels.push(format!("-W{}", v)));
|
||||||
|
clippy_lint_forbid.iter().for_each(|v| clippy_lint_levels.push(format!("-F{}", v)));
|
||||||
|
args.extend(clippy_lint_levels);
|
||||||
args
|
args
|
||||||
} else {
|
} else {
|
||||||
vec![]
|
vec![]
|
||||||
|
@ -91,6 +91,10 @@ pub enum Subcommand {
|
|||||||
Clippy {
|
Clippy {
|
||||||
fix: bool,
|
fix: bool,
|
||||||
paths: Vec<PathBuf>,
|
paths: Vec<PathBuf>,
|
||||||
|
clippy_lint_allow: Vec<String>,
|
||||||
|
clippy_lint_deny: Vec<String>,
|
||||||
|
clippy_lint_warn: Vec<String>,
|
||||||
|
clippy_lint_forbid: Vec<String>,
|
||||||
},
|
},
|
||||||
Fix {
|
Fix {
|
||||||
paths: Vec<PathBuf>,
|
paths: Vec<PathBuf>,
|
||||||
@ -246,6 +250,10 @@ pub fn parse(args: &[String]) -> Flags {
|
|||||||
opts.optopt("", "rust-profile-use", "use PGO profile for rustc build", "PROFILE");
|
opts.optopt("", "rust-profile-use", "use PGO profile for rustc build", "PROFILE");
|
||||||
opts.optflag("", "llvm-profile-generate", "generate PGO profile with llvm built for rustc");
|
opts.optflag("", "llvm-profile-generate", "generate PGO profile with llvm built for rustc");
|
||||||
opts.optopt("", "llvm-profile-use", "use PGO profile for llvm build", "PROFILE");
|
opts.optopt("", "llvm-profile-use", "use PGO profile for llvm build", "PROFILE");
|
||||||
|
opts.optmulti("A", "", "allow certain clippy lints", "OPT");
|
||||||
|
opts.optmulti("D", "", "deny certain clippy lints", "OPT");
|
||||||
|
opts.optmulti("W", "", "warn about certain clippy lints", "OPT");
|
||||||
|
opts.optmulti("F", "", "forbid certain clippy lints", "OPT");
|
||||||
|
|
||||||
// We can't use getopt to parse the options until we have completed specifying which
|
// We can't use getopt to parse the options until we have completed specifying which
|
||||||
// options are valid, but under the current implementation, some options are conditional on
|
// options are valid, but under the current implementation, some options are conditional on
|
||||||
@ -544,7 +552,14 @@ pub fn parse(args: &[String]) -> Flags {
|
|||||||
}
|
}
|
||||||
Subcommand::Check { paths }
|
Subcommand::Check { paths }
|
||||||
}
|
}
|
||||||
Kind::Clippy => Subcommand::Clippy { paths, fix: matches.opt_present("fix") },
|
Kind::Clippy => Subcommand::Clippy {
|
||||||
|
paths,
|
||||||
|
fix: matches.opt_present("fix"),
|
||||||
|
clippy_lint_allow: matches.opt_strs("A"),
|
||||||
|
clippy_lint_warn: matches.opt_strs("W"),
|
||||||
|
clippy_lint_deny: matches.opt_strs("D"),
|
||||||
|
clippy_lint_forbid: matches.opt_strs("F"),
|
||||||
|
},
|
||||||
Kind::Fix => Subcommand::Fix { paths },
|
Kind::Fix => Subcommand::Fix { paths },
|
||||||
Kind::Test => Subcommand::Test {
|
Kind::Test => Subcommand::Test {
|
||||||
paths,
|
paths,
|
||||||
|
Loading…
Reference in New Issue
Block a user