Skip to content

BRO1517: Code should not contain multiple blank lines in a row

Two or more blank lines in a row become one. Replaces StyleCop SA1507.

Example

Before

public class Report
{
    public int Total(int a, int b)
    {
        var sum = a + b;


        return sum;
    }
}

After

public class Report
{
    public int Total(int a, int b)
    {
        var sum = a + b;

        return sum;
    }
}

Why

One blank line separates; more add scrolling without saying anything more.

How the fix works

The first blank line stays, the others are removed, in every run of blank lines at once (also several runs between directives, like empty #regions in a row). Blank lines inside strings and in disabled #if code aren't touched.

This rule replaces the SDK's IDE2000, which writes merge conflict markers in multi-targeted projects under dotnet format and also counts blank lines at the start of a file and before } (see decisions).

Not reported

  • At the start or end of the file: the end is BRO1507's.
  • Right after {, right before } and below a // comment when BRO1503, BRO1518 or BRO1506 is on: those rules remove all of them there. Blank lines between two comments are BRO1517's again (BRO1506 allows a blank line above a comment).

Compared with StyleCop

Same positions and output, apart from the places left to the rules above.