Skip to content

Warn when passing what looks like multiple arguments to a single std::process::Command::arg(...) call #10316

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

Closed
HayleyDeckers opened this issue Feb 10, 2023 · 0 comments · Fixed by #10317
Labels
A-lint Area: New lints

Comments

@HayleyDeckers
Copy link

What it does

Emit a warning when an argument of the form "-x foo", "--abc bar", /X baz, or a concatenation of these is passed to std::process::Command::arg(...) and suggest to use either multiple arg calls or a single args call instead.

In these cases the programmer likely intended to pass multiple args to the process, and probably wants to use something like std::process::Command::args(["-x", "foo"]) instead.

Lint Name

possible_multiple_args_in_arg

Category

suspicious

Advantage

  • prevent unintended behavior when executing other processes with Command.

Drawbacks

This lint will by design always have some false-positives as Clippy can't be sure this isn't what you wanted to do.

Example

std::process::Command::new("mkdir")
        .arg("-p foo/bar")

Could be written as:

std::process::Command::new("mdkir")
        .args(["-p", "foo/bar"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant