[C#] Rule for multiple empty lines in a row

Hello

Rule: Do not use multiple empty lines in a row

We use this in C#, but it is applicable for any language. There may be a parameter to how many empty lines in a row are accepted. This is a styling rule, which makes source code a bit more concise and nicer.

Noncompliant code

function void f1() {
    int i;



    i = Compute();
}


function void f2() {
    ...
}

Compliant Code

function void f1() {
    int i;

    i = Compute();
}

function void f2() {
    ...
}

I’m not sure if Sonar should invest time in rules like these (I use such an analyser too). There are other libs already doing so. But that is a strategic decision that is up to them.

Hi @satano,

Thank you for suggesting this rule.

I think you can already have this rule by using StyleCop. See rule SA1507CodeMustNotContainMultipleBlankLinesInARow.
SonarQube and SonarCloud are able to import roslyn issues: https://docs.sonarqube.org/latest/analysis/external-issues/

Reimplementing this rule wouldn’t add much value and could impact the user experience. The technical debt wouldn’t make much sense if this issue can be fixed automatically in 5 minutes on the whole codebase.

Let us know if it works for you.