heygsc
heygsc

Reputation: 98

Difference Between `cargo clippy --all --fix --allow-dirty --allow-staged` and `cargo clippy --all --tests -- -D warnings`?

Executing cargo clippy --all --fix --allow-dirty --allow-staged will automatically fix the code, but if you don't execute it, meaning you don't fix those codes, cargo clippy --all --tests -- -D warnings can pass.

Is there a difference in how the former and the latter handle the rules?

I tried looking through various documents and source code but couldn't find the answer.

I guess it's because of different scanning ranges or rule requirements, but I don't have any documentation or evidence of clip source code.

Upvotes: 0

Views: 95

Answers (1)

Kevin Reid
Kevin Reid

Reputation: 43782

From the Clippy documentation:

Clippy can automatically apply some lint suggestions, just like the compiler. Note that --fix implies --all-targets, so it can fix as much code as it can.

Thus, in order to get the same behavior without --fix, you should pass the --all-targets option.

You should also not use the --tests option, because that is a narrower target filter than --all-targets — it selects all targets that are tested by default; fromthe Target Selection section of the similar cargo check command:

Check all targets that have the test = true manifest flag set. By default this includes the library and binaries built as unittests, and integration tests.

Note that this set does not include examples. So, your command cargo clippy --all --tests -- -D warnings will fail only if Clippy finds a warning or error in any of your tested-by-default targets, and all other targets, including examples, are not checked at all.

--all-targets --tests is in practice equivalent to just --all-targets, but the --tests part is redundant, so you should leave it out.

Upvotes: 0

Related Questions