Hi,
We are using SonarCloud on our C# projects in a default configuration. (we use the Sonar Way profile for c#)
There are some legacy controllers in our code base that had accumulated a lot of parameters in the constructor. So we noticed having a lot of csharpsquid:S107 rules that needed some attention.
But when fixing them we noticed some of the ‘controllers’ had not been detected as having an issue.
Weird behavior here is that when using inheritance, you get extra parameters for free:
I’ve also tested this behaviour with SonarLint in VS2022 (v5.3.0.41207). (I didn’t connect to our sonarcloud project, to make sure we get default behavior)
So my question:
Is this default behavior I’m not aware of or is this just a bug?
If it isn’t a bug, do you have suggestions how to make people aware in our team that even in these situations to keep their constructors/methods nice and tidy?
– Fred
Code for copy paste:
public class Class1 {
public Class1(int one) { }
}
public class Class2
{
public Class2(int one, int two, int three, int four,
int five, int six, int seven, int eight)
{
}
}
public class Class3 : Class1
{
public Class3(int one, int two, int three, int four,
int five, int six, int seven, int eight) : base(one)
{
}
}
public class Class4 : Class1
{
public Class4(int one, int two, int three, int four,
int five, int six, int seven, int eight, int nine) : base(one)
{
}
}