Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Use Prettier #9101
Because manual code formatting in so 2016.
A few caveats...
Lint has an issue with some of this stuff. We need to modify lint to exclude the rules that are incompatible with prettier.
We have been inconsistent with line wrapping. We used to strict follow 80 characters but recently we've been more up to 120ish.
Overall it seems pretty good!
The change of concatenated string on multiple lines is probably the biggest change.
In terms of tooling how should we set this up?
We'll probably want CI to run and ensure that nothing gets reformatted.
Do we want the precommit hooks in the repo or should this be a manual step? A manual step is annoying but not too bad. An auto-installed precommit hook in the repo is fairly aggressive. I'd be worried that it would mess something up with no way to revert since the original is not in the history.
Another solution could be a post-commit amend. That way the original commit is still in
FWIW, I've been using a pre-commit hook with
While I understand the concern about loosing work, the chance of prettier removing something at all is tiny, and then to remove something that's critical and you can't trivially reproduce based on the context is... highly unlikely.
In my opinion, the cost of having to comment under many PRs with failed CIs because the submitters forgot to run prettier is higher than the potential to loose critical, irreplaceable work. This is subjective, so take it with a grain of salt, but I think it makes sense to run it in a pre commit hook.
We treat those as "unbreak-now" priority. We ran extensive fuzzing on the codebase to detect this. The one place where there likely are disappearing content is with comments, but we detect when we don't print all the comments and throw an exception instead of silently dropping it.
referenced this pull request
Mar 9, 2017
We set it up as a lint step for Jest, similar to how it would work if it was internally at Facebook.
This will throw if files are not printing correctly and tell people what to do. A large part of