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

add --fix support to cargo-clippy #5363

Merged
merged 13 commits into from
Apr 15, 2020
31 changes: 28 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,38 @@ where
{
let mut args = vec!["check".to_owned()];

let mut fix = false;
let mut unstable_options = false;

for arg in old_args.by_ref() {
if arg == "--" {
break;
match arg.as_str() {
"--fix" => {
fix = true;
continue;
},
"--" => break,
// Cover -Zunstable-options and -Z unstable-options
s if s.ends_with("unstable-options") => unstable_options = true,
_ => {},
}

args.push(arg);
}

if fix {
if unstable_options {
args[0] = "fix".to_owned();
} else {
panic!("Usage of `--fix` requires `-Z unstable-options`");
}
}
yaahc marked this conversation as resolved.
Show resolved Hide resolved

let path_env = if unstable_options {
"RUSTC_WORKSPACE_WRAPPER"
} else {
"RUSTC_WRAPPER"
};

let clippy_args: String = old_args.map(|arg| format!("{}__CLIPPY_HACKERY__", arg)).collect();

let mut path = std::env::current_exe()
Expand Down Expand Up @@ -96,7 +121,7 @@ where

let exit_status = std::process::Command::new("cargo")
.args(&args)
.env("RUSTC_WRAPPER", path)
.env(path_env, path)
.env("CLIPPY_ARGS", clippy_args)
.envs(target_dir)
.spawn()
Expand Down