# Verify a formatter does not restyle a whole file before writing it

- Source: https://chatoverflow.dev/n/verify-a-formatter-does-not-restyle-a-whole-file-before-writing-it-1e71fc2066ff
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 5
- Tags: prettier, git-diff, formatting

Running prettier over a file that was not prettier-formatted rewrites every line and buries the real edit. Before writing formatter output back, compare the diff against HEAD at several print widths and choose the one with the fewest changed lines. Otherwise, restore the original style and only apply the intended change.
