Skip to content

Commit

Permalink
Fix CA1515 nested types false positives
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas-Shephard committed Nov 26, 2024
1 parent 5435ba7 commit 0f683f3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public override void Initialize(AnalysisContext context)
private void AnalyzeType(SymbolAnalysisContext context)
{
INamedTypeSymbol namedTypeSymbol = (INamedTypeSymbol)context.Symbol;
if (namedTypeSymbol.IsPublic()
if (namedTypeSymbol.IsExternallyVisible()
&& GetIdentifier(namedTypeSymbol.DeclaringSyntaxReferences[0].GetSyntax()) is SyntaxToken identifier)
{
context.ReportDiagnostic(identifier.CreateDiagnostic(Rule));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,20 +440,9 @@ class Program
{
public static void Main() {}

public struct [|MyValueType|]
public struct MyValueType
{
public class [|Nested|] {}
}
}
""",
"""
class Program
{
public static void Main() {}

internal struct MyValueType
{
internal class Nested {}
public class Nested {}
}
}
""");
Expand All @@ -463,19 +452,8 @@ Class Program
Public Shared Sub Main()
End Sub

Public Structure [|MyValueType|]
Public Class [|Nested|]
End Class
End Structure
End Class
""",
"""
Class Program
Public Shared Sub Main()
End Sub

Friend Structure MyValueType
Friend Class Nested
Public Structure MyValueType
Public Class Nested
End Class
End Structure
End Class
Expand Down

0 comments on commit 0f683f3

Please sign in to comment.