Search code examples
javasonarqube

Configure Sonar to ignore single-line if-statements


Is there a way to configure Sonar to ignore single-line if-statements like

if (value == true) return;

while marking multi-line if-statements witout braces such as

if (value == true)
    return;

as violations?


Solution

  • There is no rule that matches your needs but you can write your own rule with XPath. You can find a tutorial here

    If you don't know how to extend the coding rules of sonar you can find a tutorial here