Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we use Prettier (or similar formatter) for Javascript code? #16115

Closed
trivikr opened this issue Oct 10, 2017 · 11 comments
Closed

Can we use Prettier (or similar formatter) for Javascript code? #16115

trivikr opened this issue Oct 10, 2017 · 11 comments
Labels
meta Issues and PRs related to the general management of the project. question Issues that look for answers.

Comments

@trivikr
Copy link
Member

trivikr commented Oct 10, 2017

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?

@mscdex mscdex added meta Issues and PRs related to the general management of the project. question Issues that look for answers. labels Oct 10, 2017
@mscdex
Copy link
Contributor

mscdex commented Oct 10, 2017

I would guess as long as the eslint config is happy, then sure, go ahead.

@trivikr
Copy link
Member Author

trivikr commented 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
Copy link
Member Author

trivikr commented 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
Copy link
Member

BridgeAR commented 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
Copy link
Member Author

trivikr commented 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
Copy link
Member

We only switched from closure_linter to eslint two years ago!

Like @BridgeAR mentions, eslint is already pretty good at fixing style issues.

@mscdex
Copy link
Contributor

mscdex commented 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
Copy link
Member Author

trivikr commented 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
Copy link
Member

Trott commented Oct 15, 2017

Seems like this can be closed. If I'm mistaken about that, please comment. Thanks!

@Trott Trott closed this as completed Oct 15, 2017
@gengjiawen
Copy link
Member

Prettier is different from eslint, it bring the consistent style for project like semicolons and quotes.

@gengjiawen
Copy link
Member

I did a little dig

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meta Issues and PRs related to the general management of the project. question Issues that look for answers.
Projects
None yet
Development

No branches or pull requests

6 participants