如何为工作区中的所有板条箱共享Clippy配置



我将一个应用程序拆分为几个板条箱。我想拒绝或允许在所有板条箱中放入特定的皮棉。例如:

#![deny(clippy::print_stdout)]

似乎我必须把这个添加到每个板条箱的lib.rs中。

Cargo有一张允许以某种方式进行配置的罚单,但它已经开放了几年,没有明确的结论。

是否有一种变通方法可以避免每个板条箱重复这些允许/拒绝/警告行?

我的一个想法是通过在工作区根目录创建一个clippy_config.rsinclude!行,然后在每个板条箱的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,但仅限于可配置lint的子集

对于跨板条箱的项目范围配置,如果配置文件有效,则它是最佳选择。

否则,第二个最好的(hacky(选项是间接地使用标志。也就是说,您不需要在编译器调用之前指定RUSTFLAGS=-Dclippy::print-stdout,而是可以让Cargo执行此操作,并在整个项目范围内配置Cargo。

在项目的根目录中,创建一个包含以下内容的.cargo/config.toml文件:

[build]
rustflags = ["-Dclippy::print-stdout"]

当clippy调用该标志时,Cargo会将该标志传递给它

注意:在工作区设置中,从工作区根目录调用Cargo时,会忽略单个机箱文件夹中的.cargo/config.toml,因此最好将其放在根目录的.cargo

最新更新