From f873a884b1cb50f4dcd45d88a9fedb3cde070461 Mon Sep 17 00:00:00 2001 From: Ousama Ben Younes Date: Wed, 11 Mar 2026 20:18:37 +0000 Subject: [PATCH] fix: prevent double `--` separator in cargo clippy with -p flags When running `rtk cargo clippy -p my-crate -- -D warnings`, Clap with `trailing_var_arg = true` preserves the `--` in parsed args when flags precede it. `restore_double_dash()` then added a second `--`, producing `cargo clippy -p my-crate -- -- -D warnings`. This caused rustc to interpret `-D` as a filename instead of a lint flag. Fix: skip restoration when args already contain `--` (Clap preserved it). Fixes #496 Co-Authored-By: Claude Opus 4.6 Signed-off-by: Ousama Ben Younes --- src/cargo_cmd.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/cargo_cmd.rs b/src/cargo_cmd.rs index ed0734eb3..5f55fa40a 100644 --- a/src/cargo_cmd.rs +++ b/src/cargo_cmd.rs @@ -40,6 +40,11 @@ fn restore_double_dash_with_raw(args: &[String], raw_args: &[String]) -> Vec pos, @@ -1054,6 +1059,42 @@ mod tests { assert_eq!(result, vec!["--", "-D", "warnings"]); } + #[test] + fn test_restore_double_dash_clippy_with_package_flags() { + // rtk cargo clippy -p my-service -p my-crate -- -D warnings + // Clap with trailing_var_arg preserves "--" when args precede it + // → clap gives ["-p", "my-service", "-p", "my-crate", "--", "-D", "warnings"] + let args: Vec = vec![ + "-p".into(), + "my-service".into(), + "-p".into(), + "my-crate".into(), + "--".into(), + "-D".into(), + "warnings".into(), + ]; + let raw = vec![ + "rtk".into(), + "cargo".into(), + "clippy".into(), + "-p".into(), + "my-service".into(), + "-p".into(), + "my-crate".into(), + "--".into(), + "-D".into(), + "warnings".into(), + ]; + let result = restore_double_dash_with_raw(&args, &raw); + // Should NOT double the "--" + assert_eq!( + result, + vec!["-p", "my-service", "-p", "my-crate", "--", "-D", "warnings"] + ); + // Verify only one "--" exists + assert_eq!(result.iter().filter(|a| *a == "--").count(), 1); + } + #[test] fn test_filter_cargo_build_success() { let output = r#" Compiling libc v0.2.153