Jump to content

Topic on Talk:Continuous integration/Codehealth Pipeline/Flow

"Remove this redundant jump" giving bad advice

3
Daimona Eaytoy (talkcontribs)

See here. Simplified example:

foreach ( $foo as $bar ) {
   if ( foo1() ) {
      doSomething1();
   } elseif ( foo2() ) {
      continue; // <-- faulty line
   } else {
      doSomething2();
   }
}

The continue line is reported by SonarQube as being non-compliant with message "Remove this redundant jump.". On sonarcloud.io there's an interesting description for this issue: "jump statements that direct the control flow to the original direction are just a waste of keystrokes."

I have a very different idea of "waste of keystrokes". Jump statements make code like that more resilient and reliable. Without the continue, some day I might add some instructions after the conditional (but inside the loop) without any tool telling me of my mistake. So no, this is not a waste of keystrokes.

DKinzler (WMF) (talkcontribs)

Yes, indeed.

PWangai-WMF (talkcontribs)

As far as I can tell, the rule in question is inactive for PHP but active for JavaScript and TypeScript. If you happen to have a recent patch, it would be helpful in optimizing the scan feedback in SonarCloud, since the provided patch sample was pruned from SonarCloud long ago. I have gone ahead and disabled the rule for JavaScript and TypeScript. In case it's still an issue, please feel free to reopen the topic.