Allow newlines in when clause sequences.

This commit is contained in:
KtorZ 2023-03-30 13:49:00 +02:00
parent 5d4c95d538
commit 6a4f62d074
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
2 changed files with 14 additions and 7 deletions

View File

@ -1458,7 +1458,6 @@ impl<'comments> Formatter<'comments> {
fn clause<'a>(&mut self, clause: &'a UntypedClause, index: u32) -> Document<'a> {
let space_before = self.pop_empty_lines(clause.location.start);
let after_position = clause.location.end;
let clause_doc = join(
clause.patterns.iter().map(|p| self.pattern(p)),
" | ".to_doc(),
@ -1468,9 +1467,6 @@ impl<'comments> Formatter<'comments> {
Some(guard) => clause_doc.append(" if ").append(self.clause_guard(guard)),
};
// Remove any unused empty lines within the clause
self.pop_empty_lines(after_position);
if index == 0 {
clause_doc
} else if space_before {

View File

@ -133,17 +133,28 @@ fn test_format_when() {
let src = indoc! {r#"
pub fn foo( a) {
when a is{
True -> 14
True -> {
bar()
14
}
False ->
42}
42
}
}
"#};
let expected = indoc! {r#"
pub fn foo(a) {
when a is {
True ->
True -> {
bar()
14
}
False ->
42
}