Braces RulesThe Braces Ruleset contains a collection of braces rules. IfStmtsMustUseBracesAvoid using if statements without using curly braces This rule is defined by the following XPath expression: //IfStatement[count(*) < 3][not(Statement/Block)] Here's an example of code that would trigger this rule: public class Foo { public void bar() { int x = 0; if (foo) x++; } } WhileLoopsMustUseBracesRuleAvoid using 'while' statements without using curly braces This rule is defined by the following XPath expression: //WhileStatement[not(Statement/Block)] Here's an example of code that would trigger this rule: public void doSomething() { while (true) x++; } IfElseStmtsMustUseBracesRuleAvoid using if..else statements without using curly braces This rule is defined by the following XPath expression: //IfStatement[count(*) > 2][not(Statement/Block)] Here's an example of code that would trigger this rule: public void doSomething() { // this is OK if (foo) x++; // but this is not if (foo) x=x+1; else x=x-1; } ForLoopsMustUseBracesRuleAvoid using 'for' statements without using curly braces This rule is defined by the following XPath expression: //ForStatement[not(Statement/Block)] Here's an example of code that would trigger this rule: public void foo() { for (int i=0; i<42;i++) foo(); } |