BRO1525: Attributes should not be followed by a blank line¶
No blank line between an attribute list and the element it applies to, or between two attribute lists of the same element. Not a StyleCop rule: StyleCop proposed it as SA1521 (AttributesMustNotBeFollowedByBlankLine, issue #738) and never implemented it.
Example¶
Before¶
using System;
public class Order
{
public void Ship()
{
}
[Obsolete("Use Ship.")]
public void Send()
{
}
public int Count
{
[Obsolete("Use Size.")]
get => 0;
}
}
After¶
using System;
public class Order
{
public void Ship()
{
}
[Obsolete("Use Ship.")]
public void Send()
{
}
public int Count
{
[Obsolete("Use Size.")]
get => 0;
}
}
Why¶
An attribute is part of the declaration below it. A blank line after it makes it look like it belongs to nothing, or to the code above; BRO1511 asks the same of documentation comments.
How the fix works¶
It removes the blank lines between the attribute list and the next line of code. BRO1505 (elements
separated by a blank line) doesn't count those lines, since an element's code starts at its first attribute: a member
whose only blank line sits below its attribute gets BRO1505's blank line above the attribute, in the same
dotnet format run.
Not reported¶
- A comment, documentation comment or directive between the attribute and the element (
[Theory], a blank line, a// ...comment): BRO1504 wants a blank line above a comment that follows code, and an#ifchanges which element the attribute applies to. - Assembly and module attributes (
[assembly: ...]): they apply to no element below them. - Code with syntax errors around the element.
Compared with StyleCop¶
StyleCop has no such rule. Its maintainers gave it the id SA1521 in issue
#738 ("up for grabs" since 2015), but it was never
implemented and has no documentation page. stylebro-migrate turns this rule off, so migrating doesn't change a
StyleCop-clean repository.