A conditionally executed single line should be denoted by indentation -- cpp:S3973

I’m using some 10.0 of SonarQube with SonarScanner for C/C++ sources, and quite likely Java would be same.

It nags about bad indentation in a piece of code like the following:

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

Just assuming that you can reproduce it in any current version, I wonder,
if the special case of equally-indented-if following next line after else,
could be excepted from this rule.

Except for that special case, the indentation rule is just fine.

PS: in case you cannot reproduce it easily, just discard this comment.

Hi Andreas,

I don’t see why we should support this style. I think it’s important to show that the second if will not be unconditionally tested.

What we do support is the following, which binds together at the same level the first if, all subsequent else if and the final else:

    if (...) { ...; }
    else if (...) { ...; }
    else ...

Well, so be it - mine was just an idle suggestion…

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.