Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Prettier formatting of ternaries
// Original code
const score = 7;
const someVar =
score < 10 ? 'some long string' :
score < 20 ? 'this is looking promising' :
score < 30 ? 'passing' :
score < 40 ? 'proficient' :
'expert';
// What Prettier does
const score = 7;
const someVar =
score < 10
? 'some long string'
: score < 20
? 'this is looking promising'
: score < 30 ? 'passing' : score < 40 ? 'proficient' : 'expert';
// Why does the last line contain more than one condition?
// In function definitions Prettier either puts all the parameters on the same line
// or each one on a separate line. Ternaries should be the same ...
// either all conditions on one line or each on a separate line.
@lipis
Copy link

lipis commented Mar 1, 2018

File an issue if you feel like there is a better way..

@mvolkmann
Copy link
Author

mvolkmann commented Mar 1, 2018

Okay, I just filed prettier/prettier#4087.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment