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

Report RS1008 for ISymbol and IOperation fields #7197

Merged
merged 2 commits into from
Mar 5, 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 @@ -141,6 +141,12 @@ protected override void AnalyzeNode(SymbolAnalysisContext symbolContext, TFieldD
}
}

if (SymbolEqualityComparer.Default.Equals(type, _symbolType) || SymbolEqualityComparer.Default.Equals(type, _operationType))
{
ReportDiagnostic(type, typeNode, symbolContext);
return;
}

foreach (INamedTypeSymbol iface in type.AllInterfaces)
{
if (SymbolEqualityComparer.Default.Equals(iface, _symbolType) || SymbolEqualityComparer.Default.Equals(iface, _operationType))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Microsoft.CodeAnalysis.Analyzers.UnitTests.MetaAnalyzers
{
public class DoNotStorePerCompilationDataOntoFieldsRuleTests
{
[Fact]
[Fact, WorkItem(7196, "https://github.com/dotnet/roslyn-analyzers/issues/7196")]
public async Task CSharp_VerifyDiagnosticAsync()
{
var source = @"
Expand All @@ -44,6 +44,8 @@ class MyAnalyzer : DiagnosticAnalyzer
private readonly List<MyNamedType> x3;
private static Dictionary<MyCompilation, MyNamedType> x4;
private static readonly IBinaryOperation x5;
private static readonly ISymbol x6;
private static readonly IOperation x7;

public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
{
Expand All @@ -63,13 +65,15 @@ public override void Initialize(AnalysisContext context)
GetCSharpExpectedDiagnostic(20, 28, violatingTypeName: typeof(CSharpCompilation).FullName),
GetCSharpExpectedDiagnostic(21, 27, violatingTypeName: typeof(INamedTypeSymbol).FullName),
GetCSharpExpectedDiagnostic(22, 31, violatingTypeName: "MyCompilation"),
GetCSharpExpectedDiagnostic(23, 29, violatingTypeName: typeof(IBinaryOperation).FullName)
GetCSharpExpectedDiagnostic(23, 29, violatingTypeName: typeof(IBinaryOperation).FullName),
GetCSharpExpectedDiagnostic(24, 29, violatingTypeName: typeof(ISymbol).FullName),
GetCSharpExpectedDiagnostic(25, 29, violatingTypeName: typeof(IOperation).FullName)
};

await VerifyCS.VerifyAnalyzerAsync(source, expected);
}

[Fact]
[Fact, WorkItem(7196, "https://github.com/dotnet/roslyn-analyzers/issues/7196")]
public async Task VisualBasic_VerifyDiagnosticAsync()
{
var source = @"
Expand All @@ -95,6 +99,8 @@ Public Shared ReadOnly x2 As VisualBasicCompilation
Private ReadOnly x3 As List(Of MyNamedType)
Private Shared x4 As Dictionary(Of MyCompilation, MyNamedType)
Private Shared ReadOnly x5 As IBinaryOperation
Private Shared ReadOnly x6 As ISymbol
Private Shared ReadOnly x7 As IOperation

Public Overrides ReadOnly Property SupportedDiagnostics() As ImmutableArray(Of DiagnosticDescriptor)
Get
Expand All @@ -112,7 +118,9 @@ End Class
GetBasicExpectedDiagnostic(20, 34, violatingTypeName: typeof(VisualBasicCompilation).FullName),
GetBasicExpectedDiagnostic(21, 36, violatingTypeName: typeof(INamedTypeSymbol).FullName),
GetBasicExpectedDiagnostic(22, 40, violatingTypeName: "MyCompilation"),
GetBasicExpectedDiagnostic(23, 35, violatingTypeName: typeof(IBinaryOperation).FullName)
GetBasicExpectedDiagnostic(23, 35, violatingTypeName: typeof(IBinaryOperation).FullName),
GetBasicExpectedDiagnostic(24, 35, violatingTypeName: typeof(ISymbol).FullName),
GetBasicExpectedDiagnostic(25, 35, violatingTypeName: typeof(IOperation).FullName)
};

await VerifyVB.VerifyAnalyzerAsync(source, expected);
Expand Down