marker icon indicating copy to clipboard operation
marker copied to clipboard

[Feat]: Provide a way to automatically fix lints with `--fix` flag

Open Veetaha opened this issue 2 years ago • 2 comments

Summary

If cargo marker is supplied with a --fix flag, then it should invoke cargo fix to automatically apply the suggestions. Other flags from cargo fix should be reexposed like --allow-dirty, --allow-staged

Workaround

One may mimic the cargo fix behavior using this script, but beware that this script uses an unstable and undocumented command cargo marker test-setup so it may not work in the future.

env -S $(cargo marker test-setup | grep -oP 'env:\K.*') cargo fix

Veetaha avatar Oct 19 '23 18:10 Veetaha

I wonder why there is a cargo fix subcommand, but clippy uses a cargo clippy --fix argument. @xFrednet do you know anything about this?

Veetaha avatar Oct 19 '23 18:10 Veetaha

Good call, this should be supported :+1:

I wonder why there is a cargo fix subcommand, but clippy uses a cargo clippy --fix argument

Rustfix can be used to migrate between editions and a few other things. When running cargo fix --edition. It will invoke rustc and turn all lints off, except the edition related ones, which are marked as --force-warn. So, it's basically to expose a richer interface than the one that a simple cargo clippy --fix exposes.

cargo fix --help gives an overview over the possible values.


Do we maybe want fix to be a sub command instead of a flag? The --allow-dirty and --allow-staged flags don't make much sense on their own. If we have fix as a sub-command, it would be cleaner, IMO.

  • cargo marker <check-args..>
  • cargo marker fix <--allow-dirty|--allow-staged|check-args..>

The downside is, that this deviates from Clippy. We could also have --fix be an argument for the normal check command, but redirect users to cargo marker fix if they want something mor fancy, like --allow-dirty or --allow-staged.


We might also want to support the --broken-code and --allow-no-vcs flags from rustfix

xFrednet avatar Oct 19 '23 21:10 xFrednet