Repository navigation
Keep single-WHEN CASE expressions on one line - #92
joelmukuthu wants to merge 1 commit into
Conversation
nene
left a comment
There was a problem hiding this comment.
Thanks. But looking at the resulting formatting, I think a different approach is needed. See below.
| SELECT CASE WHEN column_name = 1 | ||
| THEN | ||
| result_name | ||
| END |
There was a problem hiding this comment.
This looks weird. It reads like SELECT ... THEN ... END.
Similar with other examples where we have a CASE with single WHEN clause that has multi-line content.
I think we really need to take a different approach to this. IMHO what we really desire is:
- when the whole
CASE ... ENDexpression can fit on a single line, then don't break it to multiple lines.
But if somewhere inside the case-expression we have multi-line content, then we should switch to multi-line formatting of the case-expression as well.
I think a simple general fix for this all would be to eliminate this node.clauses.length === 1 special case and just use line instead if hardline in the case_expr implementation. We could instead add a different special case: saying that whenever there are more then one item in CASE we force it on multiple lines, but if it's just one, it can be on a single line, if it fits.
There was a problem hiding this comment.
Ha, I commented on this before I saw your comment. I'll look into it later this week but feel free to pick up before then if you'd like :)
| THEN | ||
| result_name |
There was a problem hiding this comment.
This looks a little awkward but fixing it is beyond the scope of this PR (it'd also go against the design in #80 (comment)). It would also probably require some coupling between WHEN and THEN i.e. "break THEN if WHEN conditions break", so we can keep:
WHEN
column_name = 1
AND other_column = 2
THEN
result_nameBut also get:
CASE WHEN column_name = 1
THEN result_nameI'm not sure how to go about this, or if closing this PR is the way to go for now (which is also fine by me)
Ref #91