Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for interface implementations, CA1054 #6628

Merged
merged 3 commits into from
May 25, 2023
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 @@ -104,6 +104,12 @@ public void Analyze(SymbolAnalysisContext context)
return;
}

if (method.IsImplementationOfAnyInterfaceMember())
{
// should not warn for implementations of interfaces that may be out of our control
return;
}

if (context.Options.IsConfiguredToSkipAnalysis(Rule, method, context.Compilation))
{
// property is excluded from analysis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,36 @@ public static void Method(Uri url, Uri url2) { }

}

[Fact, WorkItem(6371, "https://github.com/dotnet/roslyn-analyzers/issues/6371")]
public async Task CA1054NoWarningsForInterfaceImplementationsAsync()
{
await VerifyCS.VerifyAnalyzerAsync(@"
using System;

public interface IUrlInterface1
{
void Method(string url);
}

public interface IUrlInterface2
{
void Method(string url);
}

public class A : IUrlInterface1, IUrlInterface2
{
public void Method(string url) // Implements IUrlInterface1, implicitly
{
}

void IUrlInterface2.Method(string url) // Implements IUrlInterface2, explicitly
{
}
}
", GetCA1054CSharpResultAt(6, 28, "url", "IUrlInterface1.Method(string)")
, GetCA1054CSharpResultAt(11, 28, "url", "IUrlInterface2.Method(string)"));
}

[Fact]
public async Task CA1054NoWarningNotPublicAsync()
{
Expand Down