Skip to content

no-doc-slashes-in-plain-comment

C#stylefix: safedefault: offcsharp/stylecop

Reports a /// comment that holds only text and no XML element: a plain comment written with documentation slashes. The fix writes //, unless the comment documents a declaration (it would remove documentation).

Three slashes make the comment documentation, and the compiler and tools then read it as XML. A plain remark written that way is attached to the next declaration and shown in its hover, or reported as malformed.

To fix, write //.

Reported
...
public class PlainComments
{
/// plain text on a field
public int Field;
/// first line
/// second line
public void Attached() { }
/// <summary>Good.</summary>
...
void Body()
{
/// plain in a body
int j = 0;
///
int k = 0;
...
//// four slashes
public int Four;
int last; ///trailing
}
/// <summary>Text.</summary>
...
After the fix
...
public class PlainComments
{
/// plain text on a field
public int Field;
/// first line
/// second line
public void Attached() { }
/// <summary>Good.</summary>
...
void Body()
{
// plain in a body
int j = 0;
//
int k = 0;
...
//// four slashes
public int Four;
int last; //trailing
}
/// <summary>Text.</summary>
...
csharp:
lint:
rules:
no-doc-slashes-in-plain-comment: warn # off (default), warn, error

Enabled by the presets: csharp/stylecop.

Suppress one line with sudsy-disable-next-line no-doc-slashes-in-plain-comment in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
StyleCop SA1626 full