Repository navigation
Can we use Prettier (or similar formatter) for Javascript code? #16115
Description
Activity
- addedmetaIssues and PRs related to the general management of the project.Issues and PRs related to the general management of the project.questionIssues asking questions about Node.js.Issues asking questions about Node.js.
on Oct 10, 2017 I would guess as long as the eslint config is happy, then sure, go ahead.
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 optionEslint 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.
We only switched from closure_linter to eslint two years ago!
Like @BridgeAR mentions, eslint is already pretty good at fixing style issues.
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.
Seems like this can be closed. If I'm mistaken about that, please comment. Thanks!
Prettier is different from eslint, it bring the consistent style for project like semicolons and quotes.
- React: react/react@1843f87
325 changed files with 12,714 additions and 11,413 deletions. - Babel: babel/babel@e4b35f6
307 changed files with 6,764 additions and 4,102 deletions.
- React: react/react@1843f87
I did a little dig
- node gengjiawen@517c95c
2,193 changed files with 67,859 additions and 50,688 deletions.
- node gengjiawen@517c95c
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:
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?