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¶
StyleCop's exceptions: 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:
- 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 (StyleCop reports these; CSharpier removes the blank line again). -
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
}whenstylebro_blank_line_between_switch_sections(BRO1526) wants no blank line there (omit, oromit_after_blockafter a section ending in a block).
Compared with StyleCop¶
Same positions and output, apart from the places left to the rules above and a } followed by a token that
continues its expression or pattern (not reported).