Skip to content

Commit f32a9a7

Browse files
committed
Add a newline to the generated JSON files
This adds a newline at the end of all cached ./.sqlx/... JSON files so that anyone who has "auto-newline" enabled in their IDE would not accidentally add it to the cached file. This also ensures that GitHub diff would not show an alarming red icon next to the end of the checked in sqlx files.
1 parent 0c8fe72 commit f32a9a7

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

sqlx-macros-core/src/query/data.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::collections::HashMap;
22
use std::fmt::{Debug, Display, Formatter};
33
use std::fs;
4+
use std::io::Write;
45
use std::marker::PhantomData;
56
use std::path::{Path, PathBuf};
67
use std::sync::Mutex;
@@ -161,8 +162,13 @@ where
161162
// with persisting the file across filesystems.
162163
let mut tmp_file = tempfile::NamedTempFile::new_in(tmp_dir)
163164
.map_err(|err| format!("failed to create query file: {:?}", err))?;
165+
164166
serde_json::to_writer_pretty(tmp_file.as_file_mut(), self)
165167
.map_err(|err| format!("failed to serialize query data to file: {:?}", err))?;
168+
// Ensure there is a newline at the end of the JSON file to avoid accidental modification by IDE
169+
// and make github diff tool happier
170+
tmp_file.as_file_mut().write_all(b"\n")
171+
.map_err(|err| format!("failed to append a newline to file: {:?}", err))?;
166172

167173
tmp_file
168174
.persist(dir.as_ref().join(format!("query-{}.json", self.hash)))

0 commit comments

Comments
 (0)