Skip to content

Commit 873dd2b

Browse files
committed
Updated SA1609/SA1610 to not offer codefixes for included docs
1 parent eed3e6b commit 873dd2b

6 files changed

Lines changed: 28 additions & 8 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/SA1609SA1610CodeFixProvider.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
4444
{
4545
foreach (var diagnostic in context.Diagnostics)
4646
{
47-
context.RegisterCodeFix(
48-
CodeAction.Create(
49-
DocumentationResources.SA1609SA1610CodeFix,
50-
cancellationToken => this.GetTransformedDocumentAsync(context.Document, diagnostic, cancellationToken),
51-
nameof(SA1609SA1610CodeFixProvider)),
52-
diagnostic);
47+
if (!diagnostic.Properties.ContainsKey(PropertyDocumentationBase.NoCodeFixKey))
48+
{
49+
context.RegisterCodeFix(
50+
CodeAction.Create(
51+
DocumentationResources.SA1609SA1610CodeFix,
52+
cancellationToken => this.GetTransformedDocumentAsync(context.Document, diagnostic, cancellationToken),
53+
nameof(SA1609SA1610CodeFixProvider)),
54+
diagnostic);
55+
}
5356
}
5457

5558
return SpecializedTasks.CompletedTask;

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1609UnitTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ public int Property
321321
}";
322322
var expected = this.CSharpDiagnostic().WithLocation(5, 16);
323323
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
324+
var offeredFixes = await this.GetOfferedCSharpFixesAsync(testCode).ConfigureAwait(false);
325+
Assert.Empty(offeredFixes);
324326
}
325327

326328
/// <summary>

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1610UnitTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ public int Property
339339
}";
340340
var expected = this.CSharpDiagnostic().WithLocation(5, 16);
341341
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
342+
var offeredFixes = await this.GetOfferedCSharpFixesAsync(testCode).ConfigureAwait(false);
343+
Assert.Empty(offeredFixes);
342344
}
343345

344346
/// <summary>

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/PropertyDocumentationBase.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ namespace StyleCop.Analyzers.DocumentationRules
1717
/// </summary>
1818
internal abstract class PropertyDocumentationBase : DiagnosticAnalyzer
1919
{
20+
/// <summary>
21+
/// The key used for signalling that no codefix should be offered.
22+
/// </summary>
23+
internal const string NoCodeFixKey = "NoCodeFix";
24+
2025
private readonly Action<SyntaxNodeAnalysisContext> propertyDeclarationAction;
2126

2227
protected PropertyDocumentationBase()

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1609PropertyDocumentationMustHaveValue.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,17 @@ internal class SA1609PropertyDocumentationMustHaveValue : PropertyDocumentationB
5151
/// <inheritdoc/>
5252
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, XmlNodeSyntax syntax, XElement completeDocumentation, Location diagnosticLocation)
5353
{
54+
var properties = ImmutableDictionary.Create<string, string>();
55+
5456
if (completeDocumentation != null)
5557
{
5658
var hasValueTag = completeDocumentation.Nodes().OfType<XElement>().Any(element => element.Name == XmlCommentHelper.ValueXmlTag);
5759
if (hasValueTag)
5860
{
5961
return;
6062
}
63+
64+
properties = properties.Add(NoCodeFixKey, string.Empty);
6165
}
6266
else
6367
{
@@ -67,7 +71,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, XmlN
6771
}
6872
}
6973

70-
context.ReportDiagnostic(Diagnostic.Create(Descriptor, diagnosticLocation));
74+
context.ReportDiagnostic(Diagnostic.Create(Descriptor, diagnosticLocation, properties));
7175
}
7276
}
7377
}

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1610PropertyDocumentationMustHaveValueText.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ internal class SA1610PropertyDocumentationMustHaveValueText : PropertyDocumentat
5151
/// <inheritdoc/>
5252
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, XmlNodeSyntax syntax, XElement completeDocumentation, Location diagnosticLocation)
5353
{
54+
var properties = ImmutableDictionary.Create<string, string>();
55+
5456
if (completeDocumentation != null)
5557
{
5658
var valueTag = completeDocumentation.Nodes().OfType<XElement>().FirstOrDefault(element => element.Name == XmlCommentHelper.ValueXmlTag);
@@ -64,6 +66,8 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, XmlN
6466
{
6567
return;
6668
}
69+
70+
properties = properties.Add(NoCodeFixKey, string.Empty);
6771
}
6872
else
6973
{
@@ -79,7 +83,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, XmlN
7983
}
8084
}
8185

82-
context.ReportDiagnostic(Diagnostic.Create(Descriptor, diagnosticLocation));
86+
context.ReportDiagnostic(Diagnostic.Create(Descriptor, diagnosticLocation, properties));
8387
}
8488
}
8589
}

0 commit comments

Comments
 (0)