Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support -A, -W, -D and -F when running ./x.py clippy #97210

Merged
merged 1 commit into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/bootstrap/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ fn args(builder: &Builder<'_>) -> Vec<String> {
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
let ignored_lints = vec![
"many_single_char_names", // there are a lot in stdarch
Expand All @@ -32,7 +40,7 @@ fn args(builder: &Builder<'_>) -> Vec<String> {
"wrong_self_convention",
];
let mut args = vec![];
if fix {
if *fix {
#[rustfmt::skip]
args.extend(strings(&[
"--fix", "-Zunstable-options",
Expand All @@ -44,6 +52,12 @@ fn args(builder: &Builder<'_>) -> Vec<String> {
}
args.extend(strings(&["--", "--cap-lints", "warn"]));
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
} else {
vec![]
Expand Down
17 changes: 16 additions & 1 deletion src/bootstrap/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ pub enum Subcommand {
Clippy {
fix: bool,
paths: Vec<PathBuf>,
clippy_lint_allow: Vec<String>,
clippy_lint_deny: Vec<String>,
clippy_lint_warn: Vec<String>,
clippy_lint_forbid: Vec<String>,
},
Fix {
paths: Vec<PathBuf>,
Expand Down Expand Up @@ -240,6 +244,10 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
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.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
// options are valid, but under the current implementation, some options are conditional on
Expand Down Expand Up @@ -538,7 +546,14 @@ Arguments:
}
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::Test => Subcommand::Test {
paths,
Expand Down