Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct SA1629 to add a period if the documentation ends in an xml entity. Previously replaced the semicolon in the xml entity. #3859

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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