You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Can we use Prettier (or similar formatter) for Javascript code? #16115
Can we use Prettier for formatting Javascript code in NodeJS?
Prettier is an opinionated code formatter. It removes all original styling and ensures that all outputted code conforms to a consistent style.
Reasons:
Right now there are 1600 contributors in NodeJS repository (thanks to its huge popularity), but every Javascript developer has their own style of formatting.
Some code is difficult to read because of manual formatting. Prettier will ensure that such issue will not occur.
We recently started using Prettier for private projects, and life has been better. We don't worry/argue about formatting any more :-)
Of course there was initial oppositions to some of the decisions taken by Prettier (like lack of parenthesis around single param arrow functions), but we got used to it with time.
For Open Source projects which don't use Prettier, I manually run Prettier CLI for the files which I'm editing. I believe developers will be more productive if we use formatters like Prettier in NodeJS. What do you think?
Prettier is going to remove all original styling in code and reprint it from scratch. So it'll touch all the Javascript files and create merge conflicts for all pull requests.
It's going to be a big move - we'll have to find out how other big projects like react, jest, babeljs have done it.
I wanted to hear about what other contributors/owners think about it.
In my private repos, moving to Prettier was simple as we incorporated it during the beginning of the new projects.
@mscdex I've used Prettier CLI on the code which I've contributed to NodeJS.
The only difference I noticed is node eslint config requires us to put parenthesis around single parameter arrow functions - where Prettier doesn't provide an option
Eslint itself is a very powerful prettier and formatter. I would rather not add another tool. If there is need for more explicit styling there is probably already a rule in eslint that could be added. Adding one rule at a time also reduces the churn and it will be easier to find a compromise between all collaborators and their individual wishes.
Prettier just takes care of stylistic issues.
We still need to use eslint for enforcing good coding practices and avoiding bugs.
The move to Prettier will be tough in the beginning, but with time we'll see the benefits as we no longer worry about formatting and concentrate on code.
Maybe I misunderstood, I thought the suggestion was if individual contributors could use it on their own. Adopting it officially project-wide is probably not a good idea as Ben and Ruben have said.
Yeah, individual developers are free to use any formatter they want as long as it doesn't interfere with eslint rules. I use Prettier CLI, and add parenthesis for single param arrow functions before running make lint in my code.
Activity
mscdex commentedon Oct 10, 2017
I would guess as long as the eslint config is happy, then sure, go ahead.
trivikr commentedon Oct 10, 2017
Prettier is going to remove all original styling in code and reprint it from scratch. So it'll touch all the Javascript files and create merge conflicts for all pull requests.
It's going to be a big move - we'll have to find out how other big projects like react, jest, babeljs have done it.
I wanted to hear about what other contributors/owners think about it.
In my private repos, moving to Prettier was simple as we incorporated it during the beginning of the new projects.
trivikr commentedon Oct 10, 2017
@mscdex I've used Prettier CLI on the code which I've contributed to NodeJS.
The only difference I noticed is node eslint config requires us to put parenthesis around single parameter arrow functions - where Prettier doesn't provide an option
BridgeAR commentedon Oct 10, 2017
Eslint itself is a very powerful prettier and formatter. I would rather not add another tool. If there is need for more explicit styling there is probably already a rule in eslint that could be added. Adding one rule at a time also reduces the churn and it will be easier to find a compromise between all collaborators and their individual wishes.
trivikr commentedon Oct 10, 2017
Prettier just takes care of stylistic issues.
We still need to use eslint for enforcing good coding practices and avoiding bugs.
The move to Prettier will be tough in the beginning, but with time we'll see the benefits as we no longer worry about formatting and concentrate on code.
bnoordhuis commentedon Oct 10, 2017
We only switched from closure_linter to eslint two years ago!
Like @BridgeAR mentions, eslint is already pretty good at fixing style issues.
mscdex commentedon Oct 10, 2017
Maybe I misunderstood, I thought the suggestion was if individual contributors could use it on their own. Adopting it officially project-wide is probably not a good idea as Ben and Ruben have said.
trivikr commentedon Oct 10, 2017
Yeah, individual developers are free to use any formatter they want as long as it doesn't interfere with eslint rules. I use Prettier CLI, and add parenthesis for single param arrow functions before running make lint in my code.
Trott commentedon Oct 15, 2017
Seems like this can be closed. If I'm mistaken about that, please comment. Thanks!
gengjiawen commentedon Nov 18, 2018
Prettier is different from eslint, it bring the consistent style for project like semicolons and quotes.
325 changed files with 12,714 additions and 11,413 deletions.
307 changed files with 6,764 additions and 4,102 deletions.
gengjiawen commentedon Nov 18, 2018
I did a little dig
2,193 changed files with 67,859 additions and 50,688 deletions.