Skip to content

Commit 2d7aa8e

Browse files
committed
Allow '-or-' as a standalone paragraph
Fixes #2712
1 parent 258d447 commit 2d7aa8e

2 files changed

Lines changed: 84 additions & 1 deletion

File tree

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

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,88 @@ public interface ITest
644644
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
645645
}
646646

647+
[Fact]
648+
[WorkItem(2712, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2712")]
649+
public async Task TestExceptionElementsWithStandardFormAsync()
650+
{
651+
var testCode = @"
652+
using System;
653+
public interface ITest
654+
{
655+
/// <exception cref=""ArgumentNullException"">
656+
/// <para>If <paramref name=""name""/> is <see langword=""null""/></para>
657+
/// <para>-or-</para>
658+
/// <para>If <paramref name=""value""/> is <see langword=""null""/></para>
659+
/// </exception>
660+
void Method(string name, string value);
661+
}
662+
";
663+
664+
var fixedTestCode = @"
665+
using System;
666+
public interface ITest
667+
{
668+
/// <exception cref=""ArgumentNullException"">
669+
/// <para>If <paramref name=""name""/> is <see langword=""null""/>.</para>
670+
/// <para>-or-</para>
671+
/// <para>If <paramref name=""value""/> is <see langword=""null""/>.</para>
672+
/// </exception>
673+
void Method(string name, string value);
674+
}
675+
";
676+
677+
DiagnosticResult[] expected =
678+
{
679+
this.CSharpDiagnostic().WithLocation(6, 67),
680+
this.CSharpDiagnostic().WithLocation(8, 68),
681+
};
682+
683+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
684+
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
685+
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
686+
}
687+
688+
[Fact]
689+
[WorkItem(2712, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2712")]
690+
public async Task TestExceptionElementsWithAlternateFormAsync()
691+
{
692+
var testCode = @"
693+
using System;
694+
public interface ITest
695+
{
696+
/// <exception cref=""ArgumentNullException"">
697+
/// <para>If <paramref name=""name""/> is <see langword=""null""/></para>
698+
/// -or-
699+
/// <para>If <paramref name=""value""/> is <see langword=""null""/></para>
700+
/// </exception>
701+
void Method(string name, string value);
702+
}
703+
";
704+
705+
var fixedTestCode = @"
706+
using System;
707+
public interface ITest
708+
{
709+
/// <exception cref=""ArgumentNullException"">
710+
/// <para>If <paramref name=""name""/> is <see langword=""null""/>.</para>
711+
/// -or-
712+
/// <para>If <paramref name=""value""/> is <see langword=""null""/>.</para>
713+
/// </exception>
714+
void Method(string name, string value);
715+
}
716+
";
717+
718+
DiagnosticResult[] expected =
719+
{
720+
this.CSharpDiagnostic().WithLocation(6, 67),
721+
this.CSharpDiagnostic().WithLocation(8, 68),
722+
};
723+
724+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
725+
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
726+
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
727+
}
728+
647729
protected override Project ApplyCompilationOptions(Project project)
648730
{
649731
var resolver = new TestXmlReferenceResolver();

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ private static void HandleSectionOrBlockXmlElement(SyntaxNodeAnalysisContext con
120120

121121
if (!string.IsNullOrEmpty(textWithoutTrailingWhitespace))
122122
{
123-
if (!textWithoutTrailingWhitespace.EndsWith(".", StringComparison.Ordinal))
123+
if (!textWithoutTrailingWhitespace.EndsWith(".", StringComparison.Ordinal)
124+
&& !textWithoutTrailingWhitespace.EndsWith("-or-", StringComparison.Ordinal))
124125
{
125126
var location = Location.Create(xmlElement.SyntaxTree, new TextSpan(textToken.SpanStart + textWithoutTrailingWhitespace.Length, 1));
126127
context.ReportDiagnostic(Diagnostic.Create(Descriptor, location));

0 commit comments

Comments
 (0)