Created
March 1, 2018 15:31
-
-
Save mvolkmann/7876a4629ba11291ed65882c5d364f04 to your computer and use it in GitHub Desktop.
Prettier formatting of ternaries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
File an issue if you feel like there is a better way..