Skip to content

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. bro migrate turns this rule off, so migrating doesn't change a repository that was clean before.

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 #if changes 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.