4 ms·
Anybody know if it’s possible to run a formater before diffing? For example running “go fmt” or “prettier”?
by arve0 5y ago
Anybody know if it’s possible to run a formater before diffing? For example running “go fmt” or “prettier”?
- TheChaplain 5y agoWouldn't it be better to do that before committing? Or by using a hook? Since diff is used to make patches it could ruin things I imagine..
- arve0 5y agoYes, using a hook is optimal. But when reading repos without a style guide or formater, “pretty diffing” makes it easier to review. Another use case is when you encounter that giga god-commit “added formater” which touched all lines in all files. If you take this even further, you can tailor to anyones style taste, formatting on check out instead of check in. That leaves the stored code as a serialization format the compiler understands. Viewed code is in whatever format the programmer likes.
- 5e92cb50239222b 5y agoI haven't tested this, but maybe it will serve you as a starting point. Throw this script into $PATH (let's say into ~/.local/bin/diff-fmt): #!/bin/bash exec delta <(gofmt "$1") <(gofmt "$2") here I'm using delta as the difftool: https://github.com/dandavison/delta https://github.com/dandavison/delta and then, once: $ git config --global interactive.diffFilter diff-fmt
- arve0 5y agoThank you, will try it out :-)