Skip to content

Commit b029a8e

Browse files
authored
Merge pull request #3715 from bjornhellander/feature/sa1648-static-abstract-interface-members
Update SA1648 to accept inheritdoc on members implemented from static abstract/virtual interface members
2 parents 1dd5ced + a558a43 commit b029a8e

File tree

4 files changed

+67
-7
lines changed

4 files changed

+67
-7
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/DocumentationRules/SA1648CSharp11UnitTests.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,46 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp11.DocumentationRules
55
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
69
using StyleCop.Analyzers.Test.CSharp10.DocumentationRules;
10+
using Xunit;
711

812
public partial class SA1648CSharp11UnitTests : SA1648CSharp10UnitTests
913
{
14+
[WorkItem(3595, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3595")]
15+
[Theory]
16+
[InlineData("abstract void TestMethod();", "public void TestMethod() {}")]
17+
[InlineData("abstract void TestMethod();", "void TestInterface.TestMethod() {}")]
18+
[InlineData("virtual void TestMethod() {}", "public void TestMethod() {}")]
19+
[InlineData("virtual void TestMethod() {}", "void TestInterface.TestMethod() {}")]
20+
[InlineData("abstract int TestProperty { get; set; }", "public int TestProperty { get; set; }")]
21+
[InlineData("abstract int TestProperty { get; set; }", "int TestInterface.TestProperty { get; set; }")]
22+
[InlineData("virtual int TestProperty { get; set; }", "public int TestProperty { get; set; }")]
23+
[InlineData("virtual int TestProperty { get; set; }", "int TestInterface.TestProperty { get; set; }")]
24+
[InlineData("abstract event System.Action TestEvent;", "public event System.Action TestEvent;")]
25+
[InlineData("abstract event System.Action TestEvent;", "event System.Action TestInterface.TestEvent { add {} remove {} }")]
26+
[InlineData("virtual event System.Action TestEvent;", "public event System.Action TestEvent;")]
27+
[InlineData("virtual event System.Action TestEvent;", "event System.Action TestInterface.TestEvent { add {} remove {} }")]
28+
public async Task TestCorrectMemberInheritDocFromStaticAbstractOrVirtualMemberInInterfaceAsync(string interfaceMember, string classMember)
29+
{
30+
var testCode = $@"
31+
public interface TestInterface
32+
{{
33+
/// <summary>
34+
/// A summary text.
35+
/// </summary>
36+
static {interfaceMember}
37+
}}
38+
39+
public class TestClass : TestInterface
40+
{{
41+
/// <inheritdoc />
42+
static {classMember}
43+
}}";
44+
45+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
46+
}
1047
}
1148
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/DocumentationRules/SA1648CSharp8UnitTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,37 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp8.DocumentationRules
55
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
69
using StyleCop.Analyzers.Test.CSharp7.DocumentationRules;
10+
using Xunit;
711

812
public partial class SA1648CSharp8UnitTests : SA1648CSharp7UnitTests
913
{
14+
[WorkItem(3595, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3595")]
15+
[Theory]
16+
[InlineData("void TestMethod() {}")]
17+
[InlineData("int TestProperty { get; set; }")]
18+
[InlineData("event System.Action TestEvent;")]
19+
public async Task TestIncorrectMemberInheritDocFromStaticMemberInInterfaceAsync(string member)
20+
{
21+
var testCode = $@"
22+
public interface TestInterface
23+
{{
24+
/// <summary>
25+
/// A summary text.
26+
/// </summary>
27+
static {member}
28+
}}
29+
30+
public class TestClass : TestInterface
31+
{{
32+
/// [|<inheritdoc />|]
33+
public static {member}
34+
}}";
35+
36+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
37+
}
1038
}
1139
}

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1648UnitTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,10 @@ public async Task TestIncorrectDelegateInheritDocAsync()
323323
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
324324
}
325325

326-
private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult expected, CancellationToken cancellationToken)
326+
protected static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult expected, CancellationToken cancellationToken)
327327
=> VerifyCSharpDiagnosticAsync(source, new[] { expected }, cancellationToken);
328328

329-
private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken)
329+
protected static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken)
330330
{
331331
var test = CreateTest(expected);
332332
test.TestCode = source;

StyleCop.Analyzers/StyleCop.Analyzers/Helpers/NamedTypeHelpers.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,6 @@ internal static bool IsPartialDeclaration(MemberDeclarationSyntax declaration)
145145
/// <returns>true if the member is implementing an interface member, otherwise false.</returns>
146146
internal static bool IsImplementingAnInterfaceMember(ISymbol memberSymbol)
147147
{
148-
if (memberSymbol.IsStatic)
149-
{
150-
return false;
151-
}
152-
153148
bool isImplementingExplicitly;
154149

155150
// Only methods, properties and events can implement an interface member

0 commit comments

Comments
 (0)