Skip to content

BREAKING CHANGE fix running path/to/cargo-clippy --fix #9461

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -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)]

Expand Down Expand Up @@ -43,7 +44,23 @@ 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") || first_arg.ends_with("cargo-clippy.exe"))
{
// turn this of during the migration
// env::args().skip(1)
eprintln!(
"WARNING: potentially breaking change: 'cargo-clippy arg1 arg2...' will no longer ignore 'arg1' after edition=2024"
);
env::args().skip(2)
} else {
env::args().skip(2)
};

if let Err(code) = process(args) {
Comment on lines -46 to +63
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔

process::exit(code);
}
}
Expand Down Expand Up @@ -216,4 +233,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")));
}
}
1 change: 0 additions & 1 deletion tests/dogfood.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ fn run_clippy_for_package(project: &str, args: &[&str]) -> bool {
command
.current_dir(root_dir.join(project))
.env("CARGO_INCREMENTAL", "0")
.arg("clippy")
.arg("--all-targets")
.arg("--all-features");

Expand Down
3 changes: 0 additions & 3 deletions tests/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ fn test_no_deps_ignores_path_deps_in_workspaces() {
.current_dir(&cwd)
.env("CARGO_INCREMENTAL", "0")
.env("CARGO_TARGET_DIR", &target_dir)
.arg("clippy")
.args(["-p", "subcrate"])
.arg("--no-deps")
.arg("--")
Expand All @@ -91,7 +90,6 @@ fn test_no_deps_ignores_path_deps_in_workspaces() {
.current_dir(&cwd)
.env("CARGO_INCREMENTAL", "0")
.env("CARGO_TARGET_DIR", &target_dir)
.arg("clippy")
.args(["-p", "subcrate"])
.arg("--")
.arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
Expand All @@ -118,7 +116,6 @@ fn test_no_deps_ignores_path_deps_in_workspaces() {
.current_dir(&cwd)
.env("CARGO_INCREMENTAL", "0")
.env("CARGO_TARGET_DIR", &target_dir)
.arg("clippy")
.args(["-p", "subcrate"])
.arg("--")
.arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
Expand Down
Loading