You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to run Clippy in pre-commit checks and CI too, and in these situations, I want it to fail (exit with a non-zero status code) if any warnings are encountered.
Currently I have two ways of doing this:
using something like sed to rewrite Cargo.toml, replacing "warn" with "deny", or
using flags to override the lints.
Neither of these seem great. Using sed is error-prone, especially when running it locally in a pre-commit hook, and if I use flags, I have to re-specify all of the "allow" lints, which means I probably have to generate the command-line arguments programmatically.
I would like a command-line argument that tells Clippy to fail on warnings instead. I suggest --exit-with-failure-on-warnings, though you may prefer something more terse.
I am happy to attempt to work on this feature myself, but I would like to discuss it to ensure that the maintainers of Clippy agree in principle first.
If I am missing an obvious way to achieve this, please let me know!
@Alexendoo, I didn't know that would work with Clippy warnings. Thanks!
This is a good solution for CI but as it's a change to the rustc flags, it requires recompiling all dependencies, which is kind of unworkable for a pre-commit check.
It sounds like the Cargo flag is the proposed solution already though, and reading through it, I get the impression it's intended to only apply to local crates, not dependencies, so I think it will address the above issue.
Do you think this issue should be closed, then, and converted to a comment on the Cargo issue?
You could try cargo clippy -- -D warnings for such a hook, I believe that would avoid recompiling dependencies.
Yeah the cargo issue would be the place to look at for a solution that works everywhere in cargo, but I think that should suit your needs on the clippy side of things.
As an aside priority in [lints] can be negative so you only have to set it for groups, e.g.
[workspace.lints.clippy]
pedantic = { level = "warn", priority = -1 }
# disable some pedantic warnings which feel a little too pedanticdoc_markdown = "allow"missing_errors_doc = "allow"# ...
Description
We can now configure the various levels of each lint option in Cargo.toml. I currently have one that looks like this:
I want to run Clippy in pre-commit checks and CI too, and in these situations, I want it to fail (exit with a non-zero status code) if any warnings are encountered.
Currently I have two ways of doing this:
sed
to rewrite Cargo.toml, replacing"warn"
with"deny"
, orNeither of these seem great. Using
sed
is error-prone, especially when running it locally in a pre-commit hook, and if I use flags, I have to re-specify all of the "allow" lints, which means I probably have to generate the command-line arguments programmatically.I would like a command-line argument that tells Clippy to fail on warnings instead. I suggest
--exit-with-failure-on-warnings
, though you may prefer something more terse.I am happy to attempt to work on this feature myself, but I would like to discuss it to ensure that the maintainers of Clippy agree in principle first.
If I am missing an obvious way to achieve this, please let me know!
Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: