Description
openedon Feb 12, 2018
This issue started its life in clippy (rust-lang/rust-clippy#1313). Once it was realized this should apply to built-in lints as well, it migrated to rust (rust-lang/rust#45832). There @kennytm suggested that it should be Cargo's responsibility to pass the -D
/-W
/-A
flags to rustc.
Motivation
Currently project-wide lint configuration needs to be included in the crate sources. This is okay when the project consists of a single crate, but gets more cumbersome when the project is a workspace with dozen crates.
Being able to define the lints in an external file that will be used when building the crates would have several benefits:
- Sharing one configuration file for all the crates in a workspace.
- A canonical place to check for lint configuration when contributing to a new project.
- An easy way to examine the version history for lint changes.
Proposal
- A configuration
lints.toml
(or[lints]
inCargo.toml
?) file that specifies the lints. - The lints can be specified on the workspace level and for individual packages. Anything on the package level will override the workspace setup on per lint basis.
- The configuration file is cfg/feature-aware and can specify different lints depending on features. Specifying clippy-lints will result in clippy complaining about unknown lints if clippy isn't used.
Also... unlike what @oli-obk suggested in the rust issue, personally I'd prefer the following format:
[lints]
allow_unused = "allow"
non_snake_case = "allow"
While this is more verbose than allow = [ "allow_unused", "non_snake_case" ]
, I think the diff benefits and the ability for the user to group logically similar lints together even if some of them are deny
and some allow
outweighs the increased verbosity.
Also if Cargo/rustc ever support lint configurations, this would be more future proof:
cyclomatic_complexity = { state = "allow", threshold = 30 }
Example configuration
[lints]
allow_unused = "deny"
non_snake_case = "allow"
[lints.'cfg(feature = "clippy")']
cyclomatic_compexity = "deny"
The feature syntax is lifted from Cargo's dependency syntax - at least that was the intention. Personally I'm not a fan of it, but I guess that's a limitation of toml. Don't really have a better proposal for it, given I don't really know what's available int he toml syntax. :<