- Currently, I use VSCode as my IDE when programming Rust.
- I use the
rust-analyzerVSCode extension, since it seems to be the best one out there for Rust (as of 2022).
I have the following two entries in my "settings.json" for VSCode:
{
"rust-analyzer.checkOnSave.command": "clippy",
"[rust]": {
"editor.formatOnSave": true,
},
}
- This makes it so that
clippy(the linter) runs automatically upon pressing Ctrl + s to save the file. - It also makes it so that
rustfmt(the formatter) runs automatically upon pressing Ctrl + s to save the file.
In addition to these two things, I also want cargo fix to run automatically upon pressing Ctrl + s to save the file, because doing that automatically cleans up unused imports.
How can I accomplish this?
(I want unused imports to be automatically cleaned up for the same reason that I want an automatic formatter. Manually removing unused imports is tedium and a complete waste of my time in the same way that manually adding the appropriate amount of tabs or spaces is.)