Skip to content
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

Add suspicious_command_arg_space lint #10317

Merged
merged 6 commits into from
Feb 12, 2023

Conversation

m-ou-se
Copy link
Member

@m-ou-se m-ou-se commented Feb 10, 2023

Fixes #10316


changelog: New lint: [suspicious_command_arg_space]
#10317

@rustbot
Copy link
Collaborator

rustbot commented Feb 10, 2023

r? @Manishearth

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Feb 10, 2023
clippy_lints/src/methods/mod.rs Outdated Show resolved Hide resolved
tests/ui/suspicious_command_arg_space.rs Show resolved Hide resolved
@m-ou-se m-ou-se force-pushed the suspicious-command-arg-space branch from 0a927b1 to 8f56767 Compare February 10, 2023 18:04
@Alexendoo
Copy link
Member

I did a search to look at existing usages

There are results with = in like https://github.com/bytecodealliance/wasm-tools/blob/e5293d587f463e67d42ca26b151cd7afdc0a5e17/build.rs#L17 and https://github.com/kpcyrd/sh4d0wup/blob/7043379d0a26070ecb517b3162cef84dbfd64f5a/src/codegen/go.rs#L64. I think the current impl wouldn't flag these but it'd be good to have a test case

There are some short flag usages like https://github.com/PoC-Consortium/scavenger/blob/b38f6552c31d589a0433cb8ef52a44c87ce18725/src/utils.rs#L33 but all the ones I saw are worth linting, e.g. there the format gets a leading space which is unexpected

@Manishearth
Copy link
Member

Yeah --foobar=some long string was one of the things i was thinking about which is handled but not tested

@m-ou-se
Copy link
Member Author

m-ou-se commented Feb 10, 2023

Thanks! Added test cases.

@Manishearth
Copy link
Member

error: the lint `SUSPICIOUS_COMMAND_ARG_SPACE` is not added to any `LintPass`
    --> src/methods/mod.rs:3166:1
     |
3166 | / declare_clippy_lint! {
3167 | |     /// ### What it does
3168 | |     ///
3169 | |     /// Checks for `Command::arg()` invocations that look like they
...    |
3189 | |     "single command line argument that looks like it should be multiple arguments"
3190 | | }
     | |_^
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#lint_without_lint_pass
     = note: `-D clippy::lint-without-lint-pass` implied by `-D clippy::internal`
     = note: this error originates in the macro `declare_tool_lint` which comes from the expansion of the macro `declare_clippy_lint` (in Nightly builds, run with -Z macro-backtrace for more info)

Oh, right, you also need to construct the lint pass and register it in lib.rs

@m-ou-se
Copy link
Member Author

m-ou-se commented Feb 12, 2023

Oh oops. Done.

@Manishearth
Copy link
Member

@bors r+

thanks, this is great!

@bors
Copy link
Contributor

bors commented Feb 12, 2023

📌 Commit 1f77866 has been approved by Manishearth

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Feb 12, 2023

⌛ Testing commit 1f77866 with merge 298f139...

@bors
Copy link
Contributor

bors commented Feb 12, 2023

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: Manishearth
Pushing 298f139 to master...

@bors bors merged commit 298f139 into rust-lang:master Feb 12, 2023
@m-ou-se m-ou-se deleted the suspicious-command-arg-space branch February 13, 2023 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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