Skip to content

RCS1181 wrongly considers that namespaces can have XML comments #1525

@Bergam64

Description

@Bergam64

Product and Version Used:
VS extension Roslynator 2022 v4.12.5

Steps to Reproduce:

  • Enable RCS1181 in your .editorconfig file (disabled by default).
  • Make sure the containing project is configured to generate documentation files:
    • Open project Properties.
    • Go to page Build -> Output
      • Generate a file containing API documentation
  • Open a C# file and add a comment after the namespace.

Actual Behavior:

namespace MyNamespace // Some comment. <-- RCS1181: Convert comment to documentation comment
{
    /// <summary>
    /// ...
    /// </summary>
    public class Class1
    {
        internal int MyProperty { get; set; }
    }
}

which is wrong, because applying the code fix produces code that triggers a compiler error:

/// <summary> <-- CS1587: XML comment is not placed on a valid language element
/// Some comment.
/// </summary>
namespace MyNamespace
{
    /// <summary>
    /// ...
    /// </summary>
    public class Class1
    {
        internal int MyProperty { get; set; }
    }
}

Expected Behavior:

namespace MyNamespace // Comment. <-- No RCS1181
{
    /// <summary>
    /// ...
    /// </summary>
    public class Class1
    {
        internal int MyProperty { get; set; }
    }
}

You can't add documentation comments to a namespace (see first table here).

Bottom line: RCS1181 should never be reported for comments on namespaces.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions