diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1629UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1629UnitTests.cs index f86afd24e..f31c5ffad 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1629UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1629UnitTests.cs @@ -1,8 +1,6 @@ // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -#nullable disable - namespace StyleCop.Analyzers.Test.DocumentationRules { using System.Threading; @@ -962,10 +960,32 @@ public interface ITest await VerifyCSharpDiagnosticAsync(testCode, testSettings, expectedResult, CancellationToken.None).ConfigureAwait(false); } + [Theory] + [InlineData("<")] + [InlineData("&")] + [InlineData(""")] + [WorkItem(3802, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3802")] + public async Task TestSentenceEndingWithXmlEntityAsync(string xmlEntity) + { + var testCode = $@" +/// Something {xmlEntity}[|<|]/summary> +public class TestClass +{{ +}}"; + + var fixedTestCode = $@" +/// Something {xmlEntity}. +public class TestClass +{{ +}}"; + + await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedTestCode, CancellationToken.None).ConfigureAwait(false); + } + private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken) => VerifyCSharpDiagnosticAsync(source, testSettings: null, expected, cancellationToken); - private static Task VerifyCSharpDiagnosticAsync(string source, string testSettings, DiagnosticResult[] expected, CancellationToken cancellationToken) + private static Task VerifyCSharpDiagnosticAsync(string source, string? testSettings, DiagnosticResult[] expected, CancellationToken cancellationToken) { var test = CreateTest(testSettings, expected); test.TestCode = source; @@ -985,7 +1005,7 @@ private static Task VerifyCSharpFixAsync(string source, DiagnosticResult[] expec return test.RunAsync(cancellationToken); } - private static StyleCopCodeFixVerifier.CSharpTest CreateTest(string testSettings, DiagnosticResult[] expected) + private static StyleCopCodeFixVerifier.CSharpTest CreateTest(string? testSettings, DiagnosticResult[] expected) { string contentClassInheritDoc = @" diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1629DocumentationTextMustEndWithAPeriod.cs b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1629DocumentationTextMustEndWithAPeriod.cs index 6f16360cf..2a0f774cd 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1629DocumentationTextMustEndWithAPeriod.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1629DocumentationTextMustEndWithAPeriod.cs @@ -11,6 +11,7 @@ namespace StyleCop.Analyzers.DocumentationRules using System.Linq; using System.Xml.Linq; using Microsoft.CodeAnalysis; + using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Text; @@ -132,7 +133,8 @@ private static void HandleSectionOrBlockXmlElement(SyntaxNodeAnalysisContext con int spanStart = textToken.SpanStart + textWithoutTrailingWhitespace.Length; ImmutableDictionary properties = null; if (textWithoutTrailingWhitespace.EndsWith(",", StringComparison.Ordinal) - || textWithoutTrailingWhitespace.EndsWith(";", StringComparison.Ordinal)) + || (textWithoutTrailingWhitespace.EndsWith(";", StringComparison.Ordinal) + && !textToken.IsKind(SyntaxKind.XmlEntityLiteralToken))) { spanStart -= 1; SetReplaceChar();