Skip to content

Commit

Permalink
fix: break between non-block if/else statements
Browse files Browse the repository at this point in the history
  • Loading branch information
jtkiesel authored and clementdessoude committed Jan 14, 2024
1 parent 6f587d7 commit 983a09d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ export class BlocksAndStatementPrettierVisitor extends BaseCstPrettierPrinter {

const elseOnSameLine =
hasTrailingLineComments(ctx.statement[0]) ||
hasLeadingLineComments(ctx.Else[0])
hasLeadingLineComments(ctx.Else[0]) ||
!ctx.statement[0].children.statementWithoutTrailingSubstatement?.[0]
.children.block
? hardline
: " ";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,27 @@ public void forEachWithEmptyStatement(List<String> list) {
}

public void ifElseWithEmptyStatements() {
if (test); else {
if (test);
else {
System.out.println("one");
}

if (test) {
System.out.println("two");
} else;

if (test); else;
if (test);
else;
}

public void ifElseWithEmptyStatementsWithComments() {
if (test) /*test*/; else {
if (test) /*test*/;
else {
System.out.println("one");
}

if (test); /*test*/else {
if (test);
/*test*/else {
System.out.println("one");
}

Expand All @@ -65,9 +69,11 @@ public void ifElseWithEmptyStatementsWithComments() {
System.out.println("two");
} else;/*test*/

if (test); /*test*/else;/*test*/
if (test);
/*test*/else;/*test*/

if (test) /*test*/; else /*test*/;
if (test) /*test*/;
else /*test*/;
}

public void simpleWhileWithEmptyStatement(boolean one) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,9 @@ default Shape rotate(double angle) {
}

default String areaMessage() {
if (this instanceof Circle) return "Circle: " + area(); else if (
this instanceof Rectangle
) return "Rectangle: " + area(); else if (
this instanceof RightTriangle
) return "Triangle: " + area();
if (this instanceof Circle) return "Circle: " + area();
else if (this instanceof Rectangle) return "Rectangle: " + area();
else if (this instanceof RightTriangle) return "Triangle: " + area();
// :(
throw new IllegalArgumentException();
}
Expand Down

0 comments on commit 983a09d

Please sign in to comment.