sindresorhus/refined-github

whitespace changes in PRs: count, highlight, etc #2775

diesalbla posted onGitHub

There are ongoing issues about displaying (or hiding) whitespace changes in the diffs of Pull Requests.

On that part of the functionality, perhaps some of the following changes may be found helpful by many developers.

  • Together with the "Lines added" and "lines deleted" counters, introduce a special counter for lines with only whitespace changes... e.g. instead of +15 -22, use +10, w5, -17.
  • In the diff view of Pull Requests, use a different colour for highlighting lines with only whitespace changes, such as softer forms of red and green, or a form of blue.
  • (Advanced): If several contiguous lines have a similar change of whitespace (indentation), then some symbol overlied could be used to indicate so. This symbol could be like the one used in LibreOffice, for indentation.
  • (Advanced) In addition to the above, apart from changes of whitespace-characters in some lines, it would also be useful to count as whitespace changes the introduction of new empty or whitespace-onlt lines (the ones you can filter with ^\w*$.

Example URL:

Consider the following Pull Request https://github.com/http4s/http4s/pull/3099/files, which by use of an automatic formatting tool introduces a lot of indentation changes.


  • Together with the "Lines added" and "lines deleted" counters, introduce a special counter for lines with only whitespace changes... e.g. instead of +15 -22, use +10, w5, -17.

It looks like GitHub updates that counter when using ?w=1, so adding this might be easy, with an extra request. Ideally this could be done via API but I don't think GraphQL offers an option to hide whitespace. Prove me wrong.

In the diff view of Pull Requests, use a different colour for highlighting lines with only whitespace changes, such as softer forms of red and green, or a form of blue.

This is not a bad idea but, together with the next two suggestions, it requires us to implement a "whitespace-only change" detection algorithm, which may be different from git's. Maybe this is easy, but I'm not familiar with it.

  • (Advanced): If several contiguous lines have a similar change of whitespace (indentation), then some symbol overlied could be used to indicate so. This symbol could be like the one used in LibreOffice, for indentation.

What does this say on top of the previously-suggested color change? It sounds like a symbol that tells the same story: this is whitespace, ignore.

  • (Advanced) In addition to the above, apart from changes of whitespace-characters in some lines, it would also be useful to count as whitespace changes the introduction of new empty or whitespace-onlt lines (the ones you can filter with ^\w*$.

It's a good practice to set your editor/linter to drop/highlight these lines since they're useless, so I would not ignore them as I consider them an error.

posted by fregante about 5 years ago

In the end, I think that it's still a better idea (and easier too) to just switch to the w=1 view, if a PR has a lot of whitespace changes.

The first suggestion would provide a good indicator though; +5 -1 w10 would tell me:

This PR has a lot of whitespace-only changes so maybe ignore it with w=1.

posted by fregante about 5 years ago

Fund this Issue

$0.00
Funded

Pull requests