Skip to content

BRO1102: Each attribute should be in its own brackets

[A, B] should be written as [A] and [B]. Replaces StyleCop SA1133.

Example

Before

using System;
using System.Diagnostics;

public class Report
{
    [Obsolete("Use Render"), DebuggerStepThrough]
    public string Print() => "report";
}

After

using System;
using System.Diagnostics;

public class Report
{
    [Obsolete("Use Render")]
    [DebuggerStepThrough]
    public string Print() => "report";
}

Why

One attribute per line is easier to scan, and adding or removing an attribute changes exactly one line in a diff.

How the fix works

A list on its own line becomes one line per attribute, at the same indentation. A list that shares its line with code stays on that line: [Obsolete, DebuggerStepThrough] void M() becomes [Obsolete] [DebuggerStepThrough] void M(). A target is repeated on every part: [assembly: A, B] becomes [assembly: A] and [assembly: B]. Arguments are kept exactly as written.

Not reported

  • Attributes on parameters and type parameters (void M([A, B] int x)), like StyleCop.
  • Lists with a comment or directive between the attributes ([A, /* why */ B]). Splitting would have to move or drop the comment.

Compared with StyleCop

StyleCop also reports lists with a comment between the attributes, and its fix drops the comment.