Skip to content

Commit

Permalink
Update PropertySummaryDocumentationAnalyzer to bail out earlier if th…
Browse files Browse the repository at this point in the history
…e current node is not an XmlElementSyntax
  • Loading branch information
bjornhellander committed Aug 2, 2024
1 parent ff5c432 commit a61e80b
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ internal class PropertySummaryDocumentationAnalyzer : PropertyDocumentationBase
/// <inheritdoc/>
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XmlNodeSyntax syntax, XElement completeDocumentation, Location diagnosticLocation)
{
if (!(syntax is XmlElementSyntax summaryElement))
{
// This is reported by SA1604 or SA1606.
return;
}

var propertyDeclaration = (PropertyDeclarationSyntax)context.Node;
var propertyType = context.SemanticModel.GetTypeInfo(propertyDeclaration.Type.StripRefFromType());
var culture = settings.DocumentationRules.DocumentationCultureInfo;
Expand All @@ -70,7 +76,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, Styl
{
AnalyzeSummaryElement(
context,
syntax,
summaryElement,
diagnosticLocation,
propertyDeclaration,
resourceManager.GetString(nameof(DocumentationResources.StartingTextGetsWhether), culture),
Expand All @@ -82,7 +88,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, Styl
{
AnalyzeSummaryElement(
context,
syntax,
summaryElement,
diagnosticLocation,
propertyDeclaration,
resourceManager.GetString(nameof(DocumentationResources.StartingTextGets), culture),
Expand All @@ -92,7 +98,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, Styl
}
}

private static void AnalyzeSummaryElement(SyntaxNodeAnalysisContext context, XmlNodeSyntax syntax, Location diagnosticLocation, PropertyDeclarationSyntax propertyDeclaration, string startingTextGets, string startingTextSets, string startingTextGetsOrSets, string startingTextReturns)
private static void AnalyzeSummaryElement(SyntaxNodeAnalysisContext context, XmlElementSyntax summaryElement, Location diagnosticLocation, PropertyDeclarationSyntax propertyDeclaration, string startingTextGets, string startingTextSets, string startingTextGetsOrSets, string startingTextReturns)
{
var diagnosticProperties = ImmutableDictionary.CreateBuilder<string, string>();
ArrowExpressionClauseSyntax expressionBody = propertyDeclaration.ExpressionBody;
Expand All @@ -116,12 +122,6 @@ private static void AnalyzeSummaryElement(SyntaxNodeAnalysisContext context, Xml
}
}

if (!(syntax is XmlElementSyntax summaryElement))
{
// This is reported by SA1604 or SA1606.
return;
}

// Add a no code fix tag when the summary element is empty.
// This will only impact SA1623, because SA1624 cannot trigger with an empty summary.
if (summaryElement.Content.Count == 0)
Expand Down

0 comments on commit a61e80b

Please sign in to comment.