Skip to content

Instantly share code, notes, and snippets.

@nmn
Created November 30, 2023 10:02
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 nmn/f605e6564a5725201e61e6b3f3aee2ba to your computer and use it in GitHub Desktop.
Save nmn/f605e6564a5725201e61e6b3f3aee2ba to your computer and use it in GitHub Desktop.
Prettier Experimental Ternaries - Bad Cases
const exprs =
pathUtils.isTemplateLiteral(path) ? path.get('expressions')
: pathUtils.isTaggedTemplateExpression(path) ?
path.get('quasi').get('expressions')
: [];
// I would want that formated as:
const exprs =
pathUtils.isTemplateLiteral(path) ?
path.get('expressions')
: pathUtils.isTaggedTemplateExpression(path) ?
path.get('quasi').get('expressions')
: [];
// If the ternary is multi-line, the conditions and the "then" cases should all be on separate lines.
const key =
prop.key.type === 'Identifier' && !prop.computed ? prop.key.name
: prop.key.type === 'StringLiteral' ? prop.key.value
: null;
// I would want that to be formatted as:
const key =
prop.key.type === 'Identifier' && !prop.computed ?
prop.key.name
: prop.key.type === 'StringLiteral' ?
prop.key.value
: null;
// If we are emulating if-else, the "then" cases need to be on their own lines.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment