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

MSTEST0018: fix false positive with data member visibility #3866

Merged
merged 1 commit into from
Sep 25, 2024
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 @@ -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