Skip to content

Commit 1a1b365

Browse files
authored
Merge pull request #2869 from sharwell/ref-docs
Update documentation analyzer to handle ref returns
2 parents cc1b7b7 + 956c999 commit 1a1b365

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/DocumentationRules/SA1623CSharp7UnitTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ public class SA1623CSharp7UnitTests : SA1623UnitTests
4848
[InlineData("protected internal", "int", "{ private get => 0; set => this.field = value; }", "Sets")]
4949
[InlineData("internal", "int", "{ get => 0; private set => this.field = value; }", "Gets")]
5050
[InlineData("internal", "int", "{ private get => 0; set => this.field = value; }", "Sets")]
51+
52+
[WorkItem(2861, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2861")]
53+
[InlineData("public", "ref int", "{ get => throw null; }", "Gets")]
5154
public async Task VerifyDocumentationWithWrongStartingTextWillProduceDiagnosticWithExpressionBodiedAccessorsAsync(string accessibility, string type, string accessors, string expectedArgument)
5255
{
5356
var testCode = $@"

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/PropertySummaryDocumentationAnalyzer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace StyleCop.Analyzers.DocumentationRules
1212
using Microsoft.CodeAnalysis.CSharp.Syntax;
1313
using Microsoft.CodeAnalysis.Diagnostics;
1414
using StyleCop.Analyzers.Helpers;
15+
using StyleCop.Analyzers.Lightup;
1516

1617
/// <summary>
1718
/// Analyzes the correct usage of property summary documentation.
@@ -60,7 +61,7 @@ internal class PropertySummaryDocumentationAnalyzer : PropertyDocumentationBase
6061
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, bool needsComment, XmlNodeSyntax syntax, XElement completeDocumentation, Location diagnosticLocation)
6162
{
6263
var propertyDeclaration = (PropertyDeclarationSyntax)context.Node;
63-
var propertyType = context.SemanticModel.GetTypeInfo(propertyDeclaration.Type);
64+
var propertyType = context.SemanticModel.GetTypeInfo(propertyDeclaration.Type.StripRefFromType());
6465
var settings = context.Options.GetStyleCopSettings(context.CancellationToken);
6566
var culture = new CultureInfo(settings.DocumentationRules.DocumentationCulture);
6667
var resourceManager = DocumentationResources.ResourceManager;

StyleCop.Analyzers/StyleCop.Analyzers/Helpers/TypeSyntaxHelper.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace StyleCop.Analyzers.Helpers
55
{
6+
using Microsoft.CodeAnalysis;
67
using Microsoft.CodeAnalysis.CSharp;
78
using Microsoft.CodeAnalysis.CSharp.Syntax;
89
using StyleCop.Analyzers.Lightup;
@@ -55,5 +56,15 @@ public static bool IsReturnType(this TypeSyntax syntax)
5556
return false;
5657
}
5758
}
59+
60+
public static TypeSyntax StripRefFromType(this TypeSyntax syntax)
61+
{
62+
if (syntax.IsKind(SyntaxKindEx.RefType))
63+
{
64+
syntax = ((RefTypeSyntaxWrapper)syntax).Type;
65+
}
66+
67+
return syntax;
68+
}
5869
}
5970
}

0 commit comments

Comments
 (0)