-
Notifications
You must be signed in to change notification settings - Fork 18
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
Be able to disable/enable Clippy lints globally #22
Comments
Ran into this again today with trying to upgrade to Rust 1.34 and where the redundant_closure had been enabled. All the cases it triggered on was for small member wrapper functions for simple conversions and where it would be a lot more verbose and quite annoying to use the full written out types, examples:
We also had a few of these cases where the suggested code didn't work because the types it suggested didn't have the Regardless, this is a case where we would like to disable the |
We now have 81 crates in our monorepo, all having to specify |
@repi I ran into this myself for a project I am working on. When running Clippy you can disable lints via the CLI. I ended up putting this in an already existing Makefile, for example:
Here the Clippy also supports using a configuration file, but last I checked you can't disable lints using it. |
@yorickpeterse thanks, that does look like a workable solution for CI. Though for working locally for users and with tools like RLS I really want a solution where everyone can just run |
@repi There is a discussion about adding support for enabling/disabling lints in |
Yeah doesn't look like very active development of it unfortunately, but hope Cargo/Clippy gets it eventually. Just added these lines on top of 30 lib.rs files in our workspace to enable more lints for our codebase.
Copy'n'paste is not pretty, but works. |
This is getting a bit more silly without this support, we have like 30 crates in our repo where all of their #![forbid(unsafe_code)]
#![warn(
clippy::all,
clippy::doc_markdown,
clippy::dbg_macro,
clippy::todo,
clippy::empty_enum,
clippy::enum_glob_use,
clippy::pub_enum_variant_names,
clippy::mem_forget,
clippy::use_self,
clippy::filter_map_next,
clippy::needless_continue,
clippy::needless_borrow,
clippy::match_wildcard_for_single_variants,
clippy::if_let_mutex,
clippy::mismatched_target_os,
clippy::await_holding_lock,
clippy::match_on_vec_items,
clippy::imprecise_flops,
clippy::suboptimal_flops,
clippy::lossy_float_literal,
clippy::rest_pat_in_fully_bound_structs,
clippy::fn_params_excessive_bools,
clippy::exit,
clippy::inefficient_to_string,
clippy::linkedlist,
clippy::macro_use_imports,
clippy::option_option,
clippy::verbose_file_reads,
clippy::unnested_or_patterns,
rust_2018_idioms,
future_incompatible,
nonstandard_style
)] Does work though! |
We now have ~170 crates across ~20 repositories so have an even larger list of Clippy lints we enable by default across them now scattered and duplicated across 170 locations, which makes it hard to add and esp easy to miss when creating new crates. We really do need the proper Cargo/Clippy solution for a |
We had a good sync with the Clippy team a couple of weeks ago and this is one of the top issues in the Clippy 2021 Roadmap! |
omg yes! |
We finally have a workaround for this that works quite well that we are transitioning our projects for, and that is to use [target.'cfg(all())']
rustflags = [
# BEGIN - Embark standard lints v0.4
# do not change or add/remove here, but one can add exceptions after this section
# for more info see: <https://github.com/EmbarkStudios/rust-ecosystem/issues/59>
"-Dunsafe_code",
"-Wclippy::all",
"-Wclippy::await_holding_lock",
"-Wclippy::char_lit_as_u8",
] from #68. There are some tradeoffs with this approach but overall it works well and dramatically easier to maintain and work with, our main private repo with 80+ crates no longer have to specify our long list of standard lints in every lib.rs/main.rs. Still would prefer proper Cargo support of a So will leave this issue open for now, but tagged as |
There seems to be a downside to this in that it only works as of Rust 1.55 (earlier versions raise an error when using |
Ah interesting, we are on Rust 1.55 and now with our v5 lint set (#67) it also requires 1.55 as we use new lints from it. Thought initially this approach wouldn't work as also believed that Cargo/Rust would have failed on those unknown clippy lints that only clippy knows about, but was glad to see that it didn't well at least not with 1.55. But good to know that it seems to require 1.55 so must have been a change in how they handle the allow/deny flags (hopefully an intentional one). |
Maybe it's fallout from rustdoc lints being moved to their own namespace a few versions earlier, and people wanting to keep activating them (with new names) in some way where they would be passed to non-rustdoc invocations. It's definitely a reasonable change to just ignore unknown tool-specific lints so I'm sure it will be kept even if it wasn't intentional 😄 |
Using the trick documented here: EmbarkStudios/rust-ecosystem#22 (comment)
Using the trick documented here: EmbarkStudios/rust-ecosystem#22 (comment)
Currently it is not directly possible to configure lints for the entire workspace via TOML, which forced us to repeat `#![allow]` blocks in each crate. embark pointed out this workaround to configure lints at the workspace level via RUSTFLAGS: EmbarkStudios/rust-ecosystem#22 (comment) Remove the common `#![allow]` blocks and switch to this method for global lint config. Temporarily allow `needless_borrow` lint, buggy pending this fix: rust-lang/rust-clippy#8355
Currently it is not directly possible to configure lints for the entire workspace via TOML, which forced us to repeat `#![allow]` blocks in each crate. embark pointed out this workaround to configure lints at the workspace level via RUSTFLAGS: EmbarkStudios/rust-ecosystem#22 (comment) Remove the common `#![allow]` blocks and switch to this method for global lint config. Temporarily allow `needless_borrow` lint, buggy pending this fix: rust-lang/rust-clippy#8355
That way they apply to all crates equally. See EmbarkStudios/rust-ecosystem#22 for why.
That way they apply to all crates equally. See EmbarkStudios/rust-ecosystem#22 for why.
We just hit a very weird issue with the
# outside any section
target-applies-to-host = false
[unstable]
target-applies-to-host = true PR that fixes this for our project, with extra comments: https://github.com/matrix-org/matrix-rust-sdk/pull/737/files |
Regarding my previous comment, do not use that nightly feature if you also want to pass |
One more update: I've found a good-ish workaround: Just reset target-applies-to-host to its default value when building docs, for example by setting the environment variable |
Btw, I've found a different (kinda horrible) workaround: You can add another binary that declares all the other entrypoints to be linted as modules, and then add the lints in that binary. It seems to have a number of drawbacks that you'll probably find out quickly (ie it triggers dead_code), but I just thought I'd leave that here, perhaps it turns out to be the least evil for some and/or the main problems can be fixed. |
Ah thanks for sharing! Kinda horrible indeed but good to know about! |
Ugh, I found that |
I wrote cargo-cranky, which allows easy clippy lint configuration. Lint config goes in a |
I need this for the
|
In our monorepo we want to have the same baseline of Clippy lints enabled & disabled across our crates. Right now we need to set this up manually for every crate in
lib.rs
/bin.rs
which is error prone and cumbersome.This is what almost all of our crates have right now:
We would strongly prefer to instead be able to specify this in our workspace
Cargo.toml
or rootClippy.toml
.This is tracked in:
The text was updated successfully, but these errors were encountered: