Skip to content

Commit 9557f27

Browse files
Updated PropertySummaryDocumentationAnalyzer to always report SA1623 for a property with a lone setter.
1 parent 816dc8f commit 9557f27

2 files changed

Lines changed: 32 additions & 7 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1623UnitTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ public int Property
196196
[InlineData("protected", "int", "=> 0;", "Gets or sets", "Gets")] // Regression test for #2253
197197
[InlineData("protected internal", "int", "=> 0;", "Gets or sets", "Gets")] // Regression test for #2253
198198
[InlineData("internal", "int", "=> 0;", "Gets or sets", "Gets")] // Regression test for #2253
199+
[InlineData("public", "int", "{ set {} }", "Gets", "Sets")] // Regression test for #2253
200+
[InlineData("public", "int", "{ set {} }", "Gets or sets", "Sets")] // Regression test for #2253
199201
public async Task IncorrectSummaryTagWithKnownPrefixShouldBeFixedCorrectlyAsync(string accessibility, string type, string accessors, string summaryPrefix, string expectedArgument)
200202
{
201203
var testCode = $@"

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

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -282,16 +282,39 @@ private static void AnalyzeSummaryElement(SyntaxNodeAnalysisContext context, Xml
282282
}
283283
else if (setterVisible)
284284
{
285-
if (startsWithGetsOrSets)
285+
if (getter != null)
286286
{
287-
diagnosticProperties.Add(ExpectedTextKey, startingTextSets);
288-
diagnosticProperties.Add(TextToRemoveKey, startingTextGetsOrSets);
289-
context.ReportDiagnostic(Diagnostic.Create(SA1624Descriptor, diagnosticLocation, diagnosticProperties.ToImmutable(), "set", startingTextSets));
287+
// Both getter and setter exist, but only setter is visible
288+
if (startsWithGetsOrSets)
289+
{
290+
diagnosticProperties.Add(ExpectedTextKey, startingTextSets);
291+
diagnosticProperties.Add(TextToRemoveKey, startingTextGetsOrSets);
292+
context.ReportDiagnostic(Diagnostic.Create(SA1624Descriptor, diagnosticLocation, diagnosticProperties.ToImmutable(), "set", startingTextSets));
293+
}
294+
else if (!startsWithSets)
295+
{
296+
diagnosticProperties.Add(ExpectedTextKey, startingTextSets);
297+
context.ReportDiagnostic(Diagnostic.Create(SA1623Descriptor, diagnosticLocation, diagnosticProperties.ToImmutable(), startingTextSets));
298+
}
290299
}
291-
else if (!startsWithSets)
300+
else
292301
{
293-
diagnosticProperties.Add(ExpectedTextKey, startingTextSets);
294-
context.ReportDiagnostic(Diagnostic.Create(SA1623Descriptor, diagnosticLocation, diagnosticProperties.ToImmutable(), startingTextSets));
302+
// Setter exists and is visible. Getter does not exist.
303+
if (!startsWithSets)
304+
{
305+
diagnosticProperties.Add(ExpectedTextKey, startingTextSets);
306+
307+
if (startsWithGetsOrSets)
308+
{
309+
diagnosticProperties.Add(TextToRemoveKey, text.Substring(0, startingTextGetsOrSets.Length));
310+
}
311+
else if (startsWithGets)
312+
{
313+
diagnosticProperties.Add(TextToRemoveKey, text.Substring(0, startingTextGets.Length));
314+
}
315+
316+
context.ReportDiagnostic(Diagnostic.Create(SA1623Descriptor, diagnosticLocation, diagnosticProperties.ToImmutable(), startingTextSets));
317+
}
295318
}
296319
}
297320
}

0 commit comments

Comments
 (0)