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.

Indentation is too aggressive for ternary operator

See original GitHub issue

Actual:

var v =
    0 ? 1 :
        2 ? 3 :
            4;

Expected:

var v =
    0 ? 1 :
    2 ? 3 :
    4;

I believe the fix is that if the false branch of the ternary operator should have the same indentation as the true branch. In the case where the true branch is on the same line as the condition, it should not be considered indented, and therefore the false branch should not be indented.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:18
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
saschanazcommented, Nov 5, 2018

Does the team still want to fix this? In other words, will the team merge my PR if I revive #5905?

1reaction
DanielRosenwassercommented, Jun 30, 2015

How does this compare to the indentation of the ternary operator in other languages, such as vanilla JavaScript, C/C++, C#, etc. ?

I think that’s the right question to ask here. Let’s try to stay close to other languages service teams. If it turns out there are shortcomings, then they should know too.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ternary operator (?:) wrong indent : IDEA-157071 - YouTrack
I suppose there is an issue with code auto reformatting. The JCC (Java Code Convensions) said how the ternary operator (?:) line breaking...
Read more >
I shall never give up on forcing ternary statements down my ...
I only use ternary operators for assignments if it's very short and obvious how the assignment is working: string username = user.
Read more >
How should I indent ternary conditional operator in python so ...
The first is more readible. · (1) PEP 8 prefers parentheses over backslashes for expressions spanning several lines. · Unfortunately, questions ...
Read more >
Maintainable JavaScript - Javascript - 50 - Passei Direto
Basic Formatting Indentation Levels Statement Termination Line Length Line ... Naming Strict Mode Assignments Equality Operators Ternary Operator Statements ...
Read more >
Joytran: Timeline - Chisel
switch from K&R style indentation to Lisp style indentation (I don't care for ... including a switch to ternary operator if/else statements in...
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