Skip to content

Commit

Permalink
Update SA1611 to suppress messages when documentation for an element …
Browse files Browse the repository at this point in the history
…is optional

Fixes DotNetAnalyzers#2444
  • Loading branch information
sharwell committed Jun 20, 2017
1 parent 5400cf3 commit b99dd6e
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,25 @@ public class ClassName
await this.VerifyCSharpDiagnosticAsync(testCode.Replace("##", p), expected, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
[WorkItem(2444, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2444")]
public async Task TestPrivateMethodMissingParametersAsync()
{
var testCode = @"
internal class ClassName
{
///
private void Test1(int arg) { }
/**
*
*/
private void Test2(int arg) { }
}";

await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
/// Verifies that valid operator declarations will not produce diagnostics.
/// </summary>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public SA1608ElementDocumentationMustNotHaveDefaultSummary()
ImmutableArray.Create(Descriptor);

/// <inheritdoc/>
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, IEnumerable<XmlNodeSyntax> syntaxList, params Location[] diagnosticLocations)
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, bool needsComment, IEnumerable<XmlNodeSyntax> syntaxList, params Location[] diagnosticLocations)
{
foreach (var syntax in syntaxList)
{
Expand All @@ -79,7 +79,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, IEnu
}

/// <inheritdoc/>
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, XElement completeDocumentation, params Location[] diagnosticLocations)
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
{
// We are working with an <include> element
var includedSummaryElement = completeDocumentation.Nodes().OfType<XElement>().FirstOrDefault(element => element.Name == XmlCommentHelper.SummaryXmlTag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@ public SA1611ElementParametersMustBeDocumented()
ImmutableArray.Create(Descriptor);

/// <inheritdoc/>
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, IEnumerable<XmlNodeSyntax> syntaxList, params Location[] diagnosticLocations)
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, bool needsComment, IEnumerable<XmlNodeSyntax> syntaxList, params Location[] diagnosticLocations)
{
if (!needsComment)
{
// Omitting documentation for a parameter is allowed for this element.
return;
}

var node = context.Node;
var parameterList = GetParameters(node);
if (parameterList == null)
Expand All @@ -69,8 +75,13 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, IEnu
}

/// <inheritdoc/>
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, XElement completeDocumentation, params Location[] diagnosticLocations)
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
{
if (!needsComment)
{
// Omitting documentation for a parameter is allowed for this element.
}

var node = context.Node;
var parameterList = GetParameters(node);
if (parameterList == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public SA1612ElementParameterDocumentationMustMatchElementParameters()
ImmutableArray.Create(MissingParameterDescriptor);

/// <inheritdoc/>
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, IEnumerable<XmlNodeSyntax> syntaxList, params Location[] diagnosticLocations)
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, bool needsComment, IEnumerable<XmlNodeSyntax> syntaxList, params Location[] diagnosticLocations)
{
var node = context.Node;
var identifier = GetIdentifier(node);
Expand Down Expand Up @@ -112,7 +112,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, IEnu
}

/// <inheritdoc/>
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, XElement completeDocumentation, params Location[] diagnosticLocations)
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
{
var node = context.Node;
var identifier = GetIdentifier(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public SA1613ElementParameterDocumentationMustDeclareParameterName()
ImmutableArray.Create(Descriptor);

/// <inheritdoc/>
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, IEnumerable<XmlNodeSyntax> syntaxList, params Location[] diagnosticLocations)
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, bool needsComment, IEnumerable<XmlNodeSyntax> syntaxList, params Location[] diagnosticLocations)
{
foreach (var syntax in syntaxList)
{
Expand All @@ -71,7 +71,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, IEnu
}

/// <inheritdoc/>
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, XElement completeDocumentation, params Location[] diagnosticLocations)
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
{
var xmlParamTags = completeDocumentation.Nodes()
.OfType<XElement>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public SA1614ElementParameterDocumentationMustHaveText()
ImmutableArray.Create(Descriptor);

/// <inheritdoc/>
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, IEnumerable<XmlNodeSyntax> syntaxList, params Location[] diagnosticLocations)
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, bool needsComment, IEnumerable<XmlNodeSyntax> syntaxList, params Location[] diagnosticLocations)
{
foreach (var syntax in syntaxList)
{
Expand All @@ -66,7 +66,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, IEnu
}

/// <inheritdoc/>
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, XElement completeDocumentation, params Location[] diagnosticLocations)
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
{
var xmlParamTags = completeDocumentation.Nodes()
.OfType<XElement>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public SA1616ElementReturnValueDocumentationMustHaveText()
ImmutableArray.Create(Descriptor);

/// <inheritdoc/>
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, IEnumerable<XmlNodeSyntax> syntaxList, params Location[] diagnosticLocations)
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, bool needsComment, IEnumerable<XmlNodeSyntax> syntaxList, params Location[] diagnosticLocations)
{
foreach (var syntax in syntaxList)
{
Expand All @@ -64,7 +64,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, IEnu
}

/// <inheritdoc/>
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, XElement completeDocumentation, params Location[] diagnosticLocations)
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
{
var returnsNodes = completeDocumentation.Nodes()
.OfType<XElement>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public SA1625ElementDocumentationMustNotBeCopiedAndPasted()
ImmutableArray.Create(Descriptor);

/// <inheritdoc/>
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, IEnumerable<XmlNodeSyntax> syntaxList, params Location[] diagnosticLocations)
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, bool needsComment, IEnumerable<XmlNodeSyntax> syntaxList, params Location[] diagnosticLocations)
{
var objectPool = SharedPools.Default<HashSet<string>>();
HashSet<string> documentationTexts = objectPool.Allocate();
Expand Down Expand Up @@ -119,7 +119,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, IEnu
}

/// <inheritdoc/>
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, XElement completeDocumentation, params Location[] diagnosticLocations)
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
{
var objectPool = SharedPools.Default<HashSet<string>>();
HashSet<string> documentationTexts = objectPool.Allocate();
Expand Down

0 comments on commit b99dd6e

Please sign in to comment.