diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/SpecifyRouteAttribute.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/SpecifyRouteAttribute.cs index a2cbb3b038f..4fb98417299 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/SpecifyRouteAttribute.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/SpecifyRouteAttribute.cs @@ -76,13 +76,6 @@ private void ReportIssues(SonarSymbolReportingContext context, ISymbol symbol, C if (declaration.GetIdentifier() is { } identifier) { 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(); - } } } } diff --git a/analyzers/tests/SonarAnalyzer.Test/Rules/SpecifyRouteAttributeTest.cs b/analyzers/tests/SonarAnalyzer.Test/Rules/SpecifyRouteAttributeTest.cs index ddcf31bc37e..0074fb3fa66 100644 --- a/analyzers/tests/SonarAnalyzer.Test/Rules/SpecifyRouteAttributeTest.cs +++ b/analyzers/tests/SonarAnalyzer.Test/Rules/SpecifyRouteAttributeTest.cs @@ -48,17 +48,17 @@ public void SpecifyRouteAttribute_PartialClasses_CS() => using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Routing; - public partial class HomeController : Controller // Noncompliant + public partial class HomeController : Controller // Noncompliant [first] { [HttpGet("Test")] - public IActionResult Index() => View(); // Secondary + public IActionResult Index() => View(); // Secondary [first, second] } """) .AddSnippet(""" using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Routing; - public partial class HomeController : Controller // Noncompliant + public partial class HomeController : Controller // Noncompliant [second] { } """)