CC0014 should place the three elements of the ternary on separate lines if the total length would exceed 72 characters.
See original GitHub issue if veryLongCondition(withALongArgumentList) Then
aVariable = aLongfunctionName(withAnotherLongArgList)
else
aVariable = anEvenLongerfunctionName(withYetAnotherLongArgList)
end if
Current output after fix applied:
aVariable = if(veryLongCondition(withALongArgumentList), aLongfunctionName(withAnotherLongArgList), anEvenLongerfunctionName(withYetAnotherLongArgList))
Expected output after fix applied:
aVariable = if(veryLongCondition(withALongArgumentList),
aLongfunctionName(withAnotherLongArgList),
anEvenLongerfunctionName(withYetAnotherLongArgList))
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Multiple Statements in the Ternary Operator - java
If you absolutely must do it with one ternary operator that's how it can be done : flag = str.length() == 1 ?...
Read more >Can ternary operators contain multiple actions? - JavaScript
Yes, we can, but with one proviso… There is no block demarcation so that action should be simple, else it would be better...
Read more >Ternary Operator in C Explained
Programmers use the ternary operator for decision making in place of longer if and else conditional statements. The ternary operator take three ......
Read more >Multiple lines in a ternary operator's clauses? - JavaScript
Basically if you want a nest a ternary operator in an existing ternary operator you need to put parentheses around the whole thing...
Read more >Ternary operators are the worst..unless you indent them right!
There is no reason that an if expression can't be multiple lines long. If you need a condition with three or more branches,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I wonder if a better option for the long line issue would be having a refactoring which takes a method with multiple parameters on a single line and breaks them up on multiple lines adding named parameters. It wouldn’t necessarily help the case of ternary operators, but might be useful as a separate tool.
@giggio I too have quite a lot screen area (two side by side 60cm/24" monitors) but long lines are still a pain to read.