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 { 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"))); + } }