[C#] New rule: Remove whitespace characters at the end of line

Hello

I have a new rule suggestion. We use it in C#, but it is general for any language.

Rule: Remove empty whitespace character at the end of line

This is a code style rule. Nowaday, most of the editors have a functionality (either built-in or by extension), that automatically removes whitespace characters when document is saved. But many developer still do not use it and leave spaces or tabs at the end of lines. This pollutes diff view - there are more changes than necessary.

Whitespace characters are marked as · in next example

Noncompliant code

function void f() {····
    int i;
····
    i = Compute();··
}

Compliant code

function void f() {
    int i;

    i = Compute();
}

Hi @satano,

Thank you for this suggestion. I understand that not every developer configures their editor the same way, and I believe that git hooks are often used for this purpose. See this blog post for example.

I see how SonarQube/SonarCloud could be used to block any pull request which adds trailing spaces. However I don’t see why developers would chose SonarQube/SonarCloud as their favorite tool to do it if a git-hook can fix it more efficiently. Could you describe your team’s current workflow and explain why you prefer to have this in SonarQube/SonarCloud?

Cheers,
Nicolas

Hi @satano,

A rapid update, I hadn’t seen that we actually have this rule for Swift, python, javascript and other languages (See S1131).

I took a look on our internal validation instance, and I see that some big python projects such as Pypy, Locust and IPython have a high number of issues. This result in an unrealistic technical debt: 15 hours just for this rule on Pypy. For C++ it is even worse, for example LibreOffice has 268,994 issues, each with 1min technical debt (4000+ hours in total). Either there are False Positives or this rule is not followed (which I agree is bad).

I think this is why this rule is not part of the Sonar Way Quality profile. SonarQube/SonarCloud are clearly not designed to handle this use case. We could implement an equivalent for C# but we still wouldn’t be able to add it to the Sonar Way Quality profile.

Cheers,
Nicolas