-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Comments
💭 Well this could be interesting, especially if you find a way to support custom implementations of the code fix. |
👍 |
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. |
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. |
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. |
Right, but #5611 is another (related) issue, not a PR :) |
Oh, my mistake. |
Also known as StyleCop's rule SA1600 : CSharp.Documentation : The {class|...} must have a documentation header. |
Closed developer feedback as duplicate. Additional notes:
|
Is there any compiler warning when a parameterized method without any XML comments parameters, but already with the summary XML comment? |
@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. |
@BDisp Thanks for the example! |
@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. |
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. |
Thanks. The compilation it's very slow. I prefer to wait for the CS fix :-) |
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)
{
} |
@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. |
StyleCop Analyzers does already have a few rules for this. Some of the rules also have code fixes; a table showing them is here: |
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:
Would that be something you think would be good for us to have? |
@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. |
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. |
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:
Here's code that will exhibit all four diagnostics when the /doc argument is passed to the compiler.
Visual Basic
Below are the diagnostics that we could potentially create code fixes for:
Here's code that will surface each of the above diagnostics.
The text was updated successfully, but these errors were encountered: