From db16dbe34763238a55b6c5fd017dabb06a708aa1 Mon Sep 17 00:00:00 2001 From: Randolf Scholz Date: Wed, 23 Aug 2023 16:41:37 +0200 Subject: [PATCH] fix #8: Do not remove last empty line. --- src/main.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main.rs b/src/main.rs index 93c4bc4..bdf33b4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -161,6 +161,11 @@ fn process_file( })?; let cleaned_contents = String::from_utf8(ser.into_inner()).map_err(|e| format!("{:?}", e))?; + // Check if the original content ended with a newline and the cleaned content doesn't + if contents.ends_with('\n') && !cleaned_contents.ends_with('\n') { + cleaned_contents.push('\n'); // Append a newline if necessary + } + if cleaned_contents != *contents { if let Some(file) = output_file { fs::write(&file, cleaned_contents)