Skip to content

Commit

Permalink
fix: trialing new line
Browse files Browse the repository at this point in the history
Signed-off-by: tison <[email protected]>
  • Loading branch information
tisonkun committed Mar 23, 2024
1 parent ccf3b6a commit d4beded
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions fmt/src/document/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::{borrow::Cow, collections::HashMap, fs, fs::File, io::BufRead, path::PathBuf};
use std::{
borrow::Cow,
collections::HashMap,
fs::File,
io::{BufRead, Write},
path::PathBuf,
};

use snafu::ResultExt;

Expand Down Expand Up @@ -126,9 +132,16 @@ impl Document {

pub fn save(&mut self, filepath: Option<&PathBuf>) -> Result<()> {
let filepath = filepath.unwrap_or(&self.filepath);
fs::write(filepath, self.parser.file_content.content()).context(SaveDocumentSnafu {
let mut file = File::create(filepath).context(SaveDocumentSnafu {
path: filepath.display().to_string(),
})
})?;
let content = self.parser.file_content.content();
for line in content.lines() {
writeln!(file, "{line}").context(SaveDocumentSnafu {
path: filepath.display().to_string(),
})?;
}
Ok(())
}

pub(crate) fn merge_properties(&self, s: &str) -> String {
Expand Down

0 comments on commit d4beded

Please sign in to comment.