Skip to content

Commit

Permalink
Fix reporting on partial classes
Browse files Browse the repository at this point in the history
  • Loading branch information
costin-zaharia-sonarsource committed Mar 21, 2024
1 parent adfa035 commit 234510c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ private static void ReportIssues(SonarSymbolReportingContext context, ISymbol sy
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.
secondaryLocations.Clear();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public partial class HomeController : Controller // Noncompliant
{
[HttpGet("Test")]
public IActionResult Index() => View(); // Secondary
// Secondary @-1
}
""")
.AddSnippet("""
Expand All @@ -64,6 +63,30 @@ public partial class HomeController : Controller // Noncompliant
}
""")
.Verify();

[TestMethod]
public void SpecifyRouteAttribute_PartialClasses_OneGenerated_CS() =>
builder
.AddSnippet("""
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Routing;

public partial class HomeController : Controller // Noncompliant
{
[HttpGet("Test")]
public IActionResult Index() => View(); // Secondary
}
""")
.AddSnippet("""
// <auto-generated/>
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Routing;

public partial class HomeController : Controller
{
}
""")
.Verify();
}

#endif

0 comments on commit 234510c

Please sign in to comment.