Live data from Hacker News

Prettier 2.0 – Opinionated JavaScript formatter

prettier.io

71–80 of 91 posts

Re: Prettier 2.0 – Opinionated JavaScript formatter

#71

> Improved method chain breaking heuristic This is great! When I'm scripting in Node.js I tend to prefer either of these two styles, with the second one being normally a cleaned-up version of the first one: const res = base .map(a => a.b) .filter(b => /abc/.test(b)) .join('\n'); const res = base.map(extractB).filter(isAbc).join('\n'); The second one would be split into different lines with Prettier 1.x, which was ann…

You should peg dev-deps just like any other dep.

I prefer not to add an extra step for newbies devs contributing to my open source projects. So if someone makes a PR and it's not well formatted, not a big deal.

For work, sure agree.

Re: Prettier 2.0 – Opinionated JavaScript formatter

#72
post #50

Earlier quoted context omitted.

> Before version 2.0, Prettier was avoiding trailing commas by default where possible. This made the resulting JavaScript compatible with now very old environments such as IE8, but implied some missed opportunities. Seems like a pretty good reason to change that one at least, since it seems to imply they've wanted trailing commas but didn't do it for compatibility reasons.

I find trailing commas annoying because every once in a while I need to copy some object to use as JSON and... it doesn't work since JSON doesn't support trailing commas.

To be fair, that's more of a JSON problem than a JS one. FWIW, JSON is also missing quote-less keys, object literal shorthand, non-decimal numbers, values that are non-simple literals, and probably a bunch else from JS object syntax.

Just `JSON.stringify` whatever object it is instead.

Re: Prettier 2.0 – Opinionated JavaScript formatter

#73

Earlier quoted context omitted.

I find trailing commas annoying because every once in a while I need to copy some object to use as JSON and... it doesn't work since JSON doesn't support trailing commas.

To be fair, that's more of a JSON problem than a JS one. FWIW, JSON is also missing quote-less keys, object literal shorthand, non-decimal numbers, values that are non-simple literals, and probably a bunch else from JS object syntax. Just `JSON.stringify` whatever object it is instead.

No comments either, which is one major reason I strongly oppose JSON as a config-file language :|

Re: Prettier 2.0 – Opinionated JavaScript formatter

#76
post #42

Earlier quoted context omitted.

Part of the calculus for the cost is losing the immediate utility of git blame once every file has been reformatted.

Configure your git blame to ignore cleanup changes. https://www.moxio.com/blog/43/ignoring-bulk-change-commits-w...

Thanks for sharing this. This issue is holding so many code bases behind.

Re: Prettier 2.0 – Opinionated JavaScript formatter

#77
post #67

Earlier quoted context omitted.

Is the cost really that high? For the vast majority of projects, all developers will need to do is run "yarn prettier". We can't expect everything to be perfect on day one, nor should we be stuck with the poor choices we made when starting a project. Maintainers should be allowed to change their mind after careful consideration and community consensus.

It will likely conflict most in-progress PR. For PRs that are large and long lived it will be a PITA to maintain and will further slow integration so, likely, yes.

I ran formatters on a largish codebase over Christmas when all the PRs were done. You just have to pick your moment. If it's really hard then get everyone to agree on a date to do it and make it each developer's responsibility to either merge before or rebase after the change. It can be done.

Re: Prettier 2.0 – Opinionated JavaScript formatter

#78

Earlier quoted context omitted.

This changes everything. Thank you!!!

If GitHub doesn't automatically support the feature (article says it doesn't) I don't think it'll be very useful for many teams.

git 2.23 isn’t that old - seems like something that GitHub could support in the future

Re: Prettier 2.0 – Opinionated JavaScript formatter

#79
post #13

Doesn't it defeat the idea of "one formatting to rule them all" if they change the rules?

I don't think Prettier ever claimed to be the one true formatting everyone must use for it to be successful. It's a tool that formats code nicer then most other tools.

Personally, I would rather a project use a formatting tool that outputs a format I don't like than not using a formatting tool at all.

I just don't want to have to waste mental bandwidth on formatting ever again.

Re: Prettier 2.0 – Opinionated JavaScript formatter

#80
post #11

Earlier quoted context omitted.

Why? Are you avoiding NPM as well? Seems like a curious requirement for JS development

Yes. I would prefer the only JavaScript VM on my computer to be the browser's. Aside: I wouldn't sell what I do as JavaScript development, though.

For the last 25 years, many apps have come with their own JS engine for scripting abilities. Ms Office, Photoshop, et. al. Not just the web browser. And more and more "native" apps have a built in JS engine. And then there's apps that not only have a JS engine, but a whole browser (Electron, Nw.js).

So it would be difficult to purge your system from anything that can run JS :P

Post reply on HN