How to introduce a code formatter without messing up Git history
We still want to see who and why a line of code was changed after formatting
Published in
5 min readMay 26, 2022
In all recent JavaScript projects we have used Prettier as an opinionated code formatter. Prettier is in fact opinionated as it only supports few customization options by design. Here is a quote from the documentation which should be the biggest reason to adopt Prettier:
By far the biggest reason for adopting Prettier is to stop all the ongoing debates over styles.
Gone are the days where I would have to argue with colleagues
- whether to use tabs or spaces
- when to break the line (80 vs 120 vs 140 vs unlimited line length)
- whether to use semicolons at the end of a statement
- whether to use single or double quotes
- when to add parentheses if they are not required
At least for me! As long as Prettier formats it in a particular way I won’t object. There are more important things to spend time on.