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

[Feature Request]: Lint Configuration inlined in the attribute macro. #10351

Closed
GilShoshan94 opened this issue Feb 16, 2023 · 2 comments
Closed

Comments

@GilShoshan94
Copy link

GilShoshan94 commented Feb 16, 2023

Description

Hi,

Awsome tool that help me to be proeficient in Rust.

I am trying to use some of the new lint such as clippy::cognitive_complexity.
I see it can be configured by cognitive-complexity-threshold.

To my understanding, some lints can be tuned and they are listed here: Lint Configuration Options.

Unless I missunderstood, the only way to set those configurations is in a in a TOML file named clippy.toml or .clippy.toml.

I like to set all my lint configuration in my lib.rs/main.rs in the attributes #![allow/warn/deny/forbid(...)] at the beginnig of the file.

It lets me see a nice overview of all my lints settings.

Is it possible for the configurable lints to have their config inlined in the attribute so we won't need an extra clippy.toml file ?

I imagined something like:

#![warn(clippy::<lints>(<config1>=<value1>, <config2>=<value2>, ...))]

Example with clippy::cognitive_complexity:

// # lib.rs

//! My demo library.

// rustc lints
#![forbid(unsafe_code)]
#![deny(non_ascii_idents, unreachable_pub)]
#![warn(rust_2018_idioms)

// clippy lints
#![warn(
    clippy::pedantic, 
    clippy::cognitive_complexity(cognitive_complexity_threshold=30),
    clippy::branches_sharing_code,
)]

(Also, if it is doable, the config can be renamed shorter, cognitive_complexity_threshold -> threshold, as it cannot be misinterpreted for another lint.)

Version

No response

Additional Labels

C-enhancement

@J-ZhengLi J-ZhengLi added C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages and removed C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages labels Apr 2, 2024
@J-ZhengLi
Copy link
Member

J-ZhengLi commented Apr 2, 2024

good idea, I saw @flip1995 made a comment addressing similar stuff here, but I like yours better (XD), which means rustc lints could also benefit from this.

@flip1995
Copy link
Member

flip1995 commented Apr 2, 2024

The lint level attributes are not implemented by Clippy, but by rustc. So this change would have to be done in rustc. However, there is no such thing as a lint configuration, as far as the compiler/Clippy is concerned. You can only configure the tool. So each configuration is a 1-to-many relationship to lints, where N might be 1 (cog-comp). So conceptually you can't configure a single lint with a configuration. You can only configure the tool, in this case Clippy, to apply the configuration to all lints. Special casing some lints here would be a lot of work (upstream in rustc and in Clippy) for something I/we don't really want to support.

Also in the future you want to configure your global lints in the Cargo.toml file. Your Clippy [lint] configuration then goes into clippy.toml. Only a few configurations can be applied with an attribute.

So I mark this as not-planned.

@flip1995 flip1995 closed this as not planned Won't fix, can't repro, duplicate, stale Apr 2, 2024
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

3 participants