Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RCS1181 code fix can produce code with CS1570 (XML comment has badly formed XML) #1527

Closed
Bergam64 opened this issue Sep 17, 2024 · 0 comments · Fixed by #1534
Closed

RCS1181 code fix can produce code with CS1570 (XML comment has badly formed XML) #1527

Bergam64 opened this issue Sep 17, 2024 · 0 comments · Fixed by #1534
Assignees

Comments

@Bergam64
Copy link

Bergam64 commented Sep 17, 2024

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 a property. The comment must contain at least 1 < or &.

Actual Behavior:

namespace MyNamespace
{
    /// <summary>
    /// ...
    /// </summary>
    public class Class1
    {
        internal int MyProperty { get; set; } // Must be >= 0 & <= 5. <-- RCS1181: Convert comment to documentation comment
    }
}

Applying code fix produces this:

namespace MyNamespace
{
    /// <summary>
    /// ...
    /// </summary>
    public class Class1
    {
        /// <summary>
        /// Must be >= 0 & <= 5. <-- CS1570 is reported 3 times here!
        /// </summary>
        internal int MyProperty { get; set; }
    }
}

In this example, compiler errors are:

  • CS1570: XML comment has badly formed XML -- 'Whitespace is not allowed at this location.'
  • CS1570: XML comment has badly formed XML -- 'An identifier was expected.'
  • CS1570: XML comment has badly formed XML -- 'The character(s) '=' cannot be used at this location.'

Expected Behavior:

namespace MyNamespace
{
    /// <summary>
    /// ...
    /// </summary>
    public class Class1
    {
        /// <summary>
        /// Must be >= 0 &amp; &lt;= 5.
        /// </summary>
        internal int MyProperty { get; set; }
    }
}

Note that encoding other XML special chars (>, " and ') is not required (at least for Visual Studio 2022) and doing so would produce source XML comments that are more complex to read (for developers) than needed.

Bottom line: RCS1181 should replace < with &lt; and & with &amp; (but IMHO leave >, " and ' unchanged).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants