Live data from Hacker News

Prettier 1.0

jlongster.com

11–20 of 78 posts

Re: Prettier 1.0

#13

I can't overstate how freeing coding with prettier has been -- often I'd find myself quickly grokking something and once I finally got it to "work," make sure it was all styled properly. Since using prettier, these things are one-and-the-same, which is a tremendous gain.

Something that's kind of tricky for me and my team is that we disagree on things like indentation and spacing in/around brackets and parens. The disagreement isn't just a "I think it should be done this way..." but "I actually understand code better when it's written this way..."

If we were to implement prettier, and chose to use 2-space indents, for a simple example, how would a 4-space developer fare when they pulled down the Prettified code? Would they just set up their own config locally based on their own standards?

Re: Prettier 1.0

#14
I recall the React team were discussing at what part of the build step they should include Prettier.

I believe there was an idea of adding it as a pre-commit hook, a second one as a manual step and another one as a post-commit amend.

Have we reached a consensus on that? Not up to date what they went with, what seems to be the best way to do this?

Re: Prettier 1.0

#15
post #9

Prettier is a code formatter for JavaScript, like the hugely popular "gofmt". Highlights of the 1.0 announcement: - production-ready (and used, eg; React, Oculus, Cloudflare, etc) - --no-semi option - --use-tabs option - parens that help indicate precedence - many formatting improvements There are a ton of edge cases in this work that really matter (read through the announcement for a few). Speaking as a contributor,…

Can it handle escaped json string constants?

For example this: http://whitneyland.com/2017/04/first-in-the-world-to-display...

Re: Prettier 1.0

#16
I really like it for personal stuff.

I'd like to hear how people are using it on teams. With some effort I got it working on save in emacs, but asking other people to please install more tooling is not always easy.

I do have some authority over package.json though. How would you make it just work for everyone (using atom, vim, etc...)

Re: Prettier 1.0

#18
post #2

Prettier goes such a long way to enforcing standards on a language and ecosystem which otherwise has none or few. What standards do exist are frequently arbitrary, or enforced by legacy code at random companies. For example, the Airbnb JS style guide [1] recommends single quotes in JS, but double quotes for JSX properties. Why the difference? Why not stick with double quotes everywhere, as they are required in JSX bl…

One of the Airbnb style guide authors here.

The point about quotes comes up often. The important part for us is consistency at Airbnb. We use eslint to enforce and maintain the consistency. Would it be more consistent to treat strings the same everywhere? For some projects sure. We diverge from the community a bit in the sense that we treat JSX as not JS and we aim to be consistent about that. If your project treats JSX and JS the same then yes, we've certainly seen folks do this. As always, please do what works best for your team or project [1]. Forks encouraged.

I will say an added benefit of including a style guide in a project for large teams that may get lost jumping straight into prettier, has been helping our engineers become stronger javascript programmers in the process of learning our style guide. That's largely anecdotal evidence from my time at Airbnb and of course your mileage my vary.

Personally, I support the Prettier mission 100%. Easier consistency is huge. Removing barriers to contributing to open source projects is huge. PR reviews focused on what the code is doing vs painful style nits is huge. It's been great to see this come from the community and I look forward to seeing where the community takes it. Congrats to all of the contributors on the 1.0!

[1] https://github.com/airbnb/javascript/issues/102

Re: Prettier 1.0

#19
post #9

Prettier is a code formatter for JavaScript, like the hugely popular "gofmt". Highlights of the 1.0 announcement: - production-ready (and used, eg; React, Oculus, Cloudflare, etc) - --no-semi option - --use-tabs option - parens that help indicate precedence - many formatting improvements There are a ton of edge cases in this work that really matter (read through the announcement for a few). Speaking as a contributor,…

Can it handle escaped json string constants? For example this: http://whitneyland.com/2017/04/first-in-the-world-to-display...

You can try prettier online at https://prettier.github.io/prettier/

Not sure exactly what you mean, but here's an example with JSON: https://prettier.github.io/prettier/#%7B%22content%22%3A%22x...

Prettier doesn't support JSON files per se (and doesn't currently plan to [0]), so you need to provide a leading `x = {...` or similar to ensure the { is parsed as an object instead of a block.

[0] https://github.com/prettier/prettier/issues/322

Re: Prettier 1.0

#20
post #16

I really like it for personal stuff. I'd like to hear how people are using it on teams. With some effort I got it working on save in emacs, but asking other people to please install more tooling is not always easy. I do have some authority over package.json though. How would you make it just work for everyone (using atom, vim, etc...)

One option is to add prettier as a precommit hook, eg; https://github.com/prettier/prettier#pre-commit-hook-for-cha... which doesn't require editor integrations at all.

There are integrations for most editors (Atoms, Emacs, Vim, Neovim, VSCode, VS, Sublime Text, JetBrains):

https://github.com/prettier/prettier#editor-integration

Post reply on HN