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

we need an automated fix for clippy warnings #457

Open
rminnich opened this issue Jul 8, 2021 · 2 comments
Open

we need an automated fix for clippy warnings #457

rminnich opened this issue Jul 8, 2021 · 2 comments
Labels

Comments

@rminnich
Copy link
Member

rminnich commented Jul 8, 2021

Right now, if clippy finds issues like excessive parens, it will complain.

But no invocation of clippy fix will fix it.

We need a way to fix ALL warnings that clippy generates.

@rjoleary
Copy link
Contributor

rjoleary commented Jul 8, 2021

https://stackoverflow.com/questions/53670348/can-rusts-clippy-do-autocorrection-autofix shows multiple possibly ways to auto fix clippy issues.

Perhaps:

First you need to install clippy nightly (rustup component add clippy --toolchain nightly-x86_64-unknown-linux-gnu), and after that run it with: cargo +nightly clippy --fix -Z unstable-options

Or perhaps try this if it's now stable:

cargo clippy --fix

@rjoleary
Copy link
Contributor

rjoleary commented Jul 8, 2021

This seemed to work for me:

diff --git a/Makefile b/Makefile
index 88c99cda0c..40a269d3e9 100644
--- a/Makefile
+++ b/Makefile
@@ -116,7 +116,7 @@ BROKEN_CRATES_TO_CLIPPY := \
 # TODO: Remove write_with_newline
 CRATES_TO_CLIPPY := $(patsubst %/Cargo.toml,%/Cargo.toml.clippy,$(filter-out $(BROKEN_CRATES_TO_CLIPPY),$(CRATES)))
 $(CRATES_TO_CLIPPY):
-       cd $(dir $@) && cargo clippy -- -D warnings -A clippy::write_with_newline
+       cd $(dir $@) && cargo clippy --allow-dirty --fix -Z unstable-options -- -D warnings -A clippy::write_with_newline
 .PHONY: clippy $(CRATES_TO_CLIPPY)
 clippy: $(CRATES_TO_CLIPPY)
  • --fix: Automatically fixes clippy issues
  • -Z unstable-options: Because of the error "Usage of --fix requires `-Z unstable-options"
  • --allow-dirty: Because the error "the working directory of this package has uncommitted changes, and cargo fix can potentially perform destructive changes; if you'd like to suppress this error pass --allow-dirty, --allow-staged, or commit the changes to these files:"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants