有没有一种稳定的方法告诉 Rustfmt 跳过整个文件
Is there a stable way to tell Rustfmt to skip an entire file
让 Rustfmt 跳过一个项目的官方方法是 #[rustfmt::skip]
,但是我希望它跳过整个文件。我试过这个:
#![rustfmt::skip]
但是你得到这个错误
error[E0658]: non-builtin inner attributes are unstable
Here is the issue for that error.
有解决办法吗?我不感兴趣的解决方案:
- 使用不稳定的 Rust
- 告诉 Rustfmt 不要使用文件外部的东西来处理文件(例如
rustfmt.toml
)
目前 Rustfmt 遍历 mod 树本身,因此您可以将属性放在声明了您要忽略的 module 的文件上。
#[rustfmt::skip]
mod dont_format_this_file;
那么dont_format_this_file.rs
将被跳过。
然而,Rustfmt 2 changed its behaviour 所以它 不会 遍历 mod 树,所以你必须直接指定 dont_format_this_file.rs
.在那种情况下,它似乎很可能会找到 mod dont_format_this_file;
声明,因此当 Rustfmt 2 发布时这可能不起作用。
让 Rustfmt 跳过一个项目的官方方法是 #[rustfmt::skip]
,但是我希望它跳过整个文件。我试过这个:
#![rustfmt::skip]
但是你得到这个错误
error[E0658]: non-builtin inner attributes are unstable
Here is the issue for that error.
有解决办法吗?我不感兴趣的解决方案:
- 使用不稳定的 Rust
- 告诉 Rustfmt 不要使用文件外部的东西来处理文件(例如
rustfmt.toml
)
目前 Rustfmt 遍历 mod 树本身,因此您可以将属性放在声明了您要忽略的 module 的文件上。
#[rustfmt::skip]
mod dont_format_this_file;
那么dont_format_this_file.rs
将被跳过。
然而,Rustfmt 2 changed its behaviour 所以它 不会 遍历 mod 树,所以你必须直接指定 dont_format_this_file.rs
.在那种情况下,它似乎很可能会找到 mod dont_format_this_file;
声明,因此当 Rustfmt 2 发布时这可能不起作用。