Skip to content

BRO1519: Closing brace should be followed by blank line

A statement after a block is separated from it by a blank line. Replaces StyleCop SA1513.

Example

Before

public class Ledger
{
    public int Sum(int[] values)
    {
        var total = 0;
        foreach (var value in values)
        {
            total += value;
        }
        return total;
    }
}

After

public class Ledger
{
    public int Sum(int[] values)
    {
        var total = 0;
        foreach (var value in values)
        {
            total += value;
        }

        return total;
    }
}

Why

The blank line marks where the block's work ends and the next step begins.

How the fix works

A blank line is inserted after the }. Fixes that create a } followed by a statement (BRO1514 adding braces, BRO1508/BRO1509 expanding a one-line block) add this blank line themselves when this rule is on, so one dotnet format run is enough.

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

Not reported

Not when what follows is }, else, catch, finally, a do statement's while, ), ,, ; ending an initializer, return or throw, ., :, =>, &&, ||, ], an accessor, a query clause, a //// comment or a directive, a property initializer's =; the braces are on one line; the } closes an interpolation; it is the last } in the file. Also:

  • The next accessor, also when it starts with a modifier or an attribute ([MethodImpl(...)] set => ...), the same as without one. Between two accessors with block bodies, BRO1505 decides.
  • An empty statement's ; after the } (};) when BRO1101 is on: it removes the ;, and the blank line would be left in front of what follows.
  • A } inside an expression or pattern followed by a token that continues it: ?, ??, ?., a binary operator, switch, with, is, as, when, a designation. Such a } doesn't end a block (CSharpier removes the blank line again).
  • A checked or unchecked statement after the } when CSharpier formats the repository (stylebro_layout_by = csharpier, written by bro init): CSharpier removes every blank line above such a statement, so the two formatters would undo each other.

  • A comment, documentation or a member after the }: BRO1504, BRO1513 and BRO1505 ask for that blank line (when they're on), so two fixes don't add it twice.

  • Code after the } on its line, or a comment after it: there's no line to put the blank line after.
  • A switch section after the } when stylebro_blank_line_between_switch_sections (BRO1526) wants no blank line there (omit, or omit_after_block after a section ending in a block).