Skip to content

Optionally disable allows unless linked to a justification #3695

Closed
@swfsql

Description

@swfsql

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions