- What language is this for?
C# (ASP.NET Core) - Which rule?
S6934: A Route attribute should be added to the controller when a route template is specified at the action level - Are you using
SonarLint 7.8.0.88494 / Visual Studio Community 2022 (not connected)
I don’t think this rule should be applied to abstract
controller classes:
// Lack of [Route] triggers S6934
public abstract class BaseController : Controller {
[HttpGet]
[Route("list")]
public IActionResult List() {
// ... load and return items
}
}
[Route("/api/user")]
public sealed UserController : MyAbstractController {
// other controller code
}
UserController
has its own Route
attribute and therefore exposes /api/user/list
which triggers its version of List()
.
Of course there is no way to enforce setting Route
attributes on derived classes, but I think BaseController
being abstract
could be enough of a hint, especially once the project’s conventions are known.
For reference our project does NOT use conventional routing (bar a couple very specific cases).