Skip to content

Commit e3d84b2

Browse files
authored
clippy argument support
1 parent cd73afa commit e3d84b2

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/bootstrap/check.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ fn args(builder: &Builder<'_>) -> Vec<String> {
2020
arr.iter().copied().map(String::from)
2121
}
2222

23-
if let Subcommand::Clippy { fix, .. } = builder.config.cmd {
23+
if let Subcommand::Clippy {
24+
fix,
25+
clippy_lint_allow,
26+
clippy_lint_deny,
27+
clippy_lint_warn,
28+
clippy_lint_forbid,
29+
..
30+
} = &builder.config.cmd
31+
{
2432
// disable the most spammy clippy lints
2533
let ignored_lints = vec![
2634
"many_single_char_names", // there are a lot in stdarch
@@ -32,7 +40,7 @@ fn args(builder: &Builder<'_>) -> Vec<String> {
3240
"wrong_self_convention",
3341
];
3442
let mut args = vec![];
35-
if fix {
43+
if *fix {
3644
#[rustfmt::skip]
3745
args.extend(strings(&[
3846
"--fix", "-Zunstable-options",
@@ -44,6 +52,12 @@ fn args(builder: &Builder<'_>) -> Vec<String> {
4452
}
4553
args.extend(strings(&["--", "--cap-lints", "warn"]));
4654
args.extend(ignored_lints.iter().map(|lint| format!("-Aclippy::{}", lint)));
55+
let mut clippy_lint_levels: Vec<String> = Vec::new();
56+
clippy_lint_allow.iter().for_each(|v| clippy_lint_levels.push(format!("-A{}", v)));
57+
clippy_lint_deny.iter().for_each(|v| clippy_lint_levels.push(format!("-D{}", v)));
58+
clippy_lint_warn.iter().for_each(|v| clippy_lint_levels.push(format!("-W{}", v)));
59+
clippy_lint_forbid.iter().for_each(|v| clippy_lint_levels.push(format!("-F{}", v)));
60+
args.extend(clippy_lint_levels);
4761
args
4862
} else {
4963
vec![]

src/bootstrap/flags.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ pub enum Subcommand {
9191
Clippy {
9292
fix: bool,
9393
paths: Vec<PathBuf>,
94+
clippy_lint_allow: Vec<String>,
95+
clippy_lint_deny: Vec<String>,
96+
clippy_lint_warn: Vec<String>,
97+
clippy_lint_forbid: Vec<String>,
9498
},
9599
Fix {
96100
paths: Vec<PathBuf>,
@@ -240,6 +244,10 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
240244
opts.optopt("", "rust-profile-use", "use PGO profile for rustc build", "PROFILE");
241245
opts.optflag("", "llvm-profile-generate", "generate PGO profile with llvm built for rustc");
242246
opts.optopt("", "llvm-profile-use", "use PGO profile for llvm build", "PROFILE");
247+
opts.optmulti("A", "", "allow certain clippy lints", "OPT");
248+
opts.optmulti("D", "", "deny certain clippy lints", "OPT");
249+
opts.optmulti("W", "", "warn about certain clippy lints", "OPT");
250+
opts.optmulti("F", "", "forbid certain clippy lints", "OPT");
243251

244252
// We can't use getopt to parse the options until we have completed specifying which
245253
// options are valid, but under the current implementation, some options are conditional on
@@ -538,7 +546,14 @@ Arguments:
538546
}
539547
Subcommand::Check { paths }
540548
}
541-
Kind::Clippy => Subcommand::Clippy { paths, fix: matches.opt_present("fix") },
549+
Kind::Clippy => Subcommand::Clippy {
550+
paths,
551+
fix: matches.opt_present("fix"),
552+
clippy_lint_allow: matches.opt_strs("A"),
553+
clippy_lint_warn: matches.opt_strs("W"),
554+
clippy_lint_deny: matches.opt_strs("D"),
555+
clippy_lint_forbid: matches.opt_strs("F"),
556+
},
542557
Kind::Fix => Subcommand::Fix { paths },
543558
Kind::Test => Subcommand::Test {
544559
paths,

0 commit comments

Comments
 (0)