Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace StyleCop.Analyzers.Test.CSharp7.MaintainabilityRules
{
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Testing;
Expand Down Expand Up @@ -117,5 +118,61 @@ public static explicit operator TestClass({typeExpression} p1)

await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
public async Task ValidateTuplesFromInterfaceAsync()
{
const string testCode = @"
using System.Collections.Generic;

namespace Test {
class StringTupleComparer : IEqualityComparer<(string, string)>
{
public bool Equals((string, string) x, (string, string) y) => throw null;

public int GetHashCode((string, string) obj) => throw null;
}
}";
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
public async Task ValidateTuplesFromExplicitInterfaceImplementationAsync()
{
const string testCode = @"
using System.Collections.Generic;

namespace Test {
class StringTupleComparer : IEqualityComparer<(string, string)>
{
bool IEqualityComparer<(string, string)>.Equals((string, string) x, (string, string) y) => throw null;

int IEqualityComparer<(string, string)>.GetHashCode((string, string) obj) => throw null;
}
}";
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
public async Task ValidateTuplesFromBaseClassAsync()
{
const string testCode = @"
namespace Test {
class A : B
{
public override (string, string) Run((string, string) x) => throw null;

public override (int, int) Run((int, int) y) => throw null;
}

abstract class B
{
public abstract ([|string|], [|string|]) Run(([|string|], [|string|]) x);

public virtual ([|int|], [|int|]) Run(([|int|], [|int|]) y) => throw null;
}
}";
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace StyleCop.Analyzers.MaintainabilityRules
{
using System;
using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
Expand Down Expand Up @@ -62,6 +63,10 @@ private static void HandleMethodDeclaration(SyntaxNodeAnalysisContext context)
}

var methodDeclaration = (MethodDeclarationSyntax)context.Node;
if (methodDeclaration.Modifiers.Any(SyntaxKind.OverrideKeyword))
{
return;
}

CheckType(context, methodDeclaration.ReturnType);
CheckParameterList(context, methodDeclaration.ParameterList);
Expand Down Expand Up @@ -161,7 +166,7 @@ private static void CheckTupleType(SyntaxNodeAnalysisContext context, TupleTypeS
{
CheckType(context, tupleElementSyntax.Type);

if (tupleElementSyntax.Identifier.IsKind(SyntaxKind.None))
if (tupleElementSyntax.Identifier.IsKind(SyntaxKind.None) && !NamedTypeHelpers.IsImplementingAnInterfaceMember(context.SemanticModel.GetDeclaredSymbol(context.Node)))
{
var location = tupleElementSyntax.SyntaxNode.GetLocation();
context.ReportDiagnostic(Diagnostic.Create(Descriptor, location));
Expand Down