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

Ali Kamalizade
CodeX

--

Photo by Farzad Nazifi on Unsplash

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.

“Formatted files with Prettier”: 556 changed files with 13,395 additions and 13,388…

--

--

Ali Kamalizade
CodeX
Writer for

Co-founder of Sunhat. Posts about software engineering, startups and anything else. 有難うございます。🚀