Rule: Statements should be on separate lines (OneStatementPerLine) is analyzing incorrectly

  • Bug description: The issue with the analysis is that it is flagging good code (multi-line statements) with a rule for “Statements should be on separate lines”. For the code example below, the second case statement is flagged, but the one above is not. We think it might be because of either multiple parameters in the function call, or because we’re using a namespace in the parameter list.
  • versions
    (SonarQube = * Developer Edition - Version 8.9.2 (build 46101)
    (Scanner = 3.0.1.733)
  • language is C++
  • Example code:
  switch (currentMsgType)
  {
    case MSG_REQUEST:
      handleRequest(currentMsg);
      break;
    case MSG_SEND:
      handleSend(mynamespace::Type::SEND_ID, currentMsg, mynamespace::Priority::LOW);
      break;

Hello @jeremyw,

I don’t see a reason why your code triggers this rule. could you please send us a reproducer to allow us to accurately know what happens?

To generate the reproducer file:

  • Search in the analysis log for the full path of the file that contains the false-positive). You will have to use exactly this name (same case, / or \…)
  • Add the reproducer option to the scanner configuration:
    sonar.cfamily.reproducer= "Full path to the .cpp"
  • Re-run the scanner to generate a file named sonar-cfamily.reproducer in the project folder.
  • Please share this file. If you think this file contains private information, let us know, we’ll send you a private message that will allow you to send it privately.

Hi Loïc,

Thanks for the quick reply. We have created the reproducer file. It is a bit over 6MB in size. I see it has some of our source code included in it. I would like to send this to you in a private manner. Also, it looks like we have an NDA on file with you. Can you confirm that you have the same?

Thanks,

Jeremy

image001.png