Hello!
I enabled the rule for C# “Functions should not have too many lines of code”. The rule has status “Activate In Quality Profile: The rule is already activated on all available quality profiles”.
Between the “begin” and “end” steps, you need to build your project, execute tests and generate code coverage data. This part is specific to your needs and it is not detailed here.
As you see SonarC# plugin needs compiled code. My assumtpion is that this rule verifies binary code. Your example method executes the same operation many times and I’m sure that compiler optimizes it. Please try to add more logic which cannot be replaced with one instruction (in your case return 32;).
Are you sure that is the designed behavior - examining the compiled code and not code written by developer? It sounds strange to me because Sonar can warn me about TODO comments for example.
Anyway, we configured the rule to 1 line max and copy and pasted one of our methods, but still not there is no warning for too long functions, however issues caused by other sources do appear:
This is a parameterized rule (i.e. you need to set the threshold on server side) with a default value of 80. As your methods contains less than 80 lines of code, no issue is raised on it.
Looking at the scanner logs you should see something like Invalid rule parameter: maximum number of lines = 1. Must be at least 2. I cannot tell you why this limit was set but you have to give a value greater than or equals to 2.
If you look at the build step logs of your vsts build you should be able to find the message I mentioned (it should be prefixed by something like AD0001 - Analyzer).