Skip to content

Commit

Permalink
fixed expression case/if/try handling, fixes #271, fixes #272 (#274)
Browse files Browse the repository at this point in the history
* fixed expression case/if/try handling, fixes #271, fixes #272
* fixed type hints for arrow function parameters in calls, fixes #273
  • Loading branch information
AlexHaxe authored Nov 10, 2018
1 parent 0a96972 commit 954b291
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
- Fixed metadata whitespace, fixes [#263](https://github.com/HaxeCheckstyle/haxe-formatter/issues/263) ([#265](https://github.com/HaxeCheckstyle/haxe-formatter/issues/265))
- Fixed indentation of wrapped anon function, fixes [#256](https://github.com/HaxeCheckstyle/haxe-formatter/issues/256) ([#266](https://github.com/HaxeCheckstyle/haxe-formatter/issues/266))
- Fixed empty lines of doc comments inside conditionals, fixes [#188](https://github.com/HaxeCheckstyle/haxe-formatter/issues/188) ([#270](https://github.com/HaxeCheckstyle/haxe-formatter/issues/270))
- Fixed `sameLine.expression*` handling of Binop and Arrow, fixes [#271](https://github.com/HaxeCheckstyle/haxe-formatter/issues/271) + [#272](https://github.com/HaxeCheckstyle/haxe-formatter/issues/272) ([#274](https://github.com/HaxeCheckstyle/haxe-formatter/issues/274))
- Fixed type hints for arrow function parameters in calls, fixes [#273](https://github.com/HaxeCheckstyle/haxe-formatter/issues/273) ([#274](https://github.com/HaxeCheckstyle/haxe-formatter/issues/274))
- Changed `sameLine.expressionCase` to `keep` [#250](https://github.com/HaxeCheckstyle/haxe-formatter/issues/250)
- Refactored call and parameter wrapping [#247](https://github.com/HaxeCheckstyle/haxe-formatter/issues/247)
- Refactored method chain wrapping [#247](https://github.com/HaxeCheckstyle/haxe-formatter/issues/247)
Expand Down
10 changes: 6 additions & 4 deletions src/formatter/marker/MarkSameLine.hx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class MarkSameLine extends MarkerBase {
switch (parent.tok) {
case Kwd(KwdReturn):
return true;
case Arrow:
return true;
case Kwd(KwdUntyped):
return isExpression(parent);
case Kwd(KwdFor), Kwd(KwdWhile):
Expand Down Expand Up @@ -83,8 +85,12 @@ class MarkSameLine extends MarkerBase {
while (parent.parent.tok != null) {
parent = parent.parent;
switch (parent.tok) {
case Binop(_):
return true;
case Kwd(KwdReturn):
return true;
case Arrow:
return true;
case Kwd(KwdFunction):
return false;
case POpen:
Expand All @@ -93,10 +99,6 @@ class MarkSameLine extends MarkerBase {
return true;
case BkOpen:
return false;
case Arrow:
return false;
case Binop(OpAssign):
return true;
case BrOpen:
var type:BrOpenType = TokenTreeCheckUtils.getBrOpenType(parent);
switch (type) {
Expand Down
26 changes: 26 additions & 0 deletions test/testcases/sameline/issue_271_arrow_switch.hxtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
}

---

class Main {
public static function main() {
var f = () -> switch (false) {
case true: 1;
case false: 0;
}
var f = () -> if (false) 1 else 0;
}
}

---

class Main {
public static function main() {
var f = () -> switch (false) {
case true: 1;
case false: 0;
}
var f = () -> if (false) 1 else 0;
}
}
26 changes: 26 additions & 0 deletions test/testcases/sameline/issue_272_binop_switch.hxtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
}

---

class Main {
public static function main() {
directionIndex += switch (instruction.turn) {
case Left: -1;
case Right: 1;
}
directionIndex += if (instruction.turn == Left) -1 else 1;
}
}

---

class Main {
public static function main() {
directionIndex += switch (instruction.turn) {
case Left: -1;
case Right: 1;
}
directionIndex += if (instruction.turn == Left) -1 else 1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{}


---


class Main {
public static function main() {
var f = (a:Int, b:Int) -> 0;
foo((a:Int, b:Int) -> 0);
}
}

---

class Main {
public static function main() {
var f = (a:Int, b:Int) -> 0;
foo((a:Int, b:Int) -> 0);
}
}

0 comments on commit 954b291

Please sign in to comment.