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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider using prettier for code formatting #2837

Closed
mgcrea opened this issue Feb 5, 2021 · 9 comments
Closed

Consider using prettier for code formatting #2837

mgcrea opened this issue Feb 5, 2021 · 9 comments

Comments

@mgcrea
Copy link
Contributor

mgcrea commented Feb 5, 2021

馃殌 Feature Proposal

Use prettier for code formatting, add a .prettierc file and actively check for proper formatting on commit.

Motivation

Currently looking into writing some unit tests and having to manually adapt the code styling to prevent eslint errors is a pain! Imo prettier is such a net positive for developer experience that it feels like a no-brainer.

Looks like you actively guard against it so I guess you have another view on this, but maybe not definitive?

Adding a prettier config file of your liking and performing a one-shot --write to fix current formatting issues would lead to a more pleasant developer experience.

@mcollina
Copy link
Member

mcollina commented Feb 5, 2021

(Copied from #2269)

FYI: standard --fix does this for you. You can configure your editor to do it as well.

You probably have prettier configured as plugin in your editor to automatically lint every possible JS file it encounters. This is such a bad practice and have caused so much traffic in my repos because valid contributions completely changed the formatting of my projects: it is rude. Hence my distaste for the VSCode prettier extension and its default configuration.

Once upon a time, I set up Fastify to not to contribute to spread this phenomenon. I think changing linting is such a pain for the maintainers to never be a net benefit.

@mcollina
Copy link
Member

mcollina commented Feb 5, 2021

I'm not opposing adding a prettier config that will cause minimal changes to the repo (<100 lines, lesser is better). I don't think it's possible.

@jsumners
Copy link
Member

jsumners commented Feb 5, 2021

Please see the guide to be added by #2610

@mgcrea
Copy link
Contributor Author

mgcrea commented Feb 5, 2021

You probably have prettier configured as plugin in your editor to automatically lint every possible JS file it encounters. This is such a bad practice and have caused so much traffic in my repos because valid contributions completely changed the formatting of my projects: it is rude. Hence my distaste for the VSCode prettier extension and its default configuration.

@mcollina no I don't have my vscode configured to auto-prettify every js file, I agree this is a bad practice. It only ever runs if there is a prettier config file in the project (which obviously might/should be the default).

However I do have an eslint extension that runs when there is an eslint config file in the project, which is the case here and that nags me (rightfully) for not respecting the code formatting.

I just think that having prettier is a superior developer experience than having to manually please a myriad of style-related eslint rules.

Will have a try at a prettier config file and let you know.

@mgcrea
Copy link
Contributor Author

mgcrea commented Feb 5, 2021

Ok back from my testing, indeed the changes were in the thousands and not in the hundreds.

Main line-diff contributing issues were:

  • standard space-before-function-paren that is not configurable in prettier.
  • function block indentation issues that moves indentation of whole blocks.
  • semicolons used inconsistently across the project (~300 lines with semicolons).

I personnaly think that prettier is a net-win for any team project, but I would understand your choice of not changing the code too much and keeping the current status-quo.

If you want to have a look at the changes:

master...mgcrea:feat-prettier

@jsumners
Copy link
Member

jsumners commented Feb 5, 2021

  • semicolons used inconsistently across the project (~300 lines with semicolons).

Standard relies on automatic semi-colon insertion except for the few cases where that is not viable.

@jsumners
Copy link
Member

jsumners commented Feb 5, 2021

This would be a drastic change to many people's workflow. It also wouldn't account for the many other repositories within the overall ecosystem. I do not see this as a "net benefit" for the project.

The reality is that different projects have different styles. When contributing to a project it is incumbent upon the contributor to accept that fact and conform their contributions to said style. As a corollary, it is incumbent upon the project to make that as easy as possible for potential contributors. We are attempting to do that via #2837 (comment).

@mcollina mcollina closed this as completed Feb 5, 2021
@mcollina
Copy link
Member

mcollina commented Feb 5, 2021

Thanks for the discussion @mgcrea! I think you bring us so many valid points - I guess we'll stick with standard but it's good to keep talking about why.

@mgcrea
Copy link
Contributor Author

mgcrea commented Feb 5, 2021

I totally understand, thanks for the quick feedback and openness to discussion 馃憤 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants