From e2bd90bd6b9fe074cd1ba8d836f550bf0720f09b Mon Sep 17 00:00:00 2001 From: Brett Mayson Date: Sat, 9 Nov 2024 01:29:21 +0000 Subject: [PATCH] stringtables: add trailing newline, trim for comparisions --- libs/stringtable/src/analyze/lints/01_sorted.rs | 2 +- libs/stringtable/src/lib.rs | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/libs/stringtable/src/analyze/lints/01_sorted.rs b/libs/stringtable/src/analyze/lints/01_sorted.rs index eb94eac1..64ed08f7 100644 --- a/libs/stringtable/src/analyze/lints/01_sorted.rs +++ b/libs/stringtable/src/analyze/lints/01_sorted.rs @@ -58,7 +58,7 @@ impl LintRunner for Runner { if let Err(e) = project.to_writer(&mut writer) { panic!("Failed to write stringtable for {path}: {e}"); } - if &writer != existing { + if writer.trim() != existing.trim() { unsorted.push(path.as_str().to_string()); } } diff --git a/libs/stringtable/src/lib.rs b/libs/stringtable/src/lib.rs index e10f0d1a..020179cb 100644 --- a/libs/stringtable/src/lib.rs +++ b/libs/stringtable/src/lib.rs @@ -55,8 +55,12 @@ impl Project { // If this write fails, the serializer will also throw an error let _ = writer.write_str(r#""#); let _ = writer.write_char('\n'); - let mut ser = Serializer::new(writer); + let mut buffer = String::new(); + let mut ser = Serializer::new(&mut buffer); ser.indent(' ', 4); - self.serialize(ser) + self.serialize(ser)?; + buffer.push('\n'); + writer.write_str(&buffer)?; + Ok(()) } }