Skip to content

Commit

Permalink
Merge pull request #3859 from bjornhellander/feature/sa1629-xml-entit…
Browse files Browse the repository at this point in the history
…y-3802

Correct SA1629 to add a period if the documentation ends in an xml entity. Previously replaced the semicolon in the xml entity.
  • Loading branch information
sharwell authored Jun 10, 2024
2 parents de67e30 + a5c1d42 commit 51c772e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 = $@"
/// <summary>Something {xmlEntity}[|<|]/summary>
public class TestClass
{{
}}";

var fixedTestCode = $@"
/// <summary>Something {xmlEntity}.</summary>
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;
Expand All @@ -985,7 +1005,7 @@ private static Task VerifyCSharpFixAsync(string source, DiagnosticResult[] expec
return test.RunAsync(cancellationToken);
}

private static StyleCopCodeFixVerifier<SA1629DocumentationTextMustEndWithAPeriod, SA1629CodeFixProvider>.CSharpTest CreateTest(string testSettings, DiagnosticResult[] expected)
private static StyleCopCodeFixVerifier<SA1629DocumentationTextMustEndWithAPeriod, SA1629CodeFixProvider>.CSharpTest CreateTest(string? testSettings, DiagnosticResult[] expected)
{
string contentClassInheritDoc = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<TestClass>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -132,7 +133,8 @@ private static void HandleSectionOrBlockXmlElement(SyntaxNodeAnalysisContext con
int spanStart = textToken.SpanStart + textWithoutTrailingWhitespace.Length;
ImmutableDictionary<string, string> properties = null;
if (textWithoutTrailingWhitespace.EndsWith(",", StringComparison.Ordinal)
|| textWithoutTrailingWhitespace.EndsWith(";", StringComparison.Ordinal))
|| (textWithoutTrailingWhitespace.EndsWith(";", StringComparison.Ordinal)
&& !textToken.IsKind(SyntaxKind.XmlEntityLiteralToken)))
{
spanStart -= 1;
SetReplaceChar();
Expand Down

0 comments on commit 51c772e

Please sign in to comment.