black
black copied to clipboard
Show trailing space in diff in explicit way
Hi, I have a project with precommit hook that calls [black --check --diff] and fails commit on non-empty diff. Egor (collegue of mine) suddenly added space after last character in line but diff looks confusing:
-)
+)
I could see the source by checkout his branch and running black over it but this is a long way. Could black show trailing spaces in some explicit way? It will be appreciated even by specifying some CLI option. Thank you.
Hmm, this seems like a reasonable request, and we could append some character when we see trailing spaces in the diff. Something like ↲
and when I have 5 trailing spaces in original text and 10 trailing spaces after changes then diff will look in the same way as it is now.
I think it is better do create some magic but add Unicode representation of all characters.
I mean, the diff would look something like this:
-) ↲
+)↲
I'll note that if we accept this it must be disabled by default so tools that call black in a subprocess with --diff
can use the diff without needing to manually strip ↲
. We'd have to add another flag (or maybe hack it into --color
?)
True and good catch. But this doesn't seem worthy of a dedicated flag like --highlight-trailing-spaces
. Perhaps something like --rich
for color + whatever else magic we want to add? 🤷♂️