Skip to content

Commit

Permalink
fix deshaw#8: Do not remove last empty line.
Browse files Browse the repository at this point in the history
  • Loading branch information
randolf-scholz committed Aug 23, 2023
1 parent f1fc65d commit db16dbe
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit db16dbe

Please sign in to comment.