dotnet/roslyn

Code Style: Code fixes for xml doc comments

Open

#7,070 opened on Nov 25, 2015

View on GitHub
 (28 comments) (3 reactions) (0 assignees)C# (4,257 forks)batch import
Area-IDEInternalAskhelp wanted

Repository metrics

Stars
 (20,414 stars)
PR merge metrics
 (Avg merge 6d 17h) (256 merged PRs in 30d)

Description

We already have the "Insert Comment" command (and /// experience), but we should hook it up as a Code Fix to the compiler warnings about missing XML doc comments.

CSharp

Below are the diagnostics that we could potentially create code fixes for:

  • CS1571: XML comment has a duplicate param tag for '{0}'
  • CS1572: XML comment has a param tag for '{0}', but there is no parameter by that name
  • CS1573: Parameter '{0}' has no matching param tag in XML comment for '{1}' (but other parameters do)
  • CS1591: Missing XML comment for publicly visible type or member '{0}'

Here's code that will exhibit all four diagnostics when the /doc argument is passed to the compiler.

public class C
{
    /// <param name="x"></param>
    /// <param name="x"></param>
    /// <param name="z"></param>
    public void Foo(int x, int y)
    {

    }
}

image

Visual Basic

Below are the diagnostics that we could potentially create code fixes for:

  • BC42301: Only one XML comment block is allowed per language element.
  • BC42303: XML comment cannat appear with a method or a property. XML comment will be ignored.
  • BC42305: XML comment tag '{0}' appears with identical attributes more than once in the same XML comment block.
  • BC42306: XML comment tag '{0}' is not permitted on a 'sub' language element.
  • BC42307: XML comment parameter '{0}' does not match a parameter on the corresponding 'sub' statement.
  • BC42308: XML comment parameter must have 'name' attribute.
  • BC42312: XML documentation comments must precede member or type declarations.
  • BC42313: XML comment tag 'returns' is not permitted on a 'WriteOnly' Property.
  • BC42314: XML comment cannot be applied more than once on a partial class. XML comments for this class will be ignored.
  • BC42315: XML comment tag 'returns' is not permitted on a 'declare sub' language element.
  • BC42317: XML comment type parameter '{0}' does not match a type parameter on the corresponding '{1}' statement.
  • BC42318: XML comment type parameter must have a 'name' attribute.
  • BC42319: XML comment exception must have a 'cref' attribute.

Here's code that will surface each of the above diagnostics.

''' <summary>
''' 
''' </summary>
Partial Class C

End Class

''' <summary>
''' 
''' </summary>
Partial Class C

    '''

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="i"></param>
    ''' <param name="i"></param>
    ''' <param></param>
    ''' <param name="j"></param>
    ''' <typeparam name="T"></typeparam>
    ''' <typeparam></typeparam>
    ''' <returns></returns>
    ''' <exception></exception>
    Public Sub M(i As Integer)

        ''' <summary></summary>

    End Sub

    ''' <returns></returns>
    WriteOnly Property P As Integer
        Set(value As Integer)
        End Set
    End Property

    ''' <returns></returns>
    Declare Sub Foo Lib "User" ()

End Class

''' <summary>
''' </summary>

image

Contributor guide