@@ -80,6 +80,7 @@ mod skip_while_next;
8080mod stable_sort_primitive;
8181mod str_splitn;
8282mod string_extend_chars;
83+ mod suspicious_command_arg_space;
8384mod suspicious_map;
8485mod suspicious_splitn;
8586mod suspicious_to_owned;
@@ -3162,6 +3163,32 @@ declare_clippy_lint! {
31623163 "collecting an iterator when collect is not needed"
31633164}
31643165
3166+ declare_clippy_lint ! {
3167+ /// ### What it does
3168+ ///
3169+ /// Checks for `Command::arg()` invocations that look like they
3170+ /// should be multiple arguments instead, such as `arg("-t ext2")`.
3171+ ///
3172+ /// ### Why is this bad?
3173+ ///
3174+ /// `Command::arg()` does not split arguments by space. An argument like `arg("-t ext2")`
3175+ /// will be passed as a single argument to the command,
3176+ /// which is likely not what was intended.
3177+ ///
3178+ /// ### Example
3179+ /// ```rust
3180+ /// std::process::Command::new("echo").arg("-n hello").spawn().unwrap();
3181+ /// ```
3182+ /// Use instead:
3183+ /// ```rust
3184+ /// std::process::Command::new("echo").args(["-n", "hello"]).spawn().unwrap();
3185+ /// ```
3186+ #[ clippy:: version = "1.67.0" ]
3187+ pub SUSPICIOUS_COMMAND_ARG_SPACE ,
3188+ suspicious,
3189+ "single command line argument that looks like it should be multiple arguments"
3190+ }
3191+
31653192pub struct Methods {
31663193 avoid_breaking_exported_api : bool ,
31673194 msrv : Msrv ,
@@ -3289,6 +3316,7 @@ impl_lint_pass!(Methods => [
32893316 SEEK_FROM_CURRENT ,
32903317 SEEK_TO_START_INSTEAD_OF_REWIND ,
32913318 NEEDLESS_COLLECT ,
3319+ SUSPICIOUS_COMMAND_ARG_SPACE ,
32923320] ) ;
32933321
32943322/// Extracts a method call name, args, and `Span` of the method name.
@@ -3496,6 +3524,9 @@ impl Methods {
34963524 unnecessary_lazy_eval:: check ( cx, expr, recv, arg, "and" ) ;
34973525 }
34983526 } ,
3527+ ( "arg" , [ arg] ) => {
3528+ suspicious_command_arg_space:: check ( cx, recv, arg, span) ;
3529+ }
34993530 ( "as_deref" | "as_deref_mut" , [ ] ) => {
35003531 needless_option_as_deref:: check ( cx, expr, recv, name) ;
35013532 } ,
0 commit comments