Purty 4.0.0 and 4.0.1 released

:tada: :tada:

Time for another weekly release of purty . It’s another double header this week! You can grab the npm package or go directly for the binaries.

Notes from the changelog

4.0.0

First release in a while. We’ve moved over to interactive formatting!

We’re now based off of the 0.13.x version of the purescript package.
That means we’ve got a parser that gives us as close to source code as possible.
Using the newer version, we can format a module much more carefully.

Interactive formatting is something that elm-format does.
It’s not clear if there’s an official name for it.
It could also be called VonderHaar-style formatting (after the author of elm-format).
The way it works is by taking hints from the structure of the file to direct the formatting.
If you have some syntactic construct that could be put on one line,
and there are no line breaks in the construct, purty will format it on one line.
If you have some syntactic construct that could be put on one line,
and there is at least one line break in the construct,
purty will format the entire construct as multiple lines.
The formatting does not reach beneath the construct but may reach above it.

For example:

foo = [[1, 2, 3], [4,
  5, 6, 7]]

would be formatted as:

foo =
  [ [1, 2, 3]
  , [ 4
    , 5
    , 6
    , 7
    ]
  ]

The array [1, 2, 3] was formatted on a single line,
since it was initially all on one line.
The array [4, 5, 6, 7] was formatted over multiple lines,
as it had at least one line break.
Finally, the overall array [[1, 2, 3], [4, 5, 6, 7]] was formatted over multiple lines,
as it also had at least one line break.

The long and short of the changes here are that the control of formatting is given more to the author of the code.
This should still keep with the idea of formatting that works nicely,
but it should also give a bit of freedom to people to structure the code a little bit differently if need be.

Bear in mind, almost all of the code is re-written so it’s likely to contain a new set of bugs.
Please feel free to report any bugs you find.

Additions

Changes

Deletions

4.0.1

A quick bug fix for formatting string literals.

Additions

Changes

Deletions

9 Likes

Output looks really wonderful Hardy! Using VonderHaar style is awesome. Thanks for the great work :slight_smile:

2 Likes