【问题标题】:Is there a stable way to tell Rustfmt to skip an entire file有没有一种稳定的方法来告诉 Rustfmt 跳过整个文件
【发布时间】:2019-12-09 11:01:12
【问题描述】:

让 Rustfmt 跳过一个项目的官方方法是 #[rustfmt::skip],但我希望它跳过整个文件。我试过这个:

#![rustfmt::skip]

但是你得到这个错误

错误[E0658]:非内置内部属性不稳定

Here is the issue for that error.

有解决办法吗?我不感兴趣的解决方案:

  • 使用不稳定的 Rust
  • 告诉 Rustfmt 不要使用文件外部的东西来处理文件(例如rustfmt.toml

【问题讨论】:

  • 我猜把它作为一个外部属性?
  • 啊是的,看起来确实是这样。

标签: rust rustfmt


【解决方案1】:

目前 Rustfmt 会遍历 mod 树本身,因此您可以将属性放在声明要忽略的模块的文件上。

#[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 发布时这可能不起作用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-30
    • 2011-05-22
    • 1970-01-01
    • 2011-09-13
    • 1970-01-01
    • 1970-01-01
    • 2016-05-11
    • 1970-01-01
    相关资源
    最近更新 更多