From b8fc2d2792983218bbe51b1e587beaf486f37ec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 10 Sep 2022 23:41:51 +0200 Subject: [PATCH 1/2] BREAKING CHANGE fix running path/to/cargo-clippy --fix Previously, we would assume clippy is called as "cargo clippy --arg1 --arg2" so we stripped the first two items and parsed "--arg1" and "--arg2" as cmdline args. The problem is when we run cargo-clippy binary directly as "target/debug/cargo-clippy --arg1 --arg2", we would still remove the first two args which would be "..cargo-clippy" and "--arg1" in this case which is wrong. Fix this by checking if we run clippy via "cargo clippy" or "../path/to/cargo-clippy" and for the latter, only skip the first arg instead of two. Spotted by Kraktus because lintcheck --fix was no longer working This is potentially a breaking change because the "target/debug/cargo-clippy clippy --fix" will no longer work! Use "target/debug/cargo-clippy --fix" directly instead. changelog: fix "cargo-clippy --foo" omitting the first flag, break "../cargo-clippy clippy --foo" which will now complain about the "clippy" arg. --- src/main.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 4a32e0e54a81..abff6ebeddca 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ #![cfg_attr(feature = "deny-warnings", deny(warnings))] +#![feature(let_chains)] // warn on lints, that are included in `rust-lang/rust`s bootstrap #![warn(rust_2018_idioms, unused_lifetimes)] @@ -67,7 +68,16 @@ pub fn main() { return; } - if let Err(code) = process(env::args().skip(2)) { + // if we run "cargo clippy" (as cargo subcommand), we have to strip "cargo clippy" (first 2 args) + // but if we are run via "..../target/debug/cargo-clippy", only ommit the first arg, the second one + // might be a normal cmdline arg already (which we don't want to ommit) + let args = if let Some(first_arg) = env::args().next() && first_arg.ends_with("cargo-clippy") { + env::args().skip(1) + } else { + env::args().skip(2) + }; + + if let Err(code) = process(args) { process::exit(code); } } @@ -204,4 +214,14 @@ mod tests { let cmd = ClippyCmd::new(args); assert_eq!("check", cmd.cargo_subcommand); } + + #[test] + fn dont_skip_arg() { + let args = "target/debug/cargo-clippy --fix" + .split_whitespace() + .map(ToString::to_string); + let cmd = ClippyCmd::new(args); + assert_eq!("fix", cmd.cargo_subcommand); + assert!(!cmd.args.iter().any(|arg| arg.ends_with("unstable-options"))); + } } From 5b7934d4bd867da96e087dbb2225c4b20ae23112 Mon Sep 17 00:00:00 2001 From: kraktus Date: Sun, 11 Sep 2022 11:41:28 +0200 Subject: [PATCH 2/2] fix clippy arguments when running `lintcheck` --- lintcheck/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lintcheck/src/main.rs b/lintcheck/src/main.rs index 9ee25280f046..d7e35a1bbfa8 100644 --- a/lintcheck/src/main.rs +++ b/lintcheck/src/main.rs @@ -337,9 +337,9 @@ impl Crate { let shared_target_dir = clippy_project_root().join("target/lintcheck/shared_target_dir"); let mut args = if config.fix { - vec!["--fix", "--"] + vec!["--fix", "--allow-no-vcs", "--"] } else { - vec!["--", "--message-format=json", "--"] + vec!["--message-format=json", "--"] }; if let Some(options) = &self.options {