SonarSource / sonar-dotnet

Code analyzer for C# and VB.NET projects
https://redirect.sonarsource.com/plugins/csharp.html
GNU Lesser General Public License v3.0
773 stars 226 forks source link

New rule S6960 for C#: Controllers should not have too many responsibilities #9089

Closed mary-georgiou-sonarsource closed 4 months ago

mary-georgiou-sonarsource commented 5 months ago

RSPEC PR: https://github.com/SonarSource/rspec/pull/3845

Parts:

antonioaversa commented 4 months ago

Exclude inherited methods (because there is no option for the user than to implement them)

This may reduce the reach a lot, as many of the big projects have hierarchies of controllers. If there is an abstract base class and there is at least an method which is abstract, there is indeed no option for the user and we may want to exclude the controller altogether.

Regarding the issue on this controller: it's both an API and an MVC controller at the same time. This case seems to be a false positive because the overridden methods are abstract two levels above in the hierarchy and those abstract methods are used by public actions at that level.

denis-troller commented 4 months ago

An issue with static methods in file https://peach.aws-prd.sonarsource.com/issues?projects=umbraco&resolved=false&rules=csharpsquid%3AS6960&open=AY8vNwi3r4ooVA6A4A55

Should we exclude static methods?

denis-troller commented 4 months ago

In my opinion:

Exclude inherited methods (because there is no option for the user than to implement them)

This may reduce the reach a lot, as many of the big projects have hierarchies of controllers. If there is an abstract base class and there is at least an method which is abstract, there is indeed no option for the user and we may want to exclude the controller altogether.

Regarding the issue on this controller: it's both an API and an MVC controller at the same time. This case seems to be a false positive because the overridden methods are abstract two levels above in the hierarchy and those abstract methods are used by public actions at that level.

For the second case, we should ignore inherited controllers. In that particular case we should not raise because the class is indeed focused. We have no way to know that in the general case (what if we inherit from an external DLL?) and the easy way out is to ignore it.

IMO we want to help people who are starting to use the framework and push them towards good habits. Someone using inheritance either