Skip to content

Commit 18f90e4

Browse files
fix(fmt): match branch enum extra newline (FuelLabs#4084)
## Description Closes FuelLabs#3131 Simple check to see if we already end with a newline - if we do, don't write one. We could probably have a helper fn that condenses this into one line to make the `Format` impls take up less vertical space. ## Checklist - [x] I have linked to any relevant issues. - [ ] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [ ] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [ ] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [ ] I have requested a review from the relevant team or maintainers. Co-authored-by: Joshua Batty <[email protected]>
1 parent ada81db commit 18f90e4

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

swayfmt/src/utils/language/expr/tests.rs

+36
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,42 @@ fmt_test!( match_branch_kind
237237
quux();\n }\n\n\n}"
238238
);
239239

240+
fmt_test!( match_branch_kind_tuple_long
241+
"match (foo, bar) {
242+
(
243+
VeryLongFoo::SomeLongFoo(some_foo),
244+
VeryLongBar::SomeLongBar(some_bar),
245+
) => {
246+
foo();
247+
}
248+
(
249+
VeryLongFoo::OtherLongFoo(other_foo),
250+
VeryLongBar::OtherLongBar(other_bar),
251+
) => {
252+
bar();
253+
}
254+
_ => {
255+
revert(0)
256+
}
257+
}",
258+
intermediate_whitespace
259+
"match (foo, bar) {
260+
(
261+
VeryLongFoo::SomeLongFoo(some_foo), \n \n VeryLongBar::SomeLongBar(some_bar)) => \n
262+
\n{
263+
\n
264+
foo();
265+
}
266+
(VeryLongFoo::OtherLongFoo(other_foo), VeryLongBar::OtherLongBar(other_bar) \n ) => {
267+
bar();
268+
\n
269+
}
270+
_ \n=> {
271+
\n revert(0)
272+
}
273+
}"
274+
);
275+
240276
fmt_test!( basic_array "[1, 2, 3, 4, 5]",
241277
intermediate_whitespace " \n [ 1 , 2 , 3 , 4 , 5 ] \n"
242278
);

swayfmt/src/utils/language/punctuated.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ where
5454
write!(formatted_code, " ")?;
5555
}
5656
LineStyle::Multiline => {
57-
writeln!(formatted_code)?;
57+
if !formatted_code.ends_with('\n') {
58+
writeln!(formatted_code)?;
59+
}
5860
let value_pairs_iter = self.value_separator_pairs.iter();
5961
for (type_field, comma_token) in value_pairs_iter.clone() {
6062
write!(

0 commit comments

Comments
 (0)