Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Clarify the right way to opt-in to clippy lints #1437

Closed
nickolay opened this issue Apr 21, 2019 · 2 comments · Fixed by #1439
Closed

Clarify the right way to opt-in to clippy lints #1437

nickolay opened this issue Apr 21, 2019 · 2 comments · Fixed by #1439

Comments

@nickolay
Copy link
Contributor

nickolay commented Apr 21, 2019

The README says:

"opt-in" Clippy lints are shown when crates specify #![warn(clippy)].

(the same text was copied to the VS Code extension in rust-lang/vscode-rust#417 )

However putting that into lib.rs results in a clippy warning:

lint name clippy is deprecated and may not have an effect in the future. Also cfg_attr(cargo-clippy) won't be necessary anymore

note: #[warn(renamed_and_removed_lints)] on by default
help: change it to: clippy::all

...which confused me as it says cfg_attr won't be necessary -- maybe it's necessary now? Googling that found #149 which didn't make things clearer...

I think the right way to opt-in is adding #![warn(clippy::all)] to all the crate roots, i.e. main.rs, lib.rs, any examples/*.rs, and integration tests/*.rs. And making it conditional as in #![cfg_attr(feature = "cargo-clippy", warn(clippy::all))] is not necessary now, as current stable/beta/nightly will not fail building the project without the conditional. Is that right?

One more thing to clarify is whether clippy::all is the only variant that works as an opt-in for RLS or other categories would work too.

@alexheretic
Copy link
Member

Yep I agree the readme should be updated to #![warn(clippy::all)]. Would you like to raise a pr?

opt-in means clippy will run but with everything "allowed" so you have to opt into any clippy warnings. Other than that it should be exactly the same as running clippy any other way, so you can get clippy to show more warnings, ie #![warn(clippy::all, clippy::clone_on_ref_ptr)], opt out of warnings #![allow(clippy::cast_lossless)] etc.

Setting clippy_preference = "on" means clippy will run as default, equivalent to having #![warn(clippy::all)] in every target, ie the default warnings when you run cargo clippy.

@nickolay
Copy link
Contributor Author

@alexheretic thanks for the clarification! I think I got it -- please check the PR (#1439).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants