rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.44k stars 1.54k forks source link

Read clippy configuration normally found in `clippy.toml` from `Cargo.toml` #10890

Open lopopolo opened 1 year ago

lopopolo commented 1 year ago

Description

Cross-posting from:

I love seeing config converging into Cargo.toml. This will help to address some papercuts when working in workspaces with many crates.

I know it is out of scope for this tracking issue, but mentioning it here since it seems relevant to the general idea. Other first party Rust tools have lots of configuration files of their own. I'd love rustup, rustfmt, and clippy to look in Cargo.toml for the configuration that today is found in rust-toolchain.toml, rustfmt.toml, and clippy.toml.

Originally posted by @lopopolo in https://github.com/rust-lang/cargo/issues/12115#issuecomment-1575681614

I would like to reduce the proliferation of configuration files in the root of my repositories as much as possible. Would it be possible and/or an accepted feature to read the config normally found in clippy.toml (like doc-valid-idents) from Cargo.toml?

I don't believe this requires dedicated support from the Cargo team and could be done today with tool-specific metadata, like this example for configuring docs.rs:

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

Version

rustc 1.70.0 (90c541806 2023-05-31)
binary: rustc
commit-hash: 90c541806f23a127002de5b4038be731ba1458ca
commit-date: 2023-05-31
host: x86_64-apple-darwin
release: 1.70.0
LLVM version: 16.0.2

Additional Labels

@rustbot label +C-question

blyxyas commented 1 year ago

Pretty interesting idea! RFC 3389 also talks about Clippy, so I see implementing this [lints.clippy] table in the future (Very possibly if/when the feature gets stabilized)

Currently, unless you hack on Clippy's source or create a script to parse [lints.clippy] and move it to the terminal / clippy.toml, we don't have any options to do this.

jwodder commented 12 months ago

[lints.clippy] has now been stabilized in Rust 1.74. Supporting clippy.toml config in Cargo.toml would be good for 1.75....