Skip to content

Add check for NestedTernaryOperator #510

@EliteMasterEric

Description

@EliteMasterEric

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;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions