Skip to content

Commit

Permalink
Merge pull request #3830 from bjornhellander/feature/sa1404-global-3829
Browse files Browse the repository at this point in the history
Update SA1404 to not crash when attribute uses a namespace alias
  • Loading branch information
sharwell authored Apr 29, 2024
2 parents d855e3a + 1f7ac37 commit 17b613d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -426,5 +426,23 @@ public void Bar()

await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Theory]
[InlineData("global::System.Obsolete")]
[InlineData("global::My")]
[WorkItem(3829, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3829")]
public async Task TestGlobalOtherAttributeAsync(string name)
{
var testCode = $@"public class MyAttribute : System.Attribute
{{
}}
[{name}]
public class Foo
{{
}}";

await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,15 @@ public void HandleAttributeNode(SyntaxNodeAnalysisContext context)
{
if (!(attribute.Name is SimpleNameSyntax simpleNameSyntax))
{
QualifiedNameSyntax qualifiedNameSyntax = attribute.Name as QualifiedNameSyntax;
simpleNameSyntax = qualifiedNameSyntax.Right;
if (attribute.Name is AliasQualifiedNameSyntax aliasQualifiedNameSyntax)
{
simpleNameSyntax = aliasQualifiedNameSyntax.Name;
}
else
{
QualifiedNameSyntax qualifiedNameSyntax = attribute.Name as QualifiedNameSyntax;
simpleNameSyntax = qualifiedNameSyntax.Right;
}
}

if (simpleNameSyntax.Identifier.ValueText != nameof(SuppressMessageAttribute)
Expand Down

0 comments on commit 17b613d

Please sign in to comment.