How 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?
Not sure, didn't know it formatted JavaScript! This is written in JS at least so if anything it's more approachable to the community.
A Prettier JavaScript Formatter
31–40 of 159 posts
Re: A Prettier JavaScript Formatter
#32> 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, a…
Also, describing how these building blocks interact using laws is really incredibly useful! For that, credit goes (I think) to Hughes [1].
Re: A Prettier JavaScript Formatter
#33Flow is cool, but TypeScript has way more traction. Would jump on this in an instant if it had TypeScript support and a VS Code plugin.
Re: A Prettier JavaScript Formatter
#34Flow is cool, but TypeScript has way more traction. Would jump on this in an instant if it had TypeScript support and a VS Code plugin.
Re: A Prettier JavaScript Formatter
#35Much 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.
Note that Standard is a linter, this is a reformatter. Standard gives you errors but doesn't fix things for you.
“You can use standard --fix to automatically fix most issues automatically.
standard --fix is built into standard (since v8.0.0) for maximum convenience. Lots of problems are fixable, but some errors, like forgetting to handle the error in node-style callbacks, must be fixed manually.”
Re: A Prettier JavaScript Formatter
#36This 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.
gofmt's decision to not bother to require a line length may work somewhat for Go (which tends to encourage short lines by virtue of lacking expressiveness), but it doesn't work for lots of other languages, including JavaScript.
Re: A Prettier JavaScript Formatter
#37Flow is cool, but TypeScript has way more traction. Would jump on this in an instant if it had TypeScript support and a VS Code plugin.
Typescript is another language. It kind of goes without saying that people using a different language be more likely to use something if it were in the language they use, doesn't it?
Re: A Prettier JavaScript Formatter
#38Earlier quoted context omitted.
the parent gave an ill example and suggest a solution, how's that a negativity?
I believe it was the "Nice attempt, but currently wrong." at the start of the comment. "Nice attempt" could imply that this should be thrown out in favor of another attempt to solve the problem.
Re: A Prettier JavaScript Formatter
#39This 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.
Having choices can be nice, but it introduces a huge amount of cognitive load. And, really, if we all just use the same format, we'll all (eventually) get used to it.
We really do have better things to deal with than formatting style.
Re: A Prettier JavaScript Formatter
#40Much 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.
EDIT: Looks like they may be open to it though. https://github.com/jlongster/prettier/issues/12