haxe-checkstyle icon indicating copy to clipboard operation
haxe-checkstyle copied to clipboard

Add check for NestedTernaryOperator

Open EliteMasterEric opened this issue 2 years ago • 0 comments

Detects ternary operators which are located within one of the cases of another ternary operator. Many developers find simple ternary operators easy to read, but quickly become overwhelmed when several are included in one statement. This check can be resolved by refactoring with if/else conditional blocks.

Configuration

{
    "type": "NestedTernaryOperator",
    "props": {
        "severity": "ERROR"
    }
}

Invalid

var value = (event.keyCode != null) ? (event.keyCode == KeyCode.ENTER) ? 10 : 5 : 1;

Valid

var value = 1;
if (event.keyCode != null) {
    value = (event.keyCode == KeyCode.ENTER) ? 10 : 5;
}

EliteMasterEric avatar Sep 09 '21 19:09 EliteMasterEric