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

Add option to set all lints to allow/warn/deny on command line #1340

Closed
casey opened this issue Nov 12, 2016 · 19 comments
Closed

Add option to set all lints to allow/warn/deny on command line #1340

casey opened this issue Nov 12, 2016 · 19 comments

Comments

@casey
Copy link

casey commented Nov 12, 2016

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
@mcarton
Copy link
Member

mcarton commented Nov 12, 2016

cargo clippy is just a wrapper around rustc, which means you can do that: cargo clippy -- -D bad_bit_mask.

@Manishearth
Copy link
Member

-D clippy -A bad_bit_mask should work

@mcarton
Copy link
Member

mcarton commented Nov 12, 2016

Arf, my brain was still sleeping.

@casey
Copy link
Author

casey commented Nov 12, 2016

Oh, very cool. Thanks!

@casey casey closed this as completed Nov 12, 2016
@mcarton
Copy link
Member

mcarton commented Nov 12, 2016

Well we should add that in the “Allowing/denying lints” section of the README probably.

@mcarton mcarton reopened this Nov 12, 2016
@casey
Copy link
Author

casey commented Nov 13, 2016

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.

@llogiq
Copy link
Contributor

llogiq commented Nov 13, 2016

The allowed-by default lints are not in tge clippy, but in the clippy-pedantic group.

@casey
Copy link
Author

casey commented Nov 13, 2016

Sweet, that worked. Thank you!

@casey
Copy link
Author

casey commented Nov 13, 2016

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.

@casey
Copy link
Author

casey commented Nov 14, 2016

This may really be more a rustc issue, since I suppose that's what's processing the allow/deny rules.

@soenkehahn
Copy link

soenkehahn commented Feb 27, 2019

@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)]

@kentfredric
Copy link

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)

@flip1995
Copy link
Member

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

@kentfredric
Copy link

@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.

@flip1995
Copy link
Member

flip1995 commented May 29, 2019

You can do this on the command line by calling

cargo clippy -- -Dclippy::pedantic -Aclippy::single_match ...

@sanmai-NL
Copy link
Contributor

@flip1995: How does that interact with source code based Clippy configuration?

@flip1995
Copy link
Member

IIRC the precedence for lint levels is

  • comand line
  • crate
  • module
  • items

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.

@kentfredric
Copy link

@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

@flip1995
Copy link
Member

This came up in #4091 recently. Can you test #4091 (comment) and report back in #4091?

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

No branches or pull requests

8 participants