11 releases (6 breaking)
Uses new Rust 2024
| 0.7.1 | Dec 17, 2025 |
|---|---|
| 0.7.0 | Oct 29, 2025 |
| 0.6.1 | Sep 1, 2025 |
| 0.5.1 | Jun 2, 2025 |
| 0.1.1 | Jul 28, 2024 |
#377 in Parser implementations
31 downloads per month
68KB
459 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 a rustfmt.toml file with a max_width key is found
in a current or parent directory, the --max-width option is
applied automatically.
rustdoc-prettier supports glob patterns. Example:
rustdoc-prettier '**/*.rs'
References
- https://prettier.io/docs/en/options.html
- https://rust-lang.github.io/rustfmt/?version=master&search=
"No such file or directory" errors
rustdoc-prettier tries to tolerate "No such file or directory" errors by emitting a warning and continuing. Such errors can arise when rustdoc-prettier tries to format a file that was removed by another process, for example.
Notes
rustdoc-prettier parses source code manually. It does not use rustdoc-json. There are two reasons for this:
rustdoc-jsonprovides the span of the commented code, but not of the comment itself. To the best of my knowledge, there is no easy way to extractrustdoccomments usingrustdoc-json's output.rustdoc-jsondoes 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
~9–14MB
~295K SLoC