Switch cases should not have too many lines - not statements?

65 views
Skip to first unread message

Roger Larsson

unread,
Jul 20, 2017, 6:34:34 PM7/20/17
to SonarQube
Hi,

We have recently turned on a formatting option to put one parameter per line.
This does not work grate with a rule counting lines...

Switch cases should not have too many lines

squid : S1151

Took a look at the test cases used and there is no test case resembling our situation.
sonar-java/java-checks/src/test/files/checks/SwitchCaseTooBigCheck.java

An example
swich (code) {
   
case ONE:
        LOGGER
.trace("one {} {}",
                     obj
,
                     param
);

        result
= obj.call(5,
                          param
);

       
break;
   
case TWO:


With this I am counting to six code lines and two blank, with our old formatting we would have three...

Is lines really a good measure? With statements they both would be the same.

/RogerL

Nicolas Peru

unread,
Jul 21, 2017, 8:48:47 AM7/21/17
to Roger Larsson, SonarQube
Hi, 

This rule counts the number of lines of code, in other words, where a code token appear, it counts one line.
This formatting is pretty unusual so I don't see the point of modifying the rule to support it, and the threshold of the rule S1151  can be configured so feel free to change the default value to adapt to your formatting.

Cheers, 

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/6ee1cde0-b53f-4785-acbd-76298270270a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Nicolas Peru | SonarSource

Roger Larsson

unread,
Jul 21, 2017, 5:33:57 PM7/21/17
to SonarQube, roger....@e-gatan.se
Hi,

Modifying the limit to what? Four statements with two arguments plus break give nine... That is nine lines with only one argument per call...

In my opinion counting lines for any purpose is usually wrong.Was once in a project (C,C++) where faults per lines were measured and we had a debate about to write

if (...)
{
   
- - -
}
else
{
   
- - -
}



or

if (...) {
   
- - -
} else {
   
- - -
}

Since there were no technical reason to choose one over the other, guess what version won...

/RogerL
Reply all
Reply to author
Forward
0 new messages