Skip to content

Commit 1c9a8dd

Browse files
AndreasAAndreas Allacher
andauthored
Improves formatting for match cases. (#1994)
Fixes: #1964 Co-authored-by: Andreas Allacher <andreas.allacher@massiveart.com>
1 parent 6f4d27d commit 1c9a8dd

2 files changed

Lines changed: 42 additions & 10 deletions

File tree

src/printer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3047,8 +3047,8 @@ function printNode(path, options, print) {
30473047
const body = armPath.call(print, "body");
30483048
return concat(
30493049
armIdx > 0
3050-
? [", ", line, conds, " => ", body]
3051-
: [line, conds, " => ", body]
3050+
? [", ", hardline, conds, " => ", body]
3051+
: [hardline, conds, " => ", body]
30523052
);
30533053
}, "arms");
30543054
return group(

tests/match/__snapshots__/jsfmt.spec.js.snap

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,34 @@ $really_really_really_long_variable_name = match (getValue()) {
4949
default => throw new \\InvalidArgumentException("Unknown Value")
5050
};
5151
52-
$boolStr = match ($v) { true => "true", false => "false" };
52+
$boolStr = match ($v) {
53+
true => "true",
54+
false => "false"
55+
};
5356
5457
$boolish = match ($v) {
5558
true, 1 => true,
5659
false, 0, "", null => false,
5760
default => null
5861
};
5962
60-
$a = match (true) { test() => "Good", test2() => "Two", default => "fail" };
63+
$a = match (true) {
64+
test() => "Good",
65+
test2() => "Two",
66+
default => "fail"
67+
};
6168
62-
$nest = match (match ($a) { true => 1, false => 2 }) {
63-
1 => match ($b) { "ok" => true, "fail" => false, default => false },
69+
$nest = match (
70+
match ($a) {
71+
true => 1,
72+
false => 2
73+
}
74+
) {
75+
1 => match ($b) {
76+
"ok" => true,
77+
"fail" => false,
78+
default => false
79+
},
6480
2 => "null"
6581
};
6682
@@ -116,18 +132,34 @@ $really_really_really_long_variable_name = match (getValue()) {
116132
default => throw new \\InvalidArgumentException("Unknown Value"),
117133
};
118134
119-
$boolStr = match ($v) { true => "true", false => "false" };
135+
$boolStr = match ($v) {
136+
true => "true",
137+
false => "false",
138+
};
120139
121140
$boolish = match ($v) {
122141
true, 1 => true,
123142
false, 0, "", null => false,
124143
default => null,
125144
};
126145
127-
$a = match (true) { test() => "Good", test2() => "Two", default => "fail" };
146+
$a = match (true) {
147+
test() => "Good",
148+
test2() => "Two",
149+
default => "fail",
150+
};
128151
129-
$nest = match (match ($a) { true => 1, false => 2 }) {
130-
1 => match ($b) { "ok" => true, "fail" => false, default => false },
152+
$nest = match (
153+
match ($a) {
154+
true => 1,
155+
false => 2,
156+
}
157+
) {
158+
1 => match ($b) {
159+
"ok" => true,
160+
"fail" => false,
161+
default => false,
162+
},
131163
2 => "null",
132164
};
133165

0 commit comments

Comments
 (0)