Ternary operators increase nesting complexity
This commit is contained in:
@ -122,4 +122,15 @@ public class CognitiveComplexityVisitor extends ApexParserVisitorAdapter {
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visit(ASTTernaryExpression node, Object data) {
|
||||
State state = (State) data;
|
||||
|
||||
state.increaseNestingLevel();
|
||||
super.visit(node, data);
|
||||
state.decreaseNestingLevel();
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
@ -271,4 +271,23 @@
|
||||
]]>
|
||||
</code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>Ternary operators cause nesting</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-messages>
|
||||
<message>'c__Foo#foo(Integer)' has value 3.</message>
|
||||
</expected-messages>
|
||||
<code>
|
||||
<![CDATA[
|
||||
class Foo {
|
||||
Integer foo(Integer n) {
|
||||
return n < 0 ? // +1
|
||||
-1 : n > 0 ? // +2
|
||||
1 : 0;
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</code>
|
||||
</test-code>
|
||||
</test-data>
|
Reference in New Issue
Block a user