1
Fork 0
mirror of https://github.com/RGBCube/alejandra synced 2025-07-31 12:37:45 +00:00

feat: write if changed

This commit is contained in:
Kevin Amado 2022-02-10 18:04:25 -05:00
parent 0c095ed50d
commit cfb096c4a4
No known key found for this signature in database
GPG key ID: FFF341057F503148

View file

@ -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(())
}