#comments #prettier #format #forms #source #formatted

app rustdoc-prettier

Format //! and /// comments with prettier

3 unstable releases

0.2.0 Aug 8, 2024
0.1.1 Jul 28, 2024
0.1.0 Jun 30, 2024

#571 in Rust patterns

Download history 149/week @ 2024-06-30 5/week @ 2024-07-07 135/week @ 2024-07-28 112/week @ 2024-08-04 11/week @ 2024-08-11 1/week @ 2024-08-18 40/week @ 2024-09-15 21/week @ 2024-09-22 43/week @ 2024-09-29

104 downloads per month

MIT/Apache

14KB
308 lines

rustdoc-prettier

Format //! and /// comments with prettier

Installation

cargo install rustdoc-prettier

rustdoc-prettier requires prettier to be installed independently, e.g.:

npm install -g prettier

Usage

rustdoc-prettier [ARGS]

Arguments ending with .rs are considered source files and are formatted. All other arguments are forwarded to prettier, with one exception. An option of the form:

---max-width <N>

is converted to options of the form:

--prose-wrap always --print-width <M>

where M is N minus the sum of the widths of the indentation, the //! or /// syntax, and the space that might follow that syntax. If the current directory contains a rustfmt.toml file with a max_width key, the --max-width option is applied automatically.

rustdoc-prettier supports glob patterns. Example:

rustdoc-prettier '**/*.rs'

References

Notes

rustdoc-prettier parses source code manually. It does not use rustdoc-json. There are two reasons for this:

  1. rustdoc-json provides the span of the commented code, but not of the comment itself. To the best of my knowledge, there is no easy way to extract rustdoc comments using rustdoc-json's output.
  2. rustdoc-json does not output spans for items that come from macro expansions or inline assembly. However, there are legitimate reasons to want to format such comments.

Dependencies

~7–17MB
~247K SLoC