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

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

Open
Veetaha opened this issue Oct 19, 2023 · 2 comments
Open

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

Veetaha opened this issue Oct 19, 2023 · 2 comments
Labels
A-marker-cargo Area: All things connected to `cargo_marker` C-enhancement Category: New feature or request

Comments

@Veetaha
Copy link
Contributor

Veetaha commented Oct 19, 2023

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 Veetaha added C-enhancement Category: New feature or request S-needs-triage Status: This issue needs triage labels Oct 19, 2023
@Veetaha
Copy link
Contributor Author

Veetaha commented Oct 19, 2023

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

@xFrednet
Copy link
Member

Good call, this should be supported 👍

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 xFrednet added A-marker-cargo Area: All things connected to `cargo_marker` and removed S-needs-triage Status: This issue needs triage labels Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-marker-cargo Area: All things connected to `cargo_marker` C-enhancement Category: New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants