Fix formatter adding extra unnecessary newlines after literal lists clause values or assignments.

This commit is contained in:
KtorZ
2024-09-15 14:40:40 +02:00
parent d6c728c0f6
commit 12c0d0bc04
5 changed files with 9 additions and 8 deletions

View File

@@ -1889,9 +1889,7 @@ impl<'comments> Formatter<'comments> {
.force_break(),
),
UntypedExpr::Fn { .. } | UntypedExpr::List { .. } => {
line().append(self.expr(expr, false)).nest(INDENT).group()
}
UntypedExpr::Fn { .. } => line().append(self.expr(expr, false)).nest(INDENT).group(),
UntypedExpr::When { .. } => line().append(self.expr(expr, false)).nest(INDENT).group(),
@@ -1976,6 +1974,7 @@ impl<'comments> Formatter<'comments> {
} else {
|| break_(",", ", ")
};
let elements_document =
join(elements.iter().map(|e| self.pattern(e)), break_style());
let tail = tail.as_ref().map(|e| {

View File

@@ -298,6 +298,7 @@ fn format_nested_when_if() {
when xs is {
[] ->
[]
[x] -> [1, 2, 3]
[_x, ..rest] ->
drop(rest, n - 1)
}

View File

@@ -3,8 +3,7 @@ source: crates/aiken-lang/src/tests/format.rs
description: "Code:\n\ntest foo() {\n let left =\n [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n let right =\n [\n 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n 0, 0, 0, 0,\n ]\n left == right\n}\n"
---
test foo() {
let left =
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
let left = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
let right =
[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

View File

@@ -1,14 +1,14 @@
---
source: crates/aiken-lang/src/tests/format.rs
description: "Code:\n\npub fn drop(xs: List<a>, n: Int) -> List<a> {\n if n <= 0 {\n xs\n } else {\n when xs is {\n [] ->\n []\n [_x, ..rest] ->\n drop(rest, n - 1)\n }\n }\n}\n"
description: "Code:\n\npub fn drop(xs: List<a>, n: Int) -> List<a> {\n if n <= 0 {\n xs\n } else {\n when xs is {\n [] ->\n []\n [x] -> [1, 2, 3]\n [_x, ..rest] ->\n drop(rest, n - 1)\n }\n }\n}\n"
---
pub fn drop(xs: List<a>, n: Int) -> List<a> {
if n <= 0 {
xs
} else {
when xs is {
[] ->
[]
[] -> []
[x] -> [1, 2, 3]
[_x, ..rest] -> drop(rest, n - 1)
}
}