#comments #rustfmt #formatting #syn #format

app prettyplease-cli

非官方的基本CLI包装程序,围绕 ::prettyplease

3个版本

0.1.0 2022年2月3日

#24 in #rustfmt

Zlib OR MIT OR Apache-2.0

12KB
100

::prettyplease-cli 或:如何学会停止担忧并修剪注释。

Repository Latest version MSRV unsafe forbidden License CI

非官方的基本CLI包装程序,围绕 ::prettyplease 库。

这可以作为一个 rustfmt 的穷人替代品,主要针对生成的代码

⚠️ 警告:注释将丢失 ⚠️

实际上,::prettyplease 只对 ::syn::File (按设计) 操作。而 ::syn::File 是源代码文件的抽象语法树(AST)的解析表示。这种AST 不包括注释

[^1]: 抽象语法树

这意味着将源文件的内容通过 ::syn::parse_file() 管道输入,然后输入到 ::prettyplease::unparse(),会导致 注释丢失;这正是此CLI工具所做的。

  • 但是请注意,文档注释 被保留,因为它们是Rust的AST的一部分。

安装

cargo install prettyplease-cli
## You may add `--no-default-features` to speed up the compilation
## if you are not interested in the `--check` mode showing pretty line diffs.

使用方法

Unofficial CLI wrapper around `::prettyplease::unparse` to format files and trim comments.

This modifies them IN PLACE, unless the `--check` flag is passed.

USAGE:
    prettyplease-fmt [OPTION] <files…>

OPTIONS:
        --check     Runs in 'check' mode. Exits with 0 if input is formatted
                    correctly. Exits with 1 if formatting is required, printing
                    a diff unless the `check-shows-diffs` Cargo feature were
                    disabled at compile-time.
    -h, --help      Shows this very message.

See https://crates.io/crates/prettyplease for more info about the formatting itself.

缺少功能 / FIXME

  • 以某种方式保留注释;

  • 接受文件和/或目录遍历的glob;

  • 并行处理文件。

依赖关系

~1.5–2.6MB
~51K SLoC