prettyplease-cli

Crates.ioprettyplease-cli
lib.rsprettyplease-cli
version0.1.0
sourcesrc
created_at2022-02-03 20:01:39.404877
updated_at2022-02-03 20:24:44.305167
descriptionUnofficial and basic CLI wrapper around the `::prettyplease` library.
homepage
repositoryhttps://github.com/danielhenrymantilla/prettyplease-cli
max_upload_size
id526357
size34,096
Daniel Henry-Mantilla (danielhenrymantilla)

documentation

README

::prettyplease-cli or: How I learned to Stop Worrying and Trim the Comments.

Repository Latest version MSRV unsafe forbidden License CI

Unofficial and basic CLI wrapper around the ::prettyplease library.

This can be used as a poorman's substitute of rustfmt, mainly for generated code.

⚠️ Warning: comments are lost ⚠️

Indeed, ::prettyplease only operates off a ::syn::File (by design). And a ::syn::File is an AST1 parsed representation of a file of source code. Such AST does not include comments.

This means that piping the contents of a source file into ::syn::parse_file() and then into ::prettyplease::unparse() results in loss of comments; and this is exactly what this CLI tool does.

  • Note, however, that doc-comments are preserved, since those are part of Rust's AST.

Installation

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.

Usage

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.

Missing features / FIXME

  • Preserve comments, somehow;

  • Accept files and/or globs for directory traversal;

  • Handle files in parallel.

Footnotes

  1. Abstract Syntax Tree

Commit count: 5

cargo fmt