yapf icon indicating copy to clipboard operation
yapf copied to clipboard

Only reformat modified lines

Open stefano-maggiolo opened this issue 7 years ago • 2 comments

For an established project it is difficult to justify a humongous commit with all yapf's changes in one go, so adoption becomes difficult.

A lighter approach would be to instruct authors to use yapf to format only the lines they modified in the commit. This gets most of the advantages (no discussions on style, no need to point out all formatting mistakes), with an easy adoption path (and long term convergence).

Sadly, the only option to limit the scope I see is the range of lines. I assume it would be possible to make a git hook to reformat only changed lines based on that, but it looks very cumbersome. Is this kind of git integration planned, already existing and I missed it, or something you would consider adding?

Thanks!

stefano-maggiolo avatar Mar 26 '18 20:03 stefano-maggiolo

The last reply on this issue works, you can have a try.

BoWuGit avatar Oct 17 '19 08:10 BoWuGit

One way to introduce YAPF (or any other formatter) to a project is indeed doing a huge commit and then using git blame ignore to ignore that format commit. The git annotations stay clean and meaningful.

martin-ueding avatar Aug 27 '21 07:08 martin-ueding