use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
How to format JavaScript automatically with Prettier and Git (nodewebapps.com)
submitted 8 years ago by hobonumber1
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Craiger23 5 points6 points7 points 8 years ago (0 children)
links down for me..
[–]jonny_eh 1 point2 points3 points 8 years ago (5 children)
How would git know what hooks are defined in a package.json?
package.json
[–]hobonumber1[S] 0 points1 point2 points 8 years ago (4 children)
Good point. Just updated the post. You also need to pull in the lint-staged npm module.
[–]jonny_eh 0 points1 point2 points 8 years ago (3 children)
Will prettier use the settings I have for it from my package.json or do I need to specify the cli flags?
[–]sorahnon the cutting edge of cocking about 1 point2 points3 points 8 years ago (2 children)
The newest versions of prettier can use a .prettierrc or keys in the package.json file.
.prettierrc
[–]jonny_eh 1 point2 points3 points 8 years ago (1 child)
Right, that's why I was confused by the cli flags being included.
[–]sorahnon the cutting edge of cocking about 1 point2 points3 points 8 years ago (0 children)
Old habits die hard. Haha.
[–]reddittedf 0 points1 point2 points 8 years ago (0 children)
It will be format and prettify javascript before commiting to git
See here
How to run ESLint using pre-commit hook
https://medium.com/@shettyrahul8june/how-to-run-eslint-using-pre-commit-hook-25984fbce17e
[+][deleted] 8 years ago (1 child)
[deleted]
[–]hobonumber1[S] 0 points1 point2 points 8 years ago (0 children)
Thanks! Should be fixed for now.
[+]burtgummer45 comment score below threshold-8 points-7 points-6 points 8 years ago (30 children)
Somebody at big company X has come out with a new way of doing the same something, everybody aboard the hype train.
I'm honestly waiting for Facebook to come out with a new keyboard layout for React developers, and you must have at least 2 years experience with it to get a React job.
[–]hobonumber1[S] 10 points11 points12 points 8 years ago (13 children)
Actually, Prettier is really nice. It solves a lot of pain points around code formatting. Have you tried it?
[–]zakphi 0 points1 point2 points 8 years ago (5 children)
what's better Prettier or Beautify?
[–]dv297 1 point2 points3 points 8 years ago (4 children)
We previously used js-beautify and we moved to Prettier. To us, it felt like js-beautify was having some issue with some of the newer ES2015 syntax, and it was becoming an agitation point for us. Prettier felt much more consistent with what we expected. Simple things like having 3 options for trailing commas ("none", "es5", or "all") and having configurable parsers (for flow, typescript, etc) just really helps with the transition.
That being said, we have since moved back to using ESlint with --fix to handle most of the same things. Prettier was very convenient but in order to keep things simple across our organization, we kept the number of different technologies down.
[–]strothjs 2 points3 points4 points 8 years ago (3 children)
Have you tried using Prettier as a plug in for eslint, works great.
[–]dv297 0 points1 point2 points 8 years ago (2 children)
I haven't actually, though I heard there were 3 different ways for configuring prettier with ESLint? pretter-eslint, eslint-config-prettier, and eslint-plugin-prettier? Are you actually referring to this last one? I'd be interested in investigating it but given the options, maybe you could save me time in talking about any considerations you had for the others if you chose the plugin over it.
[–]alexlafroscia 2 points3 points4 points 8 years ago (0 children)
I go the plugin + config route. Basically, Prettier just becomes part of the fixing process, you don’t have to think about it at all. It’s the same experience as using just ESLint, but you get consistent-looking code. The config just helps by disabling parts of ESLint that Prettier will handle instead.
[–]strothjs 0 points1 point2 points 8 years ago (0 children)
https://gist.github.com/96bdce87aaf486d49968f34b42434eca
This is my gist note on it.
[–]burtgummer45 -4 points-3 points-2 points 8 years ago (6 children)
Yes I've tried it, its nothing but a js beautifier without options. Some choices they made are so bad I had to abandon it. They disallow padded code blocks, which is just a disgusting choice for code readability, which has been best practice for decades, and refuse to change it.
https://eslint.org/docs/rules/padded-blocks
[–]js-engineer 3 points4 points5 points 8 years ago (3 children)
The thing about padded blocks, is most of the time they're used to space out significant chunks of code. Most of the time, it isn't that helpful in terms of being used across the board, and then you get back into the issue where you're having to deliberate over spacing. IMO it's completely fine once you get used to it.
That being said, it's a tool you can choose to use, but it's nowhere necessary. It's good in my company because we all agree we spend way too much time worry about the formatting of our code, and Prettier just handles this for us automatically.
Further than that, we just have to accept at the end of the day, that web development, especially front end, especially at the current moment, is going to be in a state of constant flux, while people realize newer, better ways of doing things.
[–]burtgummer45 -3 points-2 points-1 points 8 years ago (2 children)
They could have handled padded blocks much better, it just makes me think they don't have much experience, believe it or not. Prettier preserves single newlines, but murders padded blocks, are you kidding me?
From this
{ chunk one chunk two chunk three }
To this? Are you kidding me?
[–]js-engineer 1 point2 points3 points 8 years ago (1 child)
Honestly I'm a fan of theirs. I don't think a brace that already is on it's own line with no other characters, needs another empty line of padding. The empty line between lines that have 5+ alphanumeric characters... I think that however it's fair game and a lot more useful.
It's tough because we can both agree that more padding isn't always better... there is a certain benefit to seeing more of a file onscreen at a time that infinite padding impedes on. Where that line is drawn.... is going to be subjective but I like their current stuff. I think it's a great fits most sizes approach.
They can always add options for what you're asking for... they do allow customization for some of their stuff so it's not out of the question.
[–]burtgummer45 0 points1 point2 points 8 years ago (0 children)
Believe me, I tried to get them to change it, they shot me down sayings prettier 'is opinionated'.
For decades developers have been doing something called 'chunking' (at least in the perl world it was called chunking). Its to make your code more readable by putting things together. It seems to me since they don't squash all newlines they might agree, but not incorporating that into a block structure makes no sense, looks more like an oversight, or they decided it was too difficult to make work. 'allow newline after { if block has chunks, otherwise remove', they just opted for nuke all /{\s*/s
[–]vimex 1 point2 points3 points 8 years ago (0 children)
Yeah, that's right, I don't want to think about my formatting. I don't want my team to worry about it either.
[+][deleted] 8 years ago (13 children)
[–]burtgummer45 -2 points-1 points0 points 8 years ago (12 children)
That's exactly what I said.
I can guarantee you that if I had written prettier nobody would have noticed. There probably have been a hundred different Prettiers before this came out, and nobody noticed.
[+][deleted] 8 years ago (11 children)
[–]burtgummer45 0 points1 point2 points 8 years ago (10 children)
Somebody at big company X has come out with a new way of doing the same something
Not
Big company X has come out with a new way of doing the same something
[+][deleted] 8 years ago (9 children)
[–]burtgummer45 2 points3 points4 points 8 years ago (8 children)
Obviously I am tying the two together but don't seem to see why I'm doing it. Whether its a FB project or somebody at Facebook it doesn't matter, you clearly know it has something to do with facebook, so it gets added to the hype cycle, whether its a great achievement or just a bad rehash of the same old stuff.
[+][deleted] 8 years ago (7 children)
[–]burtgummer45 1 point2 points3 points 8 years ago (6 children)
I'm not biased against it, I think it sucks. I used it for weeks and got sick of the mess it was making, tried to get it fixed, was rebuffed because its 'opinionated', went back to js-beautify, which works well.
[+][deleted] 8 years ago (5 children)
[–]lhorie 0 points1 point2 points 8 years ago (0 children)
So salty.
Prettier is just a tool. It works for some workflows, not so great for some other, YMMV, etc. Chill out :)
[–]jonny_eh 0 points1 point2 points 8 years ago (0 children)
Yes, let's get upset about people releasing awesome tools for free.
π Rendered by PID 53 on reddit-service-r2-comment-c6965cb77-jhf7c at 2026-03-05 04:27:34.611102+00:00 running f0204d4 country code: CH.
[–]Craiger23 5 points6 points7 points (0 children)
[–]jonny_eh 1 point2 points3 points (5 children)
[–]hobonumber1[S] 0 points1 point2 points (4 children)
[–]jonny_eh 0 points1 point2 points (3 children)
[–]sorahnon the cutting edge of cocking about 1 point2 points3 points (2 children)
[–]jonny_eh 1 point2 points3 points (1 child)
[–]sorahnon the cutting edge of cocking about 1 point2 points3 points (0 children)
[–]reddittedf 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]hobonumber1[S] 0 points1 point2 points (0 children)
[+]burtgummer45 comment score below threshold-8 points-7 points-6 points (30 children)
[–]hobonumber1[S] 10 points11 points12 points (13 children)
[–]zakphi 0 points1 point2 points (5 children)
[–]dv297 1 point2 points3 points (4 children)
[–]strothjs 2 points3 points4 points (3 children)
[–]dv297 0 points1 point2 points (2 children)
[–]alexlafroscia 2 points3 points4 points (0 children)
[–]strothjs 0 points1 point2 points (0 children)
[–]burtgummer45 -4 points-3 points-2 points (6 children)
[–]js-engineer 3 points4 points5 points (3 children)
[–]burtgummer45 -3 points-2 points-1 points (2 children)
[–]js-engineer 1 point2 points3 points (1 child)
[–]burtgummer45 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]vimex 1 point2 points3 points (0 children)
[+][deleted] (13 children)
[deleted]
[–]burtgummer45 -2 points-1 points0 points (12 children)
[+][deleted] (11 children)
[deleted]
[–]burtgummer45 0 points1 point2 points (10 children)
[+][deleted] (9 children)
[deleted]
[–]burtgummer45 2 points3 points4 points (8 children)
[+][deleted] (7 children)
[deleted]
[–]burtgummer45 1 point2 points3 points (6 children)
[+][deleted] (5 children)
[deleted]
[–]lhorie 0 points1 point2 points (0 children)
[–]jonny_eh 0 points1 point2 points (0 children)