Skip to content

Commit

Permalink
Merge pull request #370 from StefanMaron/development
Browse files Browse the repository at this point in the history
Resolve false positive on Rule0028
  • Loading branch information
Arthurvdv authored Nov 27, 2023
2 parents 5f00f70 + d12f8d0 commit 1b29397
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Design/Rule0028CodeNavigabilityOnEventSubscribers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ private void CodeNavigabilityOnEventSubscribers(CodeBlockAnalysisContext context
if (!context.CodeBlock.IsKind(SyntaxKind.MethodDeclaration)) return;

IEnumerable<MemberAttributeSyntax> MemberAttributeSyntaxList = ((MethodDeclarationSyntax)context.CodeBlock).Attributes.Where(value => SemanticFacts.IsSameName(value.GetIdentifierOrLiteralValue(), "EventSubscriber"));
if (!MemberAttributeSyntaxList.Select(value => value.ArgumentList.Arguments[2]).Where(syntax => syntax.IsKind(SyntaxKind.LiteralAttributeArgument)).Any() &&
!MemberAttributeSyntaxList.Select(value => value.ArgumentList.Arguments[3]).Where(syntax => syntax.IsKind(SyntaxKind.LiteralAttributeArgument)).Any()) return;

AttributeArgumentSyntax eventName = MemberAttributeSyntaxList.Select(value => value.ArgumentList.Arguments[2]).FirstOrDefault();
AttributeArgumentSyntax eventElement = MemberAttributeSyntaxList.Select(value => value.ArgumentList.Arguments[3]).FirstOrDefault();
bool isEventNameStringLiteral = eventName.IsKind(SyntaxKind.LiteralAttributeArgument);
bool isEventElementStringLiteral = !(eventElement.GetIdentifierOrLiteralValue() == "") && eventElement.IsKind(SyntaxKind.LiteralAttributeArgument);
if (!isEventNameStringLiteral && !isEventElementStringLiteral) return;

// Support for using Identifiers instead of Literals in event subscribers is supported from runtime versions: '11.0' or greater.
var manifest = AppSourceCopConfigurationProvider.GetManifest(context.SemanticModel.Compilation);
Expand Down

0 comments on commit 1b29397

Please sign in to comment.