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 indent with nested ternary in test

See original GitHub issue

Prettier 1.14.3 Playground link

--parser babylon

Input:

$var = ($number % 10 >= 2 &&
    ($number % 100 < 10 || $number % 100 >= 20)
        ? 1
        : 2)
    ? 0
    : 0;

Output:

$var = ($number % 10 >= 2 && ($number % 100 < 10 || $number % 100 >= 20)
? 1
: 2)
  ? 0
  : 0;

Expected behavior:

$var = ($number % 10 >= 2 && ($number % 100 < 10 || $number % 100 >= 20)
  ? 1
  : 2)
    ? 0
    : 0;

Maybe even better output, hard to say what will be looks good, but indent should be don’t loose.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
j-f1commented, Dec 13, 2018

IMO the first two examples should be fixed though.

1reaction
duailibecommented, Oct 17, 2018

@evilebottnawi This is intended #5039

Read more comments on GitHub >

github_iconTop Results From Across the Web

Incorrect indentation on ternary operator with object literal #4203
I was expecting better consistency in alignment between the closing braces & conditional operators. Case with nested ternary expressions & ...
Read more >
What is the accepted formatting for nested ternary-operators?
Ternary gives you such a natural testing structure that you can make the code very readable just by making it multiline and indenting...
Read more >
Ternary operators are the worst..unless you indent them right!
There's absolutely nothing wrong with nested ternaries.
Read more >
no-nested-ternary - ESLint - Pluggable JavaScript Linter
The no-nested-ternary rule disallows nested ternary expressions. Examples of incorrect code for this rule: /*eslint no-nested-ternary: "error"*/ var thing ...
Read more >
Clang-Format Style Options — Clang 16.0.0git documentation
The wrapped lines are indented ContinuationIndentWidth spaces from the start of the line. OAS_Align (in configuration: Align ) Horizontally align operands of ...
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