Skip to content

Commit 800a632

Browse files
authored
Merge pull request #2769 from sharwell/ending-parens
Allow parenthesized sentences in documentation
2 parents 35283f2 + b2c6d0f commit 800a632

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,52 @@ public interface ITest
451451
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
452452
}
453453

454+
[Theory]
455+
[WorkItem(2744, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2744")]
456+
[InlineData("Summary. (For example.)")]
457+
[InlineData("Summary (for example).")]
458+
public async Task TestSentenceEndingWithParenthesesAsync(string allowedSummary)
459+
{
460+
var testCode = $@"
461+
/// <summary>
462+
/// {allowedSummary}
463+
/// </summary>
464+
public interface ITest
465+
{{
466+
}}
467+
";
468+
469+
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
470+
}
471+
472+
[Fact]
473+
[WorkItem(2744, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2744")]
474+
public async Task TestSentenceEndingWithParenthesesWithoutPeriodAsync()
475+
{
476+
var testCode = @"
477+
/// <summary>
478+
/// Summary (for example)
479+
/// </summary>
480+
public interface ITest
481+
{
482+
}
483+
";
484+
var fixedTestCode = $@"
485+
/// <summary>
486+
/// Summary (for example).
487+
/// </summary>
488+
public interface ITest
489+
{{
490+
}}
491+
";
492+
493+
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(3, 26);
494+
495+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
496+
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
497+
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
498+
}
499+
454500
[Fact]
455501
public async Task TestMultipleParagraphBlocksAsync()
456502
{

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext co
9191
var textWithoutTrailingWhitespace = node.Value.TrimEnd(' ', '\r', '\n');
9292
if (!string.IsNullOrEmpty(textWithoutTrailingWhitespace))
9393
{
94-
if (!textWithoutTrailingWhitespace.EndsWith(".", StringComparison.Ordinal))
94+
if (!textWithoutTrailingWhitespace.EndsWith(".", StringComparison.Ordinal)
95+
&& !textWithoutTrailingWhitespace.EndsWith(".)", StringComparison.Ordinal))
9596
{
9697
context.ReportDiagnostic(Diagnostic.Create(Descriptor, diagnosticLocations[0], NoCodeFixProperties));
9798

@@ -123,6 +124,7 @@ private static void HandleSectionOrBlockXmlElement(SyntaxNodeAnalysisContext con
123124
if (!string.IsNullOrEmpty(textWithoutTrailingWhitespace))
124125
{
125126
if (!textWithoutTrailingWhitespace.EndsWith(".", StringComparison.Ordinal)
127+
&& !textWithoutTrailingWhitespace.EndsWith(".)", StringComparison.Ordinal)
126128
&& (startingWithFinalParagraph || !textWithoutTrailingWhitespace.EndsWith(":", StringComparison.Ordinal))
127129
&& !textWithoutTrailingWhitespace.EndsWith("-or-", StringComparison.Ordinal))
128130
{

0 commit comments

Comments
 (0)