Repository navigation
Keep single-WHEN CASE expressions on one line #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -160,7 +160,15 @@ describe("expr", () => { | |
| }); | ||
|
|
||
| describe("case", () => { | ||
| it(`formats CASE expression always on multiple lines`, async () => { | ||
| it(`formats single-WHEN CASE expression on one line`, async () => { | ||
| await test(`SELECT CASE WHEN x = 1 THEN 'A' END`); | ||
| }); | ||
|
|
||
| it(`formats single-WHEN CASE expression with base expression on one line`, async () => { | ||
| await test(`SELECT CASE x WHEN 1 THEN 'A' END`); | ||
| }); | ||
|
|
||
| it(`formats CASE expression with ELSE on multiple lines`, async () => { | ||
| await test(dedent` | ||
| SELECT CASE x | ||
| WHEN 1 THEN 'A' | ||
|
|
@@ -192,15 +200,14 @@ describe("expr", () => { | |
| it(`breaks long WHEN/THEN into separate lines`, async () => { | ||
| await test( | ||
| dedent` | ||
| SELECT CASE | ||
| WHEN column_name = 1 THEN | ||
| result_name | ||
| SELECT CASE WHEN column_name = 1 | ||
| THEN | ||
| result_name | ||
| END | ||
|
Comment on lines
+203
to
206
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks weird. It reads like Similar with other examples where we have a I think we really need to take a different approach to this. IMHO what we really desire is:
But if somewhere inside the case-expression we have multi-line content, then we should switch to multi-line formatting of the I think a simple general fix for this all would be to eliminate this
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 :) |
||
| `, | ||
| { printWidth: 35 }, | ||
| ); | ||
| }); | ||
|
|
||
| it(`breaks multiple long WHEN/THEN clauses without blank lines between them`, async () => { | ||
| await test( | ||
| dedent` | ||
|
|
@@ -232,12 +239,11 @@ describe("expr", () => { | |
| it(`indents long multi-condition WHEN clauses`, async () => { | ||
| await test( | ||
| dedent` | ||
| SELECT CASE | ||
| WHEN | ||
| column_name = 1 | ||
| AND (other_name = 2 OR other_name = 3) | ||
| THEN | ||
| result_name | ||
| SELECT CASE WHEN | ||
| column_name = 1 | ||
| AND (other_name = 2 OR other_name = 3) | ||
| THEN | ||
| result_name | ||
| END | ||
| `, | ||
| { printWidth: 50 }, | ||
|
|
@@ -247,10 +253,9 @@ describe("expr", () => { | |
| it(`indents long multi-expression THEN clauses`, async () => { | ||
| await test( | ||
| dedent` | ||
| SELECT CASE | ||
| WHEN column_name = 1 THEN | ||
| result_name = 1 | ||
| AND other_name = 2 | ||
| SELECT CASE WHEN column_name = 1 THEN | ||
| result_name = 1 | ||
| AND other_name = 2 | ||
| END | ||
| `, | ||
| { printWidth: 45 }, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:
But also get:
I'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)