Skip to content

Commit ef88138

Browse files
committed
Update SA1612 for partial methods
1 parent 63772da commit ef88138

File tree

2 files changed

+48
-23
lines changed

2 files changed

+48
-23
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/DocumentationRules/SA1612CSharp9UnitTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,36 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp9.DocumentationRules
55
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
68
using StyleCop.Analyzers.Test.CSharp8.DocumentationRules;
9+
using Xunit;
10+
using static StyleCop.Analyzers.Test.Verifiers.CustomDiagnosticVerifier<StyleCop.Analyzers.DocumentationRules.SA1612ElementParameterDocumentationMustMatchElementParameters>;
711

812
public partial class SA1612CSharp9UnitTests : SA1612CSharp8UnitTests
913
{
14+
[Fact]
15+
[WorkItem(3971, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3971")]
16+
public async Task TestPartialMethodDeclarationWithMismatchedParameterDocumentationAsync()
17+
{
18+
var testCode = @"
19+
/// <summary>
20+
/// Tests a partial method.
21+
/// </summary>
22+
public partial class TestClass
23+
{
24+
/// <summary>Declaration.</summary>
25+
/// <param name=""{|#0:value|}"">Value.</param>
26+
public partial void TestMethod(int other);
27+
28+
public partial void TestMethod(int other)
29+
{
30+
}
31+
}";
32+
33+
var expected = Diagnostic().WithLocation(0).WithArguments("value");
34+
35+
await VerifyCSharpDiagnosticAsync(testCode, new[] { expected }, CancellationToken.None).ConfigureAwait(false);
36+
}
1037
}
1138
}

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1612UnitTests.cs

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -562,35 +562,15 @@ public class ClassName
562562
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
563563
}
564564

565-
private static DiagnosticResult[] GetExpectedDiagnostics(DiagnosticResult normallyExpected, string declaration)
566-
{
567-
return GetExpectedDiagnostics(new[] { normallyExpected }, declaration);
568-
}
569-
570565
// Syntax node actions for type declarations with a primary constructor were called twice
571566
// before support for c# 11 was added.
572-
private static DiagnosticResult[] GetExpectedDiagnostics(DiagnosticResult[] normallyExpected, string declaration)
573-
{
574-
var isPrimaryConstructor = declaration.Contains("record") || declaration.Contains("class") || declaration.Contains("struct");
575-
576-
if (isPrimaryConstructor && !LightupHelpers.SupportsCSharp11)
577-
{
578-
// Diagnostic issued twice because of https://github.com/dotnet/roslyn/issues/53136 and https://github.com/dotnet/roslyn/issues/70488
579-
return normallyExpected.Concat(normallyExpected).ToArray();
580-
}
581-
else
582-
{
583-
return normallyExpected;
584-
}
585-
}
586-
587-
private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken)
567+
protected static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken)
588568
=> VerifyCSharpDiagnosticAsync(source, testSettings: null, expected, ignoreCompilerDiagnostics: false, cancellationToken);
589569

590-
private static Task VerifyCSharpDiagnosticAsync(string source, string testSettings, DiagnosticResult[] expected, CancellationToken cancellationToken)
570+
protected static Task VerifyCSharpDiagnosticAsync(string source, string testSettings, DiagnosticResult[] expected, CancellationToken cancellationToken)
591571
=> VerifyCSharpDiagnosticAsync(source, testSettings, expected, ignoreCompilerDiagnostics: false, cancellationToken);
592572

593-
private static Task VerifyCSharpDiagnosticAsync(string source, string testSettings, DiagnosticResult[] expected, bool ignoreCompilerDiagnostics, CancellationToken cancellationToken)
573+
protected static Task VerifyCSharpDiagnosticAsync(string source, string testSettings, DiagnosticResult[] expected, bool ignoreCompilerDiagnostics, CancellationToken cancellationToken)
594574
{
595575
string contentWithoutParamDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
596576
<ClassName>
@@ -696,5 +676,23 @@ private static Task VerifyCSharpDiagnosticAsync(string source, string testSettin
696676
test.ExpectedDiagnostics.AddRange(expected);
697677
return test.RunAsync(cancellationToken);
698678
}
679+
680+
private static DiagnosticResult[] GetExpectedDiagnostics(DiagnosticResult normallyExpected, string declaration)
681+
{
682+
return GetExpectedDiagnostics(new[] { normallyExpected }, declaration);
683+
}
684+
685+
private static DiagnosticResult[] GetExpectedDiagnostics(DiagnosticResult[] normallyExpected, string declaration)
686+
{
687+
var isPrimaryConstructor = declaration.Contains("record") || declaration.Contains("class") || declaration.Contains("struct");
688+
689+
if (isPrimaryConstructor && !LightupHelpers.SupportsCSharp11)
690+
{
691+
// Diagnostic issued twice because of https://github.com/dotnet/roslyn/issues/53136 and https://github.com/dotnet/roslyn/issues/70488
692+
return normallyExpected.Concat(normallyExpected).ToArray();
693+
}
694+
695+
return normallyExpected;
696+
}
699697
}
700698
}

0 commit comments

Comments
 (0)