Skip to content

Commit

Permalink
Add EOL at EOF for JSON files (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvdb authored Apr 4, 2024
1 parent 6c91c95 commit d7d7a62
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
4 changes: 3 additions & 1 deletion butane_cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ impl CliState {
pub fn save(&self, base_dir: &Path) -> Result<()> {
let path = base_dir.join("clistate.json");
let mut file = File::create(path)?;
file.write_all(serde_json::to_string_pretty(self)?.as_bytes())?;
let mut contents = serde_json::to_string_pretty(self)?;
contents.push('\n');
file.write_all(contents.as_bytes())?;
Ok(())
}
}
Expand Down
5 changes: 3 additions & 2 deletions butane_core/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ impl ConnectionSpec {
pub fn save(&self, path: &Path) -> Result<()> {
let path = conn_complete_if_dir(path);
let mut f = fs::File::create(path)?;
f.write_all(serde_json::to_string_pretty(self)?.as_bytes())
.map_err(|e| e.into())
let mut contents = serde_json::to_string_pretty(self)?;
contents.push('\n');
f.write_all(contents.as_bytes()).map_err(|e| e.into())
}
/// Load a previously saved connection spec
pub fn load(path: impl AsRef<Path>) -> Result<Self> {
Expand Down
9 changes: 6 additions & 3 deletions butane_core/src/migrations/fsmigrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ impl FsMigration {
}

fn write_info(&self, info: &MigrationInfo) -> Result<()> {
self.write_contents("info.json", serde_json::to_string_pretty(info)?.as_bytes())
let mut contents = serde_json::to_string_pretty(info)?;
contents.push('\n');
self.write_contents("info.json", contents.as_bytes())
}

fn write_sql(&self, name: &str, sql: &str) -> Result<()> {
Expand Down Expand Up @@ -380,8 +382,9 @@ impl FsMigrations {
}
let path = self.root.join("state.json");
let mut f = self.fs.write(&path)?;
f.write_all(serde_json::to_string_pretty(state)?.as_bytes())
.map_err(|e| e.into())
let mut contents = serde_json::to_string_pretty(state)?;
contents.push('\n');
f.write_all(contents.as_bytes()).map_err(|e| e.into())
}
/// Detach the latest migration from the list of migrations,
/// leaving the migration on the filesystem.
Expand Down
2 changes: 1 addition & 1 deletion examples/getting_started/.butane/clistate.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"embedded": true
"embedded": true
}

0 comments on commit d7d7a62

Please sign in to comment.