Since: PMD 1.0
Avoid using if statements without using curly braces.
This rule is defined by the following XPath expression:
//IfStatement[count(*) < 3][not(Statement/Block)]
Example:
public class Foo { public void bar() { int x = 0; if (foo) x++; } }
Since: PMD 0.7
Avoid using 'while' statements without using curly braces.
This rule is defined by the following XPath expression:
//WhileStatement[not(Statement/Block)]
Example:
public void doSomething() { while (true) x++; }
Since: PMD 0.2
Avoid using if..else statements without using curly braces.
This rule is defined by the following XPath expression:
//Statement [parent::IfStatement[@Else='true']] [not(child::Block)] [not(child::IfStatement)]
Example:
public void doSomething() { // this is OK if (foo) x++; // but this is not if (foo) x=x+1; else x=x-1; }