[英]How can I have a shared Clippy configuration for all the crates in a workspace?
我有一个应用程序分成几个板条箱。 我想拒绝或允许所有板条箱中的特定 lint。 例如:
#![deny(clippy::print_stdout)]
看来我必须将其添加到每个板条箱中的 lib.rs 中。
Cargo 有一张票允许以某种方式配置它,但它已经开放了好几年,没有明确的结论。
是否有解决方法来避免每个板条箱重复这些允许/拒绝/警告行?
我有一个想法是include!
通过在工作区根目录创建一个clippy_config.rs
来添加这些行,然后在每个板条箱的 lib.rs 中添加
include!("../../clippy_config.rs");
然而,这失败了
error: an inner attribute is not permitted in this context
--> app/src/../../clippy_config.rs:1:1
|
1 | #![deny(clippy::print_stdout)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them.
出于同样的原因,我使用宏的另一个想法也不起作用。
有没有一种简单的方法可以做到这一点,除了编写一个外部脚本来修改 Rust 文件以自动复制? (如描述 Embark Studio 设置的评论中所述)。
Clippy 提供了 3 种配置模式:
#[deny(clippy::print_stdout)]
-Dclippy::print-stdout
clippy.toml
,但仅限于可配置 lints 的子集。对于项目范围的配置,跨包,配置文件是最好的选择,如果它能工作的话。
否则,第二好的(hacky)选项是间接使用标志。 也就是说,与其在编译器调用前指定RUSTFLAGS=-Dclippy::print-stdout
,不如让 Cargo 来做,并在项目范围内配置 Cargo。
在项目的根目录下,创建一个包含以下内容的.cargo/config.toml
文件:
[build]
rustflags = ["-Dclippy::print-stdout"]
Cargo 在调用它时会将此标志传递给 clippy。
注意:在工作空间设置中,当从工作空间的根目录调用 Cargo 时,单个 crate 文件夹中的.cargo/config.toml
被忽略,所以最好将它放在根目录的.cargo
中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.