Skip to content

Enable Trailing Comma Rule in Prettier - #51451

Merged
megcrenshaw merged 2 commits into
stagingfrom
meg/lint-danging-comma
Apr 24, 2023
Merged

Enable Trailing Comma Rule in Prettier#51451
megcrenshaw merged 2 commits into
stagingfrom
meg/lint-danging-comma

Conversation

@megcrenshaw

@megcrenshaw megcrenshaw commented Apr 21, 2023

Copy link
Copy Markdown

As part of Molly's upgrade to Prettier (2.8.7) #51065, we now have an override to disable the trailing comma rule

trailingComma: "none",

The default value for the trailing comma rule changed as part of the Prettier upgrade https://prettier.io/docs/en/options.html#trailing-commas to "es5":

"es5" - Trailing commas where valid in ES5 (objects, arrays, etc.). No trailing commas in type parameters in TypeScript.

This PR removes the override to use the default value and updates existing files with the automated --fix feature. When I first removed the override, I ran bundle exec rake lint:javascript and got

✖ 26315 problems (26315 errors, 0 warnings)
  26315 errors and 0 warnings potentially fixable with the `--fix` option.

I then ran yarn lint:js -- --fix which yielded

➜  code-dot-org git:(meg/lint-danging-comma) ✗ gc -m "Run yarn lint:js -- --fix"
[meg/lint-danging-comma 764ee0ecc19] Run yarn lint:js -- --fix
 2633 files changed, 26367 insertions(+), 26315 deletions(-)

I committed those files, all of which were in the apps directory, and then ran bundle exec rake lint:javascript again and got no errors.

Links

Argument to enable trailing commas: https://medium.com/@nikgraf/why-you-should-enforce-dangling-commas-for-multiline-statements-d034c98e36f8

Testing story

Deployment strategy

Follow-up work

Privacy

Security

Caching

PR Checklist:

  • Tests provide adequate coverage
  • Privacy and Security impacts have been assessed
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

@megcrenshaw
megcrenshaw marked this pull request as ready for review April 21, 2023 12:43
@megcrenshaw megcrenshaw changed the title Meg/lint danging comma Enable Trailing Comma Rule in Prettier Apr 21, 2023

@levadadenys levadadenys left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
@molly-moen , @code-dot-org/studentlearning , you might wanna also take take a look

@bencodeorg bencodeorg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely felt a little skeptical off the bat, but the article you shared (and the fact that it's a default!) sold me. Thanks for doing this!

@molly-moen molly-moen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That article convinced me too, I'm in favor!

@megcrenshaw
megcrenshaw merged commit ed5f33b into staging Apr 24, 2023
@megcrenshaw
megcrenshaw deleted the meg/lint-danging-comma branch April 24, 2023 12:44
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

Successfully merging this pull request may close these issues.

4 participants