Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Problem with NestedTernaryCheck #167
NestedTernaryCheck have false-positive warnings:
If ternary expressions are wrapped into parentheses to explicitly indicate priority of operations no warning is triggered.
Checks work correctly with code:
It fails only if there is simple == or != check clause, and so, when there is no "(" ")" brackets:
produces the tree below:
Moreover, plus for this case is placed under (!) subtree of second ternary operator:
The conditional operator (also called the ternary operator) ?: has the lowest-but-one precedence, so all other operations takes place before the ?
As result, such code as:
And not expected values:
So, I propose to make NestedTernaryCheck more general, i.e. we have to replace it with check which will just count number of ternary operators per expression. That check will cover all cases such as:
New check have to have only one option: number of allowed ternary operators per expression (i.e., X threshold above).