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

Code Style: Code fixes for xml doc comments #7070

Open
9 of 17 tasks
Pilchie opened this issue Nov 25, 2015 · 28 comments
Open
9 of 17 tasks

Code Style: Code fixes for xml doc comments #7070

Pilchie opened this issue Nov 25, 2015 · 28 comments
Labels
Area-IDE Feature Request help wanted The issue is "up for grabs" - add a comment if you are interested in working on it InternalAsk
Milestone

Comments

@Pilchie
Copy link
Member

Pilchie commented Nov 25, 2015

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

@sharwell
Copy link
Member

💭 Well this could be interesting, especially if you find a way to support custom implementations of the code fix.

@DustinCampbell DustinCampbell self-assigned this Dec 1, 2015
@aluanhaddad
Copy link

👍

@DustinCampbell DustinCampbell modified the milestones: 2.0 (Preview), 1.2, 1.3 Feb 22, 2016
@Hosch250
Copy link
Contributor

In VSDiagnostics (provides analyzers/fixes for C#), we have issues for redundant/missing returns, missing exception blocks, missing summaries, and generally malformed docs (like a missing closing tag), in addition to the parameter ones.

@Pilchie
Copy link
Member Author

Pilchie commented Jul 30, 2016

It doesn't look like we're going to get to this before 2.0 😦

Moving back to unknown until we decide to pick it up, but marking as Up for Grabs, because we'd likely take contributions that added the fixes.

@Pilchie Pilchie modified the milestones: unkwn, 2.0 (Preview 4), Unknown Jul 30, 2016
@Hosch250
Copy link
Contributor

Hosch250 commented Jul 31, 2016

I'd be interested in tackling this, but I didn't say anything because I saw there were two open PR's for it, so I thought it was already spoken for.

@Pilchie
Copy link
Member Author

Pilchie commented Jul 31, 2016

@Hosch250 - thanks for pointing that out. I see #10520, but I don't see another PR?

@Hosch250
Copy link
Contributor

#5611 and #10520 are both referenced in the issue just above your comment from an hour ago.

@Pilchie
Copy link
Member Author

Pilchie commented Jul 31, 2016

Right, but #5611 is another (related) issue, not a PR :)

@Hosch250
Copy link
Contributor

Oh, my mistake.

@Pilchie
Copy link
Member Author

Pilchie commented Jul 31, 2016

Anyway, I pinged @3jr about #10520 to see if it's abandoned.

@daviburg
Copy link

daviburg commented Aug 8, 2017

Also known as StyleCop's rule SA1600 : CSharp.Documentation : The {class|...} must have a documentation header.

@jinujoseph jinujoseph added the help wanted The issue is "up for grabs" - add a comment if you are interested in working on it label Mar 8, 2018
@kendrahavens
Copy link
Contributor

Closed developer feedback as duplicate.

Additional notes:

  • Make configurable public, protected, internal or private members/classes/interfaces/etc...

@jmarolf jmarolf added the User Story A single user-facing feature. Can be grouped under an epic. label Dec 2, 2021
@BDisp
Copy link

BDisp commented Dec 7, 2021

Is there any compiler warning when a parameterized method without any XML comments parameters, but already with the summary XML comment?

@CyrusNajmabadi
Copy link
Member

@BDisp can you give an example of what you mean?

@BDisp
Copy link

BDisp commented Dec 7, 2021

@BDisp can you give an example of what you mean?

Of course, thanks.

/// <summary>
/// Function foo
/// </summary>
public void Foo(string a, string b)
{
}

This should give a compiler warning, such as missing parameters in the XML comment. But it doesn't.

@CyrusNajmabadi
Copy link
Member

@BDisp Thanks for the example!

@BDisp
Copy link

BDisp commented Dec 8, 2021

@CyrusNajmabadi in my opinion there also should have compiler warnings for the following situations, whose alerts can be disabled or enabled by the user:

Missing returns tag in the XML Comment

/// <summary>
/// Foo
/// </summary>
/// <param name="x"></param>
/// <param name="a"></param>
public string Foo (int x, string a)
{
	return $"{a}{x}";
}
Missing typeparam in the XML Comment

/// <summary>
/// Foo
/// </summary>
/// <param name="a"></param>
/// <param name="x"></param>
public void Foo<S, N> (string a, int x) where S : Bar, new() where N : FooBar, new()
{
}

It does not make much sense the compiler alerts that a parameter is missing when there is more than one and not alert when there is none.

@CyrusNajmabadi
Copy link
Member

Note: you'd be able to get this today (which is much more likely) just by writing your own analzyers. It's possible stylecop may already have this.

@BDisp
Copy link

BDisp commented Dec 9, 2021

Thanks. The compilation it's very slow. I prefer to wait for the CS fix :-)

@BDisp
Copy link

BDisp commented Dec 9, 2021

It would be great to warn if any tag is empty.

"Documentation text should not be empty, for 'x' and 'a'"

/// <summary>
/// Foo
/// </summary>
/// <param name="x"></param>
/// <param name="a"></param>
public void Foo (int x, string a)
{
}

@CyrusNajmabadi
Copy link
Member

@BDisp imo, it's very unlikely we would do this. Adding new diagnostics for existing legal code is almost entirely preferred to be done through analyzers.

@sharwell
Copy link
Member

sharwell commented Dec 9, 2021

Note: you'd be able to get this today (which is much more likely) just by writing your own analzyers. It's possible stylecop may already have this.

StyleCop Analyzers does already have a few rules for this.
https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/DocumentationRules.md

Some of the rules also have code fixes; a table showing them is here:
https://dotnetanalyzers.github.io/StyleCopAnalyzers/

@CyrusNajmabadi
Copy link
Member

Thanks @sharwell ! Given that, i believe we'd be much more inclined to keep things as the status quo (As far as roslyn or csharplang are concerned). This would be a space we'd say is ripe for external analyzers to step in for.

In terms of this issue @sharwell, what do you think we should do? I personally don't think we need code-style/fixes in the IDE. However, i would be ok with code refactorings, which users could bring up in existing doc-comments to "add the missing elements" as it were. So, if you had:

/// <summary>
/// Function foo
/// </summary>
public int Foo(string a, string b)
{
}

And you brought up the lightbulb in the doc comment, there would be items like:

  1. Add missing <param> tags
  2. Add missing <return> tag
  3. Add all missing tags

Would that be something you think would be good for us to have?

@BDisp
Copy link

BDisp commented Dec 9, 2021

@CyrusNajmabadi, it's not code fixes I asking for, but only warnings at compile time. Some analyzers tools read this warnings and presents suggestion for some code fixes.

@CyrusNajmabadi
Copy link
Member

@BDisp

but only warnings at compile time.

I understand. This is a perfect place for analyzers. Their purpose is exactly to do things like just give warnings at compile time. The compiler/lang is highly unlikely to add these as it's already possible to do today, fairly simply, with analyzers. And there is already plenty of precedent for tools (like style-cop) to do this.

@jmarolf jmarolf removed the User Story A single user-facing feature. Can be grouped under an epic. label Jan 6, 2022
@github-project-automation github-project-automation bot moved this to InQueue in Small Fixes Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Feature Request help wanted The issue is "up for grabs" - add a comment if you are interested in working on it InternalAsk
Projects
Status: InQueue
Development

No branches or pull requests