Skip to content

Commit bd00b4d

Browse files
committed
Merge pull request #1 from vweijsters/pr-1947
Implemented proposed changes from code review
2 parents a720174 + 4e7d650 commit bd00b4d

3 files changed

Lines changed: 19 additions & 11 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/PropertySummaryDocumentationCodeFixProvider.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,15 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
4040
{
4141
foreach (Diagnostic diagnostic in context.Diagnostics)
4242
{
43-
context.RegisterCodeFix(
44-
CodeAction.Create(
45-
DocumentationResources.PropertySummaryStartTextCodeFix,
46-
cancellationToken => GetTransformedDocumentAsync(context.Document, diagnostic, cancellationToken),
47-
nameof(PropertySummaryDocumentationCodeFixProvider)),
48-
diagnostic);
43+
if (!diagnostic.Properties.ContainsKey(PropertySummaryDocumentationAnalyzer.NoCodeFixKey))
44+
{
45+
context.RegisterCodeFix(
46+
CodeAction.Create(
47+
DocumentationResources.PropertySummaryStartTextCodeFix,
48+
cancellationToken => GetTransformedDocumentAsync(context.Document, diagnostic, cancellationToken),
49+
nameof(PropertySummaryDocumentationCodeFixProvider)),
50+
diagnostic);
51+
}
4952
}
5053

5154
return SpecializedTasks.CompletedTask;

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,10 @@ public int Property
170170
}";
171171

172172
var expected = this.CSharpDiagnostic(PropertySummaryDocumentationAnalyzer.SA1623Descriptor).WithLocation(4, 16).WithArguments("Gets");
173-
174173
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
175174

176-
// Intentionally do not provide a code fix: https://github.com/DotNetAnalyzers/StyleCopAnalyzers/pull/1957#discussion_r47703520
177-
//// await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
178-
179-
await this.VerifyCSharpFixAsync(testCode, testCode).ConfigureAwait(false);
175+
var offeredFixes = await this.GetOfferedCSharpFixesAsync(testCode).ConfigureAwait(false);
176+
Assert.Empty(offeredFixes);
180177
}
181178

182179
/// <inheritdoc/>

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ internal class PropertySummaryDocumentationAnalyzer : PropertyDocumentationBase
1919
{
2020
public const string ExpectedTextKey = "ExpectedText";
2121
public const string TextToRemoveKey = "TextToRemove";
22+
public const string NoCodeFixKey = "NoCodeFix";
2223

2324
private const string SA1623DiagnosticId = "SA1623";
2425
private const string SA1624DiagnosticId = "SA1624";
@@ -108,6 +109,13 @@ private static void AnalyzeSummaryElement(SyntaxNodeAnalysisContext context, Xml
108109
return;
109110
}
110111

112+
// Add a no code fix tag when the summary element is empty.
113+
// This will only impact SA1623, because SA1624 cannot trigger with an empty summary.
114+
if (summaryElement.Content.Count == 0)
115+
{
116+
diagnosticProperties.Add(NoCodeFixKey, string.Empty);
117+
}
118+
111119
var textElement = summaryElement.Content.FirstOrDefault() as XmlTextSyntax;
112120
var text = textElement == null ? string.Empty : XmlCommentHelper.GetText(textElement, true).TrimStart();
113121

0 commit comments

Comments
 (0)