Reputation: 3980
Is it possible to run cargo clippy
with an option so it will fix warnings automatically?
From the help message, it does not look like this option is supported at the moment.
Upvotes: 25
Views: 14020
Reputation: 3418
As of June 2021 the autofix capability has been stabilized, you can apply changes using the following command
cargo clippy --fix
Upvotes: 32
Reputation: 58745
cargo fix
can already apply some suggestions deriving from rustc
's errors and warnings.
In nightly builds you can use cargo clippy --fix
to apply some suggestions from Clippy. In some older Rust versions, the syntax is reversed: cargo fix --clippy
.
If you are using a stable version of the Rust toolchain, you can opt-in to use a nightly build for just one command, by using +nightly
to override the toolchain:
cargo +nightly clippy --fix -Z unstable-options
Upvotes: 14