Skip to content

Useless ternary operator (UselessTernaryOperator)

Type Scope Severity Activated
by default
Minutes
to fix
Tags
Code smell BSL Info Yes 1 badpractice
suspicious

Description

The placement of Boolean constants "True" or "False" in the ternary operator indicates poor code thoughtfulness.

Examples

Useless operators

A = ?(B = 1, True, False);
A = ?(B = 0, False, True);

Suspicious operators

A = ?(B = 1, True, True);
A = ?(B = 0, 0, False);

Snippets

Diagnostic ignorance in code

// BSLLS:UselessTernaryOperator-off
// BSLLS:UselessTernaryOperator-on

Parameter for config

"UselessTernaryOperator": false