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

-A should override -W when it appears later on the command line #4091

Closed
zackw opened this issue May 13, 2019 · 3 comments · Fixed by rust-lang/rust#67885
Closed

-A should override -W when it appears later on the command line #4091

zackw opened this issue May 13, 2019 · 3 comments · Fixed by rust-lang/rust#67885

Comments

@zackw
Copy link

zackw commented May 13, 2019

When more than one -A, -D, or -W option in a clippy invocation refers to the same lint, either directly or indirectly, whichever one came last on the command line should win. The most important reason for this is so you can enable a category of warnings that's off by default, but then turn some of them back off again. For example, suppose src/demo.rs is this:

pub fn demo() -> &'static str {
    "παράδειγμα"
}

then this invocation should not complain about the non-ASCII characters in the string literal, but currently it does:

$ cargo clippy -- -W clippy::pedantic -A clippy::non-ascii-literal
warning: literal non-ASCII character detected
 --> src/demo.rs:2:5
  |
2 |     "παράδειγμα"
  |     ^^^^^^^^^^^^
  |
  = note: `-W clippy::non-ascii-literal` implied by `-W clippy::pedantic`
...

One might also want to be able to do -D warnings -A clippy::something_specific or -W clippy::all -D clippy::particular_bad_thing.

Version information:

$ cargo clippy -V
clippy 0.0.212 (726176e 2019-04-18)
@flip1995
Copy link
Member

Does this work with rustc lints? E.g:

cargo check -- -D warnings -A unused
// main.rs
fn main() {
    let x = 42;
}

Otherwise this would be a rustc issue, since the flags are handled by rustc and just forwarded to Clippy.

@MikailBag
Copy link

I have same problem.
This code:

Command::new("cargo")
        .args(&[
            "clippy",
            "--all",
            "--tests",
            "--",
            "-Dclippy::all",
            "-Aclippy::new-without-default",
            "-Dwarnings",
        ])

does not prevent Clippy from giving me error:

error: you should consider adding a `Default` implementation for `global::GlobalState`

  --> src/frontend-engine/src/global.rs:15:5
...
   = note: `-D clippy::new-without-default` implied by `-D clippy::all`

As for rustc lints, overriding seems to work fine:
image

@casey
Copy link

casey commented Jan 5, 2020

A workaround is to use annotations, where a specific allow will override a more general deny. For example:

#![deny(clippy::pedantic)]
#![allow(clippy::enum_glob_use)]

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

Successfully merging a pull request may close this issue.

4 participants