From cfb096c4a48c14c3b49e9f2c419170572e627894 Mon Sep 17 00:00:00 2001 From: Kevin Amado Date: Thu, 10 Feb 2022 18:04:25 -0500 Subject: [PATCH] feat: write if changed --- src/format.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/format.rs b/src/format.rs index 18f9994..77103c8 100644 --- a/src/format.rs +++ b/src/format.rs @@ -28,9 +28,15 @@ pub fn file( use std::io::Write; let input = std::fs::read_to_string(&path)?; - let output = crate::format::string(config, path.clone(), input); + let input_clone = input.clone(); + let input_bytes = input_clone.as_bytes(); - std::fs::File::create(path)?.write_all(output.as_bytes())?; + let output = crate::format::string(config, path.clone(), input); + let output_bytes = output.as_bytes(); + + if input_bytes != output_bytes { + std::fs::File::create(path)?.write_all(output_bytes)?; + } Ok(()) }