[英]Can Rust's clippy do autocorrection / autofix?
Is it possible to run cargo clippy
with an option so it will fix warnings automatically?是否可以使用选项运行cargo clippy
以便自动修复警告?
From the help message, it does not look like this option is supported at the moment.从帮助消息来看,目前似乎不支持此选项。
cargo fix
can already apply some suggestions deriving from rustc
's errors and warnings. cargo fix
已经可以应用一些来自rustc
的错误和警告的建议。
In nightly builds, since Rust 1.38 — that is, since Rust 1.40-nightly — you can use cargo fix --clippy
to apply certain suggestions from Clippy too. 在每晚构建中,由于Rust 1.38 (即Rust 1.40每晚)以来,您也可以使用cargo fix --clippy
来应用来自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: 如果您使用的是Rust工具链的稳定版本,则可以选择使用夜间构建来仅使用一个命令,方法是使用+nightly
覆盖工具链:
cargo +nightly fix --clippy -Z unstable-options
截至 2021 年 6 月,自动修复功能已稳定,您可以使用以下命令应用更改
cargo clippy --fix
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.