Skip to content

Commit f395c71

Browse files
committed
Don't emit SA1414 for interface implementations
1 parent ccaac20 commit f395c71

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,23 @@ public static explicit operator TestClass({typeExpression} p1)
117117

118118
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
119119
}
120+
121+
[Fact]
122+
public Task ValidateTuplesFromInheritedTypeAsync()
123+
{
124+
const string testCode = @"
125+
using System.Collections.Generic;
126+
127+
namespace Test {
128+
class StringTupleComparer : IEqualityComparer<(string, string)>
129+
{
130+
public bool Equals((string, string) x, (string, string) y) => throw null;
131+
132+
public int GetHashCode((string, string) obj) => throw null;
133+
}
134+
}
135+
";
136+
return VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, default);
137+
}
120138
}
121139
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace StyleCop.Analyzers.MaintainabilityRules
77
{
88
using System;
99
using System.Collections.Immutable;
10+
using System.Linq;
1011
using Microsoft.CodeAnalysis;
1112
using Microsoft.CodeAnalysis.CSharp;
1213
using Microsoft.CodeAnalysis.CSharp.Syntax;
@@ -62,6 +63,20 @@ private static void HandleMethodDeclaration(SyntaxNodeAnalysisContext context)
6263
}
6364

6465
var methodDeclaration = (MethodDeclarationSyntax)context.Node;
66+
var methodSymbol = context.SemanticModel.GetDeclaredSymbol(methodDeclaration);
67+
var containingType = methodSymbol.ContainingType;
68+
if (containingType == null)
69+
{
70+
return;
71+
}
72+
73+
foreach (var member in containingType.AllInterfaces.SelectMany(i => i.GetMembers(methodSymbol.Name).OfType<IMethodSymbol>()))
74+
{
75+
if (methodSymbol.Equals(containingType.FindImplementationForInterfaceMember(member)))
76+
{
77+
return;
78+
}
79+
}
6580

6681
CheckType(context, methodDeclaration.ReturnType);
6782
CheckParameterList(context, methodDeclaration.ParameterList);

0 commit comments

Comments
 (0)