~technomancy/fennel

[ANN] fnlfmt 0.1.0

Details
Message ID
<87blbwm4zk.fsf@whirlwind>
DKIM signature
missing
Download raw message
Hello!

The past couple weeks I've been working on a formatter for Fennel code
that uses the new and much improved `fennel.view` pretty-printer. I feel
like it's gotten to the point where its results are quite good. As an
algorithm making aesthetic decisions, it's never going to be perfect,
but it's ready for release and wider use.

  https://git.sr.ht/~technomancy/fnlfmt

You can see the results of running it on the Fennel compiler itself:

  https://git.sr.ht/~technomancy/fennel/commit/8538bad8ecafdb7979ad9b9be265b20c16b06378

The most common change is that strings with no spaces in them almost
always get turned into :colon-notation, unless they consist entirely of
punctuation. This is usually what you want but not always; for instance
there's one case there where a file path became a colon string.

The second most common change is that little places where a human may
have placed things a little more tightly to save lines end up getting
spaced out. This means a higher line count but more consistency; on the
whole I think it's better; it removes some temptation to be terse.

It also canonicalizes notation; some older code was written in a way
that predated the {: foo : bar} shorthand, and the formatter uses that
style wherever possible. Likewise the old `#` alias becomes `length`.

Of course there's a few places where I had to add a comment to get the
formatter to skip a bit of code. I think it's always good to have an
escape hatch in any automated context like this.

One fun fact is that writing this formatter exposed some shortcomings in
the Fennel parser and pretty-printer. I found certain cases where line
numbering data in the parser's AST got discarded, and some extra options
were added to fennel.view to give more flexibility in colon strings and
newline handling.

If you get a chance to try this on some of your own Fennel codebases I'd
love to hear how it goes for you, or if you have any input on how the
changes to Fennel itself look that I linked to above.

cheers,
Phil
Reply to thread Export thread (mbox)