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

Optionally disable allows unless linked to a justification #3695

Closed
swfsql opened this issue Jan 24, 2019 · 1 comment
Closed

Optionally disable allows unless linked to a justification #3695

swfsql opened this issue Jan 24, 2019 · 1 comment

Comments

@swfsql
Copy link

swfsql commented Jan 24, 2019

Hello, I really don't know if this issue should be in here,

I'm currently using 4 attributes blocks on my lib.rs': forbid, deny, warn and allow, in order, where I try to put/move as many lints (or group of lints) towards forbid as possible.

Some will stay stuck at deny level (for when I can't escape but allowing some item somehwere).

My question is, would you know a way to, based on some global attribute or flag, make those allows stricter? Some way to disable those allows (which would compile-time error on clippy) based on a condition?

I'm thinking of requiring some justification mechanism on every allow, such a reference into some document.

For example:

#![deny(clippy::pedantic)]

#![allow(unjustified_attrs)] // <--- made that up

#[allow(clippy::cast_possible_truncation)]
let a = 222_u64 as usize;
// compiles without error
#![deny(clippy::pedantic)]

#![deny(unjustified_attrs)] // <--- made that up

#[allow(clippy::cast_possible_truncation)]
let a = 222_u64 as usize;
// will not compile because lacks justification
#![deny(clippy::pedantic)]

#![deny(unjustified_attrs)] // <--- made that up

#[just(abc123)] // <--- made that up
#[allow(clippy::cast_possible_truncation)]
let a = 222_u64 as usize;
// compiles without error because this allow is justified

Another way of getting the same dynamic would be to have an intermediary setting between deny and forbid, where allows would be allowed conditionally somehow (such as only with the just attr).

@camsteffen
Copy link
Contributor

where I try to put/move as many lints (or group of lints) towards forbid as possible.

I suggest not doing that because it erases the difference between warnings and errors. Use deny(warnings) instead.

My question is, would you know a way to, based on some global attribute or flag, make those allows stricter? Some way to disable those allows (which would compile-time error on clippy) based on a condition?

There is cfg_attr(condition, allow(lint)), but I'm not sure if that's what you're looking for?

#[just(abc123)] // <--- made that up
#[allow(clippy::cast_possible_truncation)]

Attributes do not modify other attributes. Attributes modify the item or statement below.

Closing since I don't think this is actionable but feel free to comment further.

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

2 participants