Skip to content

Instantly share code, notes, and snippets.

@mvolkmann
Created March 1, 2018 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvolkmann/7876a4629ba11291ed65882c5d364f04 to your computer and use it in GitHub Desktop.
Save mvolkmann/7876a4629ba11291ed65882c5d364f04 to your computer and use it in GitHub Desktop.
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.
@mvolkmann
Copy link
Author

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