mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
Fix an extraneous newline in formatting
This commit is contained in:
parent
244a501433
commit
d1ba89f97f
1 changed files with 19 additions and 5 deletions
|
@ -699,15 +699,29 @@ fn fmt_when<'a, 'buf>(
|
|||
buf.push_str("is");
|
||||
buf.newline();
|
||||
|
||||
let mut it = branches.iter().peekable();
|
||||
while let Some(branch) = it.next() {
|
||||
let mut it = branches.iter().enumerate().peekable();
|
||||
|
||||
while let Some((branch_index, branch)) = it.next() {
|
||||
let expr = &branch.value;
|
||||
let patterns = &branch.patterns;
|
||||
let is_multiline_expr = expr.is_multiline();
|
||||
let is_multiline_patterns = is_when_patterns_multiline(branch);
|
||||
|
||||
for (index, pattern) in patterns.iter().enumerate() {
|
||||
if index != 0 {
|
||||
if index == 0 {
|
||||
match &pattern.value {
|
||||
Pattern::SpaceBefore(sub_pattern, spaces) if branch_index == 0 => {
|
||||
// Never include extra newlines before the first branch.
|
||||
// Instead, write the comments and that's it.
|
||||
fmt_comments_only(buf, spaces.iter(), NewlineAt::Bottom, indent + INDENT);
|
||||
|
||||
fmt_pattern(buf, sub_pattern, indent + INDENT, Parens::NotNeeded);
|
||||
}
|
||||
other => {
|
||||
fmt_pattern(buf, other, indent + INDENT, Parens::NotNeeded);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if is_multiline_patterns {
|
||||
buf.newline();
|
||||
// Indent an extra level for the `|`;
|
||||
|
@ -720,9 +734,9 @@ fn fmt_when<'a, 'buf>(
|
|||
}
|
||||
|
||||
buf.spaces(1);
|
||||
}
|
||||
|
||||
fmt_pattern(buf, &pattern.value, indent + INDENT, Parens::NotNeeded);
|
||||
fmt_pattern(buf, &pattern.value, indent + INDENT, Parens::NotNeeded);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(guard_expr) = &branch.guard {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue