Skip to content

BRO1518: Closing braces should not be preceded by blank line

A closing brace directly follows the code above it. Replaces StyleCop SA1508.

Example

Before

public class Inventory
{
    public int Count(int[] items)
    {
        return items.Length;

    }
}

After

public class Inventory
{
    public int Count(int[] items)
    {
        return items.Length;
    }
}

Why

A blank line before } separates nothing from nothing, and makes the end of the block harder to see.

How the fix works

The blank lines between the last line of code (or comment) and the } are removed.

This rule replaces the SDK's IDE2002, which writes merge conflict markers in multi-targeted projects under dotnet format (see decisions).

Not reported

  • Below a // comment on its own line when BRO1506 is on (below a trailing comment, x(); // note, they are reported: BRO1506 skips those), and in an empty block ({, blank lines, }) when BRO1503 is on: those rules remove the same lines.

Compared with StyleCop

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