question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invalid parens around ternary expressions

See original GitHub issue

Try this code with width 34, 35, 36. At 35 prettier will add one extra bracket.

Input:

const foo = {
  bar: props.bar ? props.bar : noop,
  baz: props.baz
}

Output:

// At 34: good
const foo = {
  bar: (
    props.bar ? props.bar : noop
  ),
  baz: props.baz
};
// At 35: bad
const foo = {
  bar: props.bar ? props.bar : noop
  ),
  baz: props.baz
};
// At 36: good
const foo = {
  bar: props.bar ? props.bar : noop,
  baz: props.baz
};

https://jlongster.github.io/prettier/#{"content"%3A"const foo %3D {\n bar%3A props.bar %3F props.bar %3A noop%2C\n baz%3A props.baz\n}"%2C"options"%3A{"printWidth"%3A35%2C"tabWidth"%3A2%2C"singleQuote"%3Afalse%2C"trailingComma"%3Afalse%2C"bracketSpacing"%3Atrue%2C"doc"%3Afalse}}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
vjeuxcommented, Jan 29, 2017

@umidbekkarimov hopefully you don’t find more 😃 If you do, we’ll fix them quickly!

1reaction
vjeuxcommented, Jan 28, 2017

@umidbekkarimov thanks for the great bug report and sorry I got confused! #502 is a fix for it 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Should parenthesis always be placed around the ternary ...
Parentheses are not required around ternary (also known as conditional) operators or its sections, because their precedence is so very low in ...
Read more >
Prettier removes parentheses around conditional in ternary ...
Adding parens around every ternary condition would cause a lot of churn. Are we sure we want to do that?
Read more >
no-extra-parens - ESLint - Pluggable JavaScript Linter
This rule restricts the use of parentheses to only where they are necessary. Rule Details. This rule always ignores extra parentheses around the...
Read more >
void operator - JavaScript - MDN Web Docs
This operator allows evaluating expressions that produce a value into places where an expression that evaluates to undefined is desired.
Read more >
Ternary conditional operator - Wikipedia
In computer programming, the ternary conditional operator is a ternary operator that is part of the syntax for basic conditional expressions in several ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found