Live data from Hacker News

Prettier 2.0 – Opinionated JavaScript formatter

prettier.io

21–30 of 91 posts

Re: Prettier 2.0 – Opinionated JavaScript formatter

#21
post #12

I have been looking for, but haven't found, a similar package for Java projects. Ideally my team can add it as a save-hook for everyone using IDEA, then we can have a pre-commit hook that checks to ensure compliance. Would be eternally grateful for anyone that can point me in the right direction!

There exists a Java plugin for Prettier: https://github.com/jhipster/prettier-java

No idea how good it is though. Please tell us. :)

Re: Prettier 2.0 – Opinionated JavaScript formatter

#22
post #12

I have been looking for, but haven't found, a similar package for Java projects. Ideally my team can add it as a save-hook for everyone using IDEA, then we can have a pre-commit hook that checks to ensure compliance. Would be eternally grateful for anyone that can point me in the right direction!

https://github.com/jhipster/prettier-java

Re: Prettier 2.0 – Opinionated JavaScript formatter

#23
post #12

I have been looking for, but haven't found, a similar package for Java projects. Ideally my team can add it as a save-hook for everyone using IDEA, then we can have a pre-commit hook that checks to ensure compliance. Would be eternally grateful for anyone that can point me in the right direction!

There’s https://github.com/jhipster/prettier-java, which expands Prettier to work with Java, but I’m not sure how complete or thoroughly-tested it is. It also requires that you have Node installed, which could be be a downside for people who only work with Java.

Re: Prettier 2.0 – Opinionated JavaScript formatter

#24
In order to get this working with vim's prettier highlighting, I had to add this to `.prettierrc`:

    {
      "trailingComma": "es5",
      "arrowParens": "always"
    }
Prettier 2.0 changed this to be the defaults, but for some reason the editor plugin wasn't acknowledging it.

Also I added a script command to format all the code in package.json:

    {
      "scripts": {
        "prettier": "prettier src webpack data --write"
      }
    }
Then `npm run prettier` got me sync'd with the latest defaults (the trailingComma and parens styling).

It even formatted my JSON and SCSS files. Didn't recognize prettier could do that.

Re: Prettier 2.0 – Opinionated JavaScript formatter

#25
post #24

In order to get this working with vim's prettier highlighting, I had to add this to `.prettierrc`: { "trailingComma": "es5", "arrowParens": "always" } Prettier 2.0 changed this to be the defaults, but for some reason the editor plugin wasn't acknowledging it. Also I added a script command to format all the code in package.json: { "scripts": { "prettier": "prettier src webpack data --write" } } Then `npm run prettier`…

> but for some reason the editor plugin wasn't acknowledging it

Is it using a bundled pre-2.0 version of Prettier?

Re: Prettier 2.0 – Opinionated JavaScript formatter

#26
post #13

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

I'm not sure how dedicated prettier is to "one formatting to rule them all" since it's configurable per-project. Switching between different projects with different prettier configuration is very low friction.

Speaking for myself, I advocate "one formatting to rule them all" in terms of just taking defaults, and one of my arguments is that, if there's something universally wrong about a prettier default, then it should be changed universally. And if it isn't universally wrong, just go with the default.

Re: Prettier 2.0 – Opinionated JavaScript formatter

#27
post #26
post #13

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

I'm not sure how dedicated prettier is to "one formatting to rule them all" since it's configurable per-project. Switching between different projects with different prettier configuration is very low friction. Speaking for myself, I advocate "one formatting to rule them all" in terms of just taking defaults, and one of my arguments is that, if there's something universally wrong about a prettier default, then it shou…

Yes.

Some things are obviously bugs, especially the chained line break problem.

Bur the semicolons config they added back in the days just baffled me.

Re: Prettier 2.0 – Opinionated JavaScript formatter

#28

Earlier quoted context omitted.

Why not just change it to a high value? Or prettier-ignore exceptional lines?

if you put a high lineWidth value, you'll have your object literals or destructuring mostly one-lined, etc.. often not desirable (for 4+ props) That's mostly why I don't like prettier, sometimes you want a bit of control over code formatting when several options are possible, prettier don't allow it. I use vscode formatter (actually it's TypeScript compiler formatter) instead Other things I dislike with prettier, lik…

I felt the same at first but I’ve honestly found after about a year of using prettier on every project that you just get used to the way it formats stuff and it’s a non-issue 99% of the time.

Where it does do something awkward e.g. to long expressions with lots of operators in, usually it’s actually a sign that you can make it clearer by splitting it into multiple smaller expressions which helps overall readability.

I think you can also tell prettier to ignore certain lines, though I don’t think I’ve ever needed to.

Re: Prettier 2.0 – Opinionated JavaScript formatter

#29
A bit irritating that formatting zealots are changing the defaults. What can possibly drive the decision to change whatever option it is they landed on and deployed? It's contrary to everything they claimed Prettier was about: for better or worse, we have decided on X so we can all move on to more important issues.

I feel like the cost of changing defaults is wildly underestimated because it's decided on by people who are so deeply engaged in the product.

It means either all my code now needs a config file added or all my code will need to be updated.

Re: Prettier 2.0 – Opinionated JavaScript formatter

#30
post #11
post #6

Prettier is one of my favourite pieces of software! I only wish they had a binary that doesn’t rely on Node.js

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.

Post reply on HN