A Prettier JavaScript Formatter
jlongster.com
A Prettier JavaScript Formatter
1–10 of 159 posts
Re: A Prettier JavaScript Formatter
#2This is awesome - this reminds me of Google's clang-format which they use to format Angular automatically, but sounds like it's less sucky. The idea behind it is that developers tend to be opinionated about code style, so having a tool do it for you eliminates those arguments, which can be a hold up for PRs getting merged into a codebase.
Re: A Prettier JavaScript Formatter
#3I enjoy something similar for Elm code called Elm Format. https://github.com/avh4/elm-format
Re: A Prettier JavaScript Formatter
#4How does this compare to clang-format, which also formats JavaScript and also (to use one of the features highlighted in the article) obeys line length?
Re: A Prettier JavaScript Formatter
#5> If computers are good at anything, they are good at parsing code and analyzing it. So I set out to make this work, and prettier was born. I didn't want to start from scratch, so it's a fork of recast's printer with the internals rewritten to use Wadler's algorithm from "A prettier printer".
Bob Nystrom (munificent) disagrees[0] after writing one himself:
> The search space we have to cover is exponentially large, and even ranking different solutions is a subtle problem.
[0]: http://journal.stuffwithstuff.com/2015/09/08/the-hardest-pro...
Re: A Prettier JavaScript Formatter
#6I really have to back up the recommendation for Wadler's "prettier printer" paper. I'm working on a Haskell parser and pretty-printer for Rust and I had pretty much given up on ever finding a lightweight pretty printer that would be able to choose whether to put something on one line or to split it up into multiple lines all by itself. For anyone needing this in Haskell, I strongly urge you to consider the modern rewrite of the initial library [1].
Re: A Prettier JavaScript Formatter
#7Much better than "Standard JS" and its choice of no semicolons. I know about "Semi Standard JS", but I refuse to accept such a little difference that could be a configuration has to live in a entirely new project.
Re: A Prettier JavaScript Formatter
#8I have used ESFormatter (https://github.com/millermedeiros/esformatter) with decent amount of success. Does anybody know how Prettier compares to ESFormatter?
Re: A Prettier JavaScript Formatter
#9This looks really nice. One of my favourite things about Golang is the use of gofmt and the resulting consistency of all Go programs. The idea of parsing the code to AST representation and then printing it back as source is brilliant, all though it can mess stuff up like the chaining of `.then` as mentioned in the post.
Re: A Prettier JavaScript Formatter
#10I have used ESFormatter ( https://github.com/millermedeiros/esformatter ) with decent amount of success. Does anybody know how Prettier compares to ESFormatter?
esformatter suffers from the same problems as eslint as described in the post. It doesn't take maximum line width into account, which is a critical piece for laying out code.