Fix S6934 FP: Abstract Controller base class
Closed this issue · 0 comments
zsolt-kolbay-sonarsource commented
Description
S6934 raises an issue when the Route
attribute isn't added to an abstract Controller
class (but it's added to one or more of its action methods). This shouldn't happen, as the action method will always be accessed through a non-abstract derived rather than the abstract base class, so the Route
attribute only needs to be applied there.
Repro steps
public abstract class BaseController : Controller // Noncompliant - FP: shouldn't raise on abstract classes
{
[HttpGet]
[Route("list")]
public IActionResult List() // Secondary
{
// ... load and return items
return View();
}
}
[Route("/api/user")]
public sealed class UserController : BaseController
{
// other controller code
}
Expected behavior
The rule should not raise an issue on the abstract class.
Actual behavior
The rule raises an issue on the abstract Controller
class.
Related information
- C#/VB.NET Plugins version: 9.24
- Visual Studio version: Visual Studio 2022 (17.9.6)
- Operating System: Windows 10