git.delta.rocks / jrsonnet / refs/commits / 45b6682ad4a7

difftreelog

fix(fmt) multiline comment whitespace handling

Yaroslav Bolyukin2024-01-16parent: #e7b9349.patch.diff
in: master

2 files changed

modifiedcmds/jrsonnet-fmt/src/comments.rsdiffbeforeafterboth
72 if matches!(loc, CommentLocation::ItemInline) {72 if matches!(loc, CommentLocation::ItemInline) {
73 p!(pi: str(" "));73 p!(pi: str(" "));
74 }74 }
75 p!(pi: str("/* ") string(lines[0].trim().to_string()) str(" */"))75 p!(pi: str("/* ") string(lines[0].trim().to_string()) str(" */") nl)
76 } else if !lines.is_empty() {76 } else if !lines.is_empty() {
77 fn common_ws_prefix<'a>(a: &'a str, b: &str) -> &'a str {77 fn common_ws_prefix<'a>(a: &'a str, b: &str) -> &'a str {
78 let offset = a78 let offset = a
modifiedcmds/jrsonnet-fmt/src/main.rsdiffbeforeafterboth
--- a/cmds/jrsonnet-fmt/src/main.rs
+++ b/cmds/jrsonnet-fmt/src/main.rs
@@ -372,8 +372,8 @@
 					return p!(new: str("{ }"));
 				}
 				let mut pi = p!(new: str("{") >i nl);
-				for mem in children.into_iter() {
-					if mem.should_start_with_newline {
+				for (i, mem) in children.into_iter().enumerate() {
+					if mem.should_start_with_newline && i != 0 {
 						p!(pi: nl);
 					}
 					p!(pi: items(format_comments(&mem.before_trivia, CommentLocation::AboveItem)));