Braces
The Braces Ruleset contains a collection of braces rules.
IfStmtsMustUseBraces
Since: PMD 5.0
Avoid using if statements without using curly braces.
//IfStatement[@Else = "false" and not(child::Scope)]
Example(s):
// Ok
if (foo) {
x++;
}
// Bad
if (foo)
x++;
IfElseStmtsMustUseBraces
Since: PMD 5.0
Avoid using if..else statements without using curly braces.
//ExpressionStatement[parent::IfStatement[@Else = "true"]]
[not(child::Scope)]
[not(child::IfStatement)]
Example(s):
// Ok
if (foo) {
x++;
} else {
y++;
}
// Bad
if (foo)
x++;
else
y++;
WhileLoopsMustUseBraces
Since: PMD 5.0
Avoid using 'while' statements without using curly braces.
//WhileLoop[not(child::Scope)]
Example(s):
// Ok
while (true) {
x++;
}
// Bad
while (true)
x++;
ForLoopsMustUseBraces
Since: PMD 5.0
Avoid using 'for' statements without using curly braces.
//ForLoop[not(child::Scope)]
|
//ForInLoop[not(child::Scope)]
Example(s):
// Ok
for (var i = 0; i < 42; i++) {
foo();
}
// Bad
for (var i = 0; i < 42; i++)
foo();