I run clippy from the command line, and it would be very nice to be able to set all lints to deny and then whitelist lints by setting them to warn or allow as necessary:
# set all lints to deny, but allow bad_bit_mask
clippy --default deny --allow bad_bit_mask
cargo clippy is just a wrapper around rustc, which means you can do that: cargo clippy -- -D bad_bit_mask.
-D clippy -A bad_bit_mask should work
Arf, my brain was still sleeping.
Oh, very cool. Thanks!
Well we should add that in the “Allowing/denying lints” section of the README probably.
I'm not sure this is working. I'm trying to deny all by default like so:
rustup run nightly cargo clippy -- -D clippy
However I'm not hitting some lints that I know I should be, for example when I run rustup run nightly cargo clippy -D assign_ops I get a bunch of errors for assign_ops.
The allowed-by default lints are not in tge clippy, but in the clippy-pedantic group.
Sweet, that worked. Thank you!
I think it still isn't doing quite what I was hoping for. I'd like to be able to deny all by default, and then allow individual lints on a case by case basis.
I was trying to do this with cargo clippy -D clippy-pedantic -A use-debug, I'm still hitting the use-debug lint.
Of course, I could go through all of clippy's lints and -D all of the lints which are allow by default but which I want.
However, my thinking here is that if clippy adds a new lint which defaults to allow, I won't know about it, even if it's something which would be good to turn on.
This may really be more a rustc issue, since I suppose that's what's processing the allow/deny rules.
@casey: It seems like this can be made work with attributes in the root modules of a crate, e.g.:
#![deny(clippy::all)]
#![allow(clippy::module_inception)]
It would be preferable not to have them in the crate though, especially if you don't want anyone but yourself to be exercising aggressive lints in pedantic (eg: you might require contributors to only pass a weak set of lints, but you yourself use aggressive lints and perform after-the-fact fixes)
I think this issue can be closed, since allowing/denying lints on the command line is possible and documented in the README.
@kentfredric You can also do this by adding a feature to your crate and allow/deny lints behind cfg_attrs:
#![cfg_attr(aggressive_lints, deny(clippy::pedantic))]
and
cargo clippy --features aggressive_lints
https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section
@flip1995 I don't really even want reference to those lints in the source if I can avoid it.
It seems too much like the wrong place to solve it.
You can do this on the command line by calling
cargo clippy -- -Dclippy::pedantic -Aclippy::single_match ...
@flip1995: How does that interact with source code based Clippy configuration?
IIRC the precedence for lint levels is
So if you allow a lint on the command line and decline the lint in your code, the lint should trigger and produce an error.
@flip1995 I've been doing that, however, the latter '-A' gets ignored for some reason, and you still get problems with the stated lint. That's the only reason I'm active on this bug, I already tried that approach, it does not work.
cargo clippy -- -Dclippy::pedantic -Aclippy::module_name_repetitions
Checking grease v0.1.0 (/home/kent/rust/grease)
error: item name starts with its containing module's name
--> src/repository/category.rs:58:1
|
58 | / pub enum CategoryFileError {
59 | | /// A specified path did not appear to exist on the filesystem
60 | | #[fail(display = "Path <{:?}> not found", _1)]
61 | | PathNotFound(#[fail(cause)] io::Error, PathBuf),
... |
73 | | FileReadError(#[fail(cause)] io::Error, PathBuf),
74 | | }
| |_^
|
= note: `-D clippy::module-name-repetitions` implied by `-D clippy::pedantic`
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#module_name_repetitions
This came up in #4091 recently. Can you test https://github.com/rust-lang/rust-clippy/issues/4091#issuecomment-491804887 and report back in #4091?
Most helpful comment
I think it still isn't doing quite what I was hoping for. I'd like to be able to deny all by default, and then allow individual lints on a case by case basis.
I was trying to do this with
cargo clippy -D clippy-pedantic -A use-debug, I'm still hitting theuse-debuglint.Of course, I could go through all of clippy's lints and
-Dall of the lints which are allow by default but which I want.However, my thinking here is that if clippy adds a new lint which defaults to allow, I won't know about it, even if it's something which would be good to turn on.