Skip to content

Commit

Permalink
MSTEST0018: fix false positive with data member visibility (#3866)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink committed Sep 25, 2024
1 parent 4b97111 commit cb5f787
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

namespace MSTest.Analyzers;

/// <summary>
/// MSTEST0018: <inheritdoc cref="Resources.DynamicDataShouldBeValidTitle"/>.
/// </summary>
[DiagnosticAnalyzer(LanguageNames.CSharp, LanguageNames.VisualBasic)]
public sealed class DynamicDataShouldBeValidAnalyzer : DiagnosticAnalyzer
{
Expand Down Expand Up @@ -202,8 +205,7 @@ private static void AnalyzeDataSource(SymbolAnalysisContext context, AttributeDa
return;
}

if (!member.IsStatic
|| member.DeclaredAccessibility != Accessibility.Public)
if (!member.IsStatic)
{
context.ReportDiagnostic(attributeSyntax.CreateDiagnostic(DataMemberSignatureRule, declaringType.Name, memberName));
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ await VerifyCS.VerifyAnalyzerAsync(
VerifyCS.Diagnostic(DynamicDataShouldBeValidAnalyzer.DataMemberSignatureRule).WithLocation(1).WithArguments("MyTestClass", "GetData"));
}

public async Task MemberIsNotPublic_Diagnostic()
public async Task MemberIsNotPublic_NoDiagnostic()
{
string code = """
using System;
Expand All @@ -557,13 +557,13 @@ public async Task MemberIsNotPublic_Diagnostic()
[TestClass]
public class MyTestClass
{
[{|#0:DynamicData("Data")|}]
[DynamicData("Data")]
[TestMethod]
public void TestMethod1(object[] o)
{
}

[{|#1:DynamicData("GetData", DynamicDataSourceType.Method)|}]
[DynamicData("GetData", DynamicDataSourceType.Method)]
[TestMethod]
public void TestMethod2(object[] o)
{
Expand All @@ -574,10 +574,7 @@ public void TestMethod2(object[] o)
}
""";

await VerifyCS.VerifyAnalyzerAsync(
code,
VerifyCS.Diagnostic(DynamicDataShouldBeValidAnalyzer.DataMemberSignatureRule).WithLocation(0).WithArguments("MyTestClass", "Data"),
VerifyCS.Diagnostic(DynamicDataShouldBeValidAnalyzer.DataMemberSignatureRule).WithLocation(1).WithArguments("MyTestClass", "GetData"));
await VerifyCS.VerifyAnalyzerAsync(code);
}

public async Task MethodHasParameters_Diagnostic()
Expand Down

0 comments on commit cb5f787

Please sign in to comment.