Skip to content

Commit

Permalink
Make --fix imply --no-deps
Browse files Browse the repository at this point in the history
  • Loading branch information
ebroto committed Nov 27, 2020
1 parent 86f9fbb commit 506ae4f
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 506ae4f

Please sign in to comment.