Make --fix imply --no-deps

This commit is contained in:
Eduardo Broto 2020-11-27 16:53:30 +01:00
parent 7eda421e96
commit a83eb7ca99

View File

@ -62,7 +62,7 @@ struct ClippyCmd {
unstable_options: bool,
cargo_subcommand: &'static str,
args: Vec<String>,
clippy_args: String,
clippy_args: Vec<String>,
}
impl ClippyCmd {
@ -99,7 +99,10 @@ impl ClippyCmd {
args.insert(0, "+nightly".to_string());
}
let clippy_args: String = old_args.map(|arg| format!("{}__CLIPPY_HACKERY__", arg)).collect();
let mut clippy_args: Vec<String> = old_args.collect();
if cargo_subcommand == "fix" && !clippy_args.iter().any(|arg| arg == "--no-deps") {
clippy_args.push("--no-deps".into());
}
ClippyCmd {
unstable_options,
@ -147,10 +150,15 @@ impl ClippyCmd {
fn into_std_cmd(self) -> Command {
let mut cmd = Command::new("cargo");
let clippy_args: String = self
.clippy_args
.iter()
.map(|arg| format!("{}__CLIPPY_HACKERY__", arg))
.collect();
cmd.env(self.path_env(), Self::path())
.envs(ClippyCmd::target_dir())
.env("CLIPPY_ARGS", self.clippy_args)
.env("CLIPPY_ARGS", clippy_args)
.arg(self.cargo_subcommand)
.args(&self.args);
@ -201,6 +209,24 @@ mod tests {
assert!(cmd.args.iter().any(|arg| arg.ends_with("unstable-options")));
}
#[test]
fn fix_implies_no_deps() {
let args = "cargo clippy --fix -Zunstable-options"
.split_whitespace()
.map(ToString::to_string);
let cmd = ClippyCmd::new(args);
assert!(cmd.clippy_args.iter().any(|arg| arg == "--no-deps"));
}
#[test]
fn no_deps_not_duplicated_with_fix() {
let args = "cargo clippy --fix -Zunstable-options -- --no-deps"
.split_whitespace()
.map(ToString::to_string);
let cmd = ClippyCmd::new(args);
assert_eq!(cmd.clippy_args.iter().filter(|arg| *arg == "--no-deps").count(), 1);
}
#[test]
fn check() {
let args = "cargo clippy".split_whitespace().map(ToString::to_string);