BRO1002: Single-line comments should begin with a space¶
A // comment should have a space between the slashes and the text. Replaces StyleCop SA1005.
Example¶
Before¶
public class Invoice
{
//Total including VAT.
public decimal Total { get; set; }
public decimal Net() => Total / 1.25m; //VAT is 25%
}
After¶
public class Invoice
{
// Total including VAT.
public decimal Total { get; set; }
public decimal Net() => Total / 1.25m; // VAT is 25%
}
Why¶
Comments read like prose, and // note is how almost all C# code writes them. Consistent spacing also makes
commented-out code (////) and separator lines (//----) stand out from real comments.
How the fix works¶
The fix inserts a space and keeps any tabs after //: commented-out code indented with tabs keeps its layout (//
still ends before the first tab stop). A comment with nothing but whitespace becomes //.
Not reported¶
- Comments that already start with whitespace, including
// two spacesfor indented text. - An empty comment (
//). ///and////, which are used for documentation and commented-out code.- Separator lines starting with
//--, such as//-----------. dotnet newtemplate markers starting with//-:or//+:(//-:cnd:noEmit), which a space would break.- Text in inactive
#ifblocks, which isn't a comment to the compiler.