Skip to content

Commit 601c5a2

Browse files
authored
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`.
2 parents 38b7215 + e3d84b2 commit 601c5a2

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>,
@@ -246,6 +250,10 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
246250
opts.optopt("", "rust-profile-use", "use PGO profile for rustc build", "PROFILE");
247251
opts.optflag("", "llvm-profile-generate", "generate PGO profile with llvm built for rustc");
248252
opts.optopt("", "llvm-profile-use", "use PGO profile for llvm build", "PROFILE");
253+
opts.optmulti("A", "", "allow certain clippy lints", "OPT");
254+
opts.optmulti("D", "", "deny certain clippy lints", "OPT");
255+
opts.optmulti("W", "", "warn about certain clippy lints", "OPT");
256+
opts.optmulti("F", "", "forbid certain clippy lints", "OPT");
249257

250258
// We can't use getopt to parse the options until we have completed specifying which
251259
// options are valid, but under the current implementation, some options are conditional on
@@ -544,7 +552,14 @@ Arguments:
544552
}
545553
Subcommand::Check { paths }
546554
}
547-
Kind::Clippy => Subcommand::Clippy { paths, fix: matches.opt_present("fix") },
555+
Kind::Clippy => Subcommand::Clippy {
556+
paths,
557+
fix: matches.opt_present("fix"),
558+
clippy_lint_allow: matches.opt_strs("A"),
559+
clippy_lint_warn: matches.opt_strs("W"),
560+
clippy_lint_deny: matches.opt_strs("D"),
561+
clippy_lint_forbid: matches.opt_strs("F"),
562+
},
548563
Kind::Fix => Subcommand::Fix { paths },
549564
Kind::Test => Subcommand::Test {
550565
paths,

0 commit comments

Comments
 (0)