Skip to content

Commit 526c7d3

Browse files
Updated PropertySummaryDocumentationAnalyzer to be easier to understand, by stating in each case what the expected prefix is.
1 parent 9557f27 commit 526c7d3

1 file changed

Lines changed: 37 additions & 31 deletions

File tree

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

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ private static void AnalyzeSummaryElement(SyntaxNodeAnalysisContext context, Xml
130130
var textElement = summaryElement.Content.FirstOrDefault() as XmlTextSyntax;
131131
var text = textElement == null ? string.Empty : XmlCommentHelper.GetText(textElement, true).TrimStart();
132132

133-
bool startsWithGetsOrSets = text.StartsWith(startingTextGetsOrSets, StringComparison.OrdinalIgnoreCase);
134-
bool startsWithGets = text.StartsWith(startingTextGets, StringComparison.OrdinalIgnoreCase);
135-
bool startsWithSets = text.StartsWith(startingTextSets, StringComparison.OrdinalIgnoreCase);
133+
bool prefixIsGetsOrSets = text.StartsWith(startingTextGetsOrSets, StringComparison.OrdinalIgnoreCase);
134+
bool prefixIsGets = text.StartsWith(startingTextGets, StringComparison.OrdinalIgnoreCase) && !prefixIsGetsOrSets;
135+
bool prefixIsSets = text.StartsWith(startingTextSets, StringComparison.OrdinalIgnoreCase);
136136

137137
bool getterVisible, setterVisible;
138138
if (getter != null && setter != null)
@@ -229,15 +229,15 @@ private static void AnalyzeSummaryElement(SyntaxNodeAnalysisContext context, Xml
229229
if (setterVisible)
230230
{
231231
// Both getter and setter are visible.
232-
if (!startsWithGetsOrSets)
232+
if (!prefixIsGetsOrSets)
233233
{
234234
diagnosticProperties.Add(ExpectedTextKey, startingTextGetsOrSets);
235235

236-
if (startsWithGets)
236+
if (prefixIsGets)
237237
{
238238
diagnosticProperties.Add(TextToRemoveKey, text.Substring(0, startingTextGets.Length));
239239
}
240-
else if (startsWithSets)
240+
else if (prefixIsSets)
241241
{
242242
diagnosticProperties.Add(TextToRemoveKey, text.Substring(0, startingTextSets.Length));
243243
}
@@ -248,30 +248,33 @@ private static void AnalyzeSummaryElement(SyntaxNodeAnalysisContext context, Xml
248248
else if (setter != null)
249249
{
250250
// Both getter and setter exist, but only getter is visible.
251-
if (startsWithGetsOrSets)
251+
if (!prefixIsGets)
252252
{
253-
diagnosticProperties.Add(ExpectedTextKey, startingTextGets);
254-
diagnosticProperties.Add(TextToRemoveKey, startingTextGetsOrSets);
255-
context.ReportDiagnostic(Diagnostic.Create(SA1624Descriptor, diagnosticLocation, diagnosticProperties.ToImmutable(), "get", startingTextGets));
256-
}
257-
else if (!startsWithGets)
258-
{
259-
diagnosticProperties.Add(ExpectedTextKey, startingTextGets);
260-
context.ReportDiagnostic(Diagnostic.Create(SA1623Descriptor, diagnosticLocation, diagnosticProperties.ToImmutable(), startingTextGets));
253+
if (prefixIsGetsOrSets)
254+
{
255+
diagnosticProperties.Add(ExpectedTextKey, startingTextGets);
256+
diagnosticProperties.Add(TextToRemoveKey, startingTextGetsOrSets);
257+
context.ReportDiagnostic(Diagnostic.Create(SA1624Descriptor, diagnosticLocation, diagnosticProperties.ToImmutable(), "get", startingTextGets));
258+
}
259+
else
260+
{
261+
diagnosticProperties.Add(ExpectedTextKey, startingTextGets);
262+
context.ReportDiagnostic(Diagnostic.Create(SA1623Descriptor, diagnosticLocation, diagnosticProperties.ToImmutable(), startingTextGets));
263+
}
261264
}
262265
}
263266
else
264267
{
265268
// Getter exists and is visible. Setter does not exist.
266-
if (!startsWithGets || startsWithGetsOrSets)
269+
if (!prefixIsGets)
267270
{
268271
diagnosticProperties.Add(ExpectedTextKey, startingTextGets);
269272

270-
if (startsWithSets)
273+
if (prefixIsSets)
271274
{
272275
diagnosticProperties.Add(TextToRemoveKey, text.Substring(0, startingTextSets.Length));
273276
}
274-
else if (startsWithGetsOrSets)
277+
else if (prefixIsGetsOrSets)
275278
{
276279
diagnosticProperties.Add(TextToRemoveKey, text.Substring(0, startingTextGetsOrSets.Length));
277280
}
@@ -284,31 +287,34 @@ private static void AnalyzeSummaryElement(SyntaxNodeAnalysisContext context, Xml
284287
{
285288
if (getter != null)
286289
{
287-
// Both getter and setter exist, but only setter is visible
288-
if (startsWithGetsOrSets)
290+
// Both getter and setter exist, but only setter is visible.
291+
if (!prefixIsSets)
289292
{
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));
293+
if (prefixIsGetsOrSets)
294+
{
295+
diagnosticProperties.Add(ExpectedTextKey, startingTextSets);
296+
diagnosticProperties.Add(TextToRemoveKey, startingTextGetsOrSets);
297+
context.ReportDiagnostic(Diagnostic.Create(SA1624Descriptor, diagnosticLocation, diagnosticProperties.ToImmutable(), "set", startingTextSets));
298+
}
299+
else
300+
{
301+
diagnosticProperties.Add(ExpectedTextKey, startingTextSets);
302+
context.ReportDiagnostic(Diagnostic.Create(SA1623Descriptor, diagnosticLocation, diagnosticProperties.ToImmutable(), startingTextSets));
303+
}
298304
}
299305
}
300306
else
301307
{
302308
// Setter exists and is visible. Getter does not exist.
303-
if (!startsWithSets)
309+
if (!prefixIsSets)
304310
{
305311
diagnosticProperties.Add(ExpectedTextKey, startingTextSets);
306312

307-
if (startsWithGetsOrSets)
313+
if (prefixIsGetsOrSets)
308314
{
309315
diagnosticProperties.Add(TextToRemoveKey, text.Substring(0, startingTextGetsOrSets.Length));
310316
}
311-
else if (startsWithGets)
317+
else if (prefixIsGets)
312318
{
313319
diagnosticProperties.Add(TextToRemoveKey, text.Substring(0, startingTextGets.Length));
314320
}

0 commit comments

Comments
 (0)