Skip to content

Commit 51c772e

Browse files
authored
Merge pull request #3859 from bjornhellander/feature/sa1629-xml-entity-3802
Correct SA1629 to add a period if the documentation ends in an xml entity. Previously replaced the semicolon in the xml entity.
2 parents de67e30 + a5c1d42 commit 51c772e

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1629UnitTests.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.DocumentationRules
75
{
86
using System.Threading;
@@ -962,10 +960,32 @@ public interface ITest
962960
await VerifyCSharpDiagnosticAsync(testCode, testSettings, expectedResult, CancellationToken.None).ConfigureAwait(false);
963961
}
964962

963+
[Theory]
964+
[InlineData("<")]
965+
[InlineData("&")]
966+
[InlineData(""")]
967+
[WorkItem(3802, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3802")]
968+
public async Task TestSentenceEndingWithXmlEntityAsync(string xmlEntity)
969+
{
970+
var testCode = $@"
971+
/// <summary>Something {xmlEntity}[|<|]/summary>
972+
public class TestClass
973+
{{
974+
}}";
975+
976+
var fixedTestCode = $@"
977+
/// <summary>Something {xmlEntity}.</summary>
978+
public class TestClass
979+
{{
980+
}}";
981+
982+
await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
983+
}
984+
965985
private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken)
966986
=> VerifyCSharpDiagnosticAsync(source, testSettings: null, expected, cancellationToken);
967987

968-
private static Task VerifyCSharpDiagnosticAsync(string source, string testSettings, DiagnosticResult[] expected, CancellationToken cancellationToken)
988+
private static Task VerifyCSharpDiagnosticAsync(string source, string? testSettings, DiagnosticResult[] expected, CancellationToken cancellationToken)
969989
{
970990
var test = CreateTest(testSettings, expected);
971991
test.TestCode = source;
@@ -985,7 +1005,7 @@ private static Task VerifyCSharpFixAsync(string source, DiagnosticResult[] expec
9851005
return test.RunAsync(cancellationToken);
9861006
}
9871007

988-
private static StyleCopCodeFixVerifier<SA1629DocumentationTextMustEndWithAPeriod, SA1629CodeFixProvider>.CSharpTest CreateTest(string testSettings, DiagnosticResult[] expected)
1008+
private static StyleCopCodeFixVerifier<SA1629DocumentationTextMustEndWithAPeriod, SA1629CodeFixProvider>.CSharpTest CreateTest(string? testSettings, DiagnosticResult[] expected)
9891009
{
9901010
string contentClassInheritDoc = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
9911011
<TestClass>

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1629DocumentationTextMustEndWithAPeriod.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace StyleCop.Analyzers.DocumentationRules
1111
using System.Linq;
1212
using System.Xml.Linq;
1313
using Microsoft.CodeAnalysis;
14+
using Microsoft.CodeAnalysis.CSharp;
1415
using Microsoft.CodeAnalysis.CSharp.Syntax;
1516
using Microsoft.CodeAnalysis.Diagnostics;
1617
using Microsoft.CodeAnalysis.Text;
@@ -132,7 +133,8 @@ private static void HandleSectionOrBlockXmlElement(SyntaxNodeAnalysisContext con
132133
int spanStart = textToken.SpanStart + textWithoutTrailingWhitespace.Length;
133134
ImmutableDictionary<string, string> properties = null;
134135
if (textWithoutTrailingWhitespace.EndsWith(",", StringComparison.Ordinal)
135-
|| textWithoutTrailingWhitespace.EndsWith(";", StringComparison.Ordinal))
136+
|| (textWithoutTrailingWhitespace.EndsWith(";", StringComparison.Ordinal)
137+
&& !textToken.IsKind(SyntaxKind.XmlEntityLiteralToken)))
136138
{
137139
spanStart -= 1;
138140
SetReplaceChar();

0 commit comments

Comments
 (0)