I consider these to be acceptable options for writing a ternary expression:
// Single line (for shorter expressions)
let x = condition ? trueOperand : falseOperand;
// Multiple line (first acceptable option, use either 1 or 2 but use the same one consistently)
let x = (condition ?
trueOperand :
falseOperand
);
// Multiple line (second acceptable option, use either 1 or 2 but use the same one consistently)
let x = (
condition ?
trueOperand :
falseOperand
);
// Imitate a match expression (nice to have)
let x = (
firstCondition ? firstResult :
secondCondition ? secondResult :
thirdCondition ? thirdResult :
defaultResult
);
But currently dprint seems insistent on formatting ternary expressions like this below. This violates the consistent principle of indented blocks always being enclosed in parens, brackets, or braces, and I think that inconsistency harms readability. I strongly dislike this formatting style (with "operatorPosition": "sameLine"):
let x = condition ?
trueOperand :
falseOperand;
I would like to have an option to not enforce this formatting, and ideally to enforce formatting like the above examples instead.