4

My project is in C#, which ignores whitespace, both spaces and in particular newlines.

When entering the diff view in Github, I know I can use the ?w=1 url parameter to ignore whitespace.

But it does not completely ignore whitespace. The line:

somethingLong + somethingAlsoLong

Gets transformed like this:

somethingLong +
somethingAlsoLong

I still get such changes showing up in the Github diff when my colleagues are reviewing it.

I understand such whitespace changes are meaningful in languages like Python but not in C#. Resharper liberally applies them, including line splitting.

Forcing a Resharper run on all files before they are committed would be better, but that does not happen often. When I make a change, I run Resharper over the file but it also hits functions that I did not change, therefore, polluting my commit.

The files probably should be normalized for spacing anyway but I'd prefer an option to ignore the meaningless whitespace changes (including newlines) when doing so. This is so the pull request diff view in GitHub shows my reviewers what I've really changed.

Is there a way to achieve this?

Noel Bahdy
  • 29
  • 4
Clinton
  • 22,361
  • 15
  • 67
  • 163

2 Answers2

1

If the online review is not satisfactory (here because of end of line diff), then a reviewer in your project will have to Check out pull requests locally.

Once checked out, a local diff can be done against the target branch, this time with diff tool able to ignore the difference between a+b and a\n+\nb.
That involves:

  • diff options (which would not be available through online GitHub alone)
  • or a semantic diff tool like SemanticMerge (non-free though)
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

GitHub's whitespace ignore filter won't work in your case because it only ignores leading or trailing whitespace. Ignoring whitespace changes everywhere would be wrong, as they make a difference in strings. What you are looking for is a semantic diff that parses the code and can therefore decide whether a whitespace or a new line is relevant.

In case you are still looking for a solution, I am working on a pull request viewer that allows you to view GitHub PRs with a semantic diff. Here is an example very similar to the one you described: While GitHub shows 1 deleted and 4 new lines due to the added line breaks, my pull request viewer only shows the added argument (1 new line).

Currently, the viewer only supports public pull requests, but if that works for you, you can just go to https://app.semanticdiff.com and enter the URL of the pull request you want to view.

DarkPlayer
  • 96
  • 1
  • 2