Skip to content

Commit

Permalink
Add check for interface implementations, CA1054 (#6628)
Browse files Browse the repository at this point in the history
* Add check for interface implementations

* Add tests, checks for all interface implementations

* Add workitem attribute
  • Loading branch information
steveberdy authored May 25, 2023
1 parent 3515b06 commit 615f625
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
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

0 comments on commit 615f625

Please sign in to comment.