Skip to content

BRO1120: Comments should contain text

An empty comment at the start or end of a comment (or on its own) is removed. Replaces StyleCop SA1120.

Example

Before

public class Report
{
    public int Total()
    {
        //
        // Sums the lines.
        //
        // Rounding happens later.
        //
        return 0;
    }
}

After

public class Report
{
    public int Total()
    {
        // Sums the lines.
        //
        // Rounding happens later.
        return 0;
    }
}

Why

An empty comment is noise; inside a comment, an empty line separates paragraphs and stays.

How the fix works

Comments on consecutive lines form a group. Empty // or /* */ comments are reported at the start and the end of a group; the fix removes every empty comment at that end, so one run is enough. When the removed lines sat between two blank lines, the blank lines below them go too, so no two blank lines are left in a row (BRO1517). A comment after code starts a new group, and //// (commented-out code) isn't empty.

Configuration

bro init turns the rule off (dotnet_diagnostic.BRO1120.severity = none) when your code frames its comments with empty // lines (// / // text / //, Mono style) in most places or mixes both forms (init's conventions).

Not reported

  • Empty lines in the middle of a comment, which separate paragraphs.
  • Empty comments that are all a pair of braces holds (catch / { / // / }): they mark the block as empty on purpose, and removing them would leave a bare { }.
  • The file header: the comments a file starts with, also right below a leading #region line (#region Apache License). Their empty // lines belong to the header's text, and IDE0073 writes them from a file_header_template that starts or ends with a line break.