Merge pull request #7536 from joshuawarner32/remove-indented-else

Remove indented-else syntax from the formatter
This commit is contained in:
Luke Boswell 2025-01-21 18:02:05 +11:00 committed by GitHub
commit 5b4c8e70d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 121 additions and 50 deletions

View file

@ -0,0 +1,72 @@
@1-24 SpaceAfter(
Defs(
Defs {
tags: [
EitherIndex(2147483648),
],
regions: [
@1-22,
],
space_before: [
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
],
space_after: [
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
],
spaces: [],
type_defs: [],
value_defs: [
Stmt(
@1-22 If {
if_thens: [
(
@3-6 UnaryOp(
@4-6 Var {
module_name: "",
ident: "a!",
},
@3-4 Not,
),
@11-12 SpaceBefore(
SpaceAfter(
Var {
module_name: "",
ident: "t",
},
[
Newline,
],
),
[
Newline,
],
),
),
],
final_else: @21-22 SpaceBefore(
Var {
module_name: "",
ident: "l",
},
[
Newline,
],
),
indented_else: true,
},
),
],
},
@23-24 SpaceBefore(
Num(
"5",
),
[
Newline,
],
),
),
[
Newline,
],
)

View file

@ -0,0 +1,5 @@
if!a!then
t
else
l
5

View file

@ -2,7 +2,6 @@ if
k
then
A
else
e
r
else
e
r

View file

@ -3061,7 +3061,7 @@ mod test_fmt {
x,
y
}| a
identity 43
"
),
@ -3069,7 +3069,7 @@ mod test_fmt {
r"
identity =
|{ x, y }| a
identity 43
"
),
@ -3083,7 +3083,7 @@ mod test_fmt {
x,
y
} -> a
identity 43
"
),
@ -3091,7 +3091,7 @@ mod test_fmt {
r"
identity =
|{ x, y }| a
identity 43
"
),
@ -3996,15 +3996,25 @@ mod test_fmt {
#[test]
fn early_return_else() {
expr_formats_same(indoc!(
r"
if foo then
bar
else
expr_formats_to(
indoc!(
r"
if foo then
bar
else
baz
"
));
baz
"
),
indoc!(
r"
if foo then
bar
else
baz
"
),
);
expr_formats_to(
indoc!(
@ -4019,9 +4029,8 @@ mod test_fmt {
r"
if thing then
whatever
else
too close
else
too close
"
),
);
@ -4031,8 +4040,7 @@ mod test_fmt {
r"
if isGrowing plant then
LetBe
else
else
Water
"
),
@ -4040,9 +4048,8 @@ mod test_fmt {
r"
if isGrowing plant then
LetBe
else
Water
else
Water
"
),
);

View file

@ -472,6 +472,7 @@ mod test_snapshots {
pass/highest_float.expr,
pass/highest_int.expr,
pass/i_over_not_g.expr,
pass/if_bang_then_bang_indented_else.expr,
pass/if_bang_then_else_one_line.expr,
pass/if_def.expr,
pass/if_newline_then_negate_else_recordupdater.expr,