Skip to content

Commit

Permalink
Reduce nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
costin-zaharia-sonarsource committed Mar 21, 2024
1 parent 8ad9358 commit 7099130
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions analyzers/src/SonarAnalyzer.CSharp/Rules/SpecifyRouteAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,22 @@ protected override void Initialize(SonarAnalysisContext context) =>

private void ReportIssues(SonarSymbolReportingContext context, ISymbol symbol, ConcurrentStack<Location> secondaryLocations)
{
if (!secondaryLocations.IsEmpty)
if (secondaryLocations.IsEmpty)
{
foreach (var declaration in symbol.DeclaringSyntaxReferences.Select(x => x.GetSyntax()))
return;
}

foreach (var declaration in symbol.DeclaringSyntaxReferences.Select(x => x.GetSyntax()))
{
if (declaration.GetIdentifier() is { } identifier)
{
if (declaration.GetIdentifier() is { } identifier)
{
context.ReportIssue(CSharpGeneratedCodeRecognizer.Instance, Diagnostic.Create(Rule, identifier.GetLocation(), secondaryLocations));
context.ReportIssue(CSharpGeneratedCodeRecognizer.Instance, Diagnostic.Create(Rule, identifier.GetLocation(), secondaryLocations));

// When a symbol was declared in multiple locations, we want to avoid reporting the same secondary locations multiple times.
// The list is cleared only if the declaration is not in generated code. Otherwise, the secondary locations are not reported at all.
if (!Language.GeneratedCodeRecognizer.IsGenerated(declaration.SyntaxTree))
{
secondaryLocations.Clear();
}
// When a symbol was declared in multiple locations, we want to avoid reporting the same secondary locations multiple times.
// The list is cleared only if the declaration is not in generated code. Otherwise, the secondary locations are not reported at all.
if (!Language.GeneratedCodeRecognizer.IsGenerated(declaration.SyntaxTree))
{
secondaryLocations.Clear();
}
}
}
Expand Down

0 comments on commit 7099130

Please sign in to comment.