Skip to content

Commit 22e8d6b

Browse files
committed
Added tests for explicit interface implementations and base classes.
1 parent f395c71 commit 22e8d6b

2 files changed

Lines changed: 54 additions & 4 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/MaintainabilityRules/SA1414CSharp7UnitTests.cs

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
namespace StyleCop.Analyzers.Test.CSharp7.MaintainabilityRules
77
{
8+
using System;
89
using System.Threading;
910
using System.Threading.Tasks;
1011
using Microsoft.CodeAnalysis.Testing;
@@ -119,7 +120,7 @@ public static explicit operator TestClass({typeExpression} p1)
119120
}
120121

121122
[Fact]
122-
public Task ValidateTuplesFromInheritedTypeAsync()
123+
public Task ValidateTuplesFromInterfaceAsync()
123124
{
124125
const string testCode = @"
125126
using System.Collections.Generic;
@@ -131,9 +132,53 @@ class StringTupleComparer : IEqualityComparer<(string, string)>
131132
132133
public int GetHashCode((string, string) obj) => throw null;
133134
}
134-
}
135-
";
135+
}";
136136
return VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, default);
137137
}
138+
139+
[Fact]
140+
public Task ValidateTuplesFromExplicitInterfaceImplementationAsync()
141+
{
142+
const string testCode = @"
143+
using System.Collections.Generic;
144+
145+
namespace Test {
146+
class StringTupleComparer : IEqualityComparer<(string, string)>
147+
{
148+
bool IEqualityComparer<(string, string)>.Equals((string, string) x, (string, string) y) => throw null;
149+
150+
int IEqualityComparer<(string, string)>.GetHashCode((string, string) obj) => throw null;
151+
}
152+
}";
153+
return VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, default);
154+
}
155+
156+
[Fact]
157+
public Task ValidateTuplesFromBaseClassAsync()
158+
{
159+
const string testCode = @"
160+
namespace Test {
161+
class A : B
162+
{
163+
public override void Run((string, string) x)
164+
{
165+
}
166+
167+
public override void Run((int, int) y)
168+
{
169+
}
170+
}
171+
172+
abstract class B
173+
{
174+
public abstract void Run(([|string|], [|string|]) x);
175+
176+
public virtual void Run(([|int|], [|int|]) y)
177+
{
178+
}
179+
}
180+
}";
181+
return VerifyCSharpDiagnosticAsync(testCode, Array.Empty<DiagnosticResult>(), default);
182+
}
138183
}
139184
}

StyleCop.Analyzers/StyleCop.Analyzers/MaintainabilityRules/SA1414TupleTypesInSignaturesShouldHaveElementNames.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,14 @@ private static void HandleMethodDeclaration(SyntaxNodeAnalysisContext context)
6363
}
6464

6565
var methodDeclaration = (MethodDeclarationSyntax)context.Node;
66+
if (methodDeclaration.Modifiers.Any(SyntaxKind.OverrideKeyword))
67+
{
68+
return;
69+
}
70+
6671
var methodSymbol = context.SemanticModel.GetDeclaredSymbol(methodDeclaration);
6772
var containingType = methodSymbol.ContainingType;
68-
if (containingType == null)
73+
if (containingType is null || methodSymbol.ExplicitInterfaceImplementations.Length > 0)
6974
{
7075
return;
7176
}

0 commit comments

Comments
 (0)