Skip to content

A formatter for templr's `templ!` macro

Notifications You must be signed in to change notification settings

PizzasBear/templrfmt

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

templrfmt

Latest version Documentation

Formatter for the templr templates library.

Install

cargo install templrfmt

Usage

Usage: templrfmt [OPTIONS] [INPUT_PATTERNS]...

Arguments:
  [INPUT_PATTERNS]...  A space separated list of file, directory or glob

Options:
  -s, --stdin    Format stdin and write to stdout
  -r, --rustfmt  Format with rustfmt
  -q, --quiet
  -h, --help     Print help
  -V, --version  Print version

Using with Rust Analyzer

You can set the rust-analyzer.rustfmt.overrideCommand setting.

  "rust-analyzer.rustfmt.overrideCommand": ["templrfmt", "--stdin", "--rustfmt"]

Pretty-printer algorithm

The pretty-printer is based on Philip Karlton’s Mesa pretty-printer, as described in the appendix to Derek C. Oppen, “Pretty Printing” (1979), Stanford Computer Science Department STAN-CS-79-770. This algorithm's implementation is taken from prettyplease which is adapted from rustc_ast_pretty.

The algorithm takes from an input stream of length n and an output device with margin width m, the algorithm requires time O(n) and space O(m). The algorithm is described in terms of two parallel processes; the first scans the input stream to determine the space required to print logical blocks of tokens; the second uses this information to decide where to break lines of text; the two processes communicate by means of a buffer of size o(m). The algorithm does not wait for the entire stream to be input, but begins printing as soon as it has received a linefull of input.

About

A formatter for templr's `templ!` macro

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%