Skip to content

Commit

Permalink
Merge pull request #96 from djacu/djacu/only-write-on-change
Browse files Browse the repository at this point in the history
Only write files on change.
  • Loading branch information
andrewbaxter authored Dec 15, 2024
2 parents 41db645 + 6af765f commit 3c58f09
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions crates/genemichaels/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ impl FormatPool {

fn process_file(&mut self, file: PathBuf) {
let log = self.log.fork(ea!(file = file.to_string_lossy()));
log.log_with(loga::INFO, "Formatting file", ea!());
log.log_with(loga::INFO, "Processing file", ea!());
let config = self.config.clone();

Check warning on line 341 in crates/genemichaels/src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

using `clone` on type `FormatConfig` which implements the `Copy` trait

warning: using `clone` on type `FormatConfig` which implements the `Copy` trait --> crates/genemichaels/src/main.rs:341:22 | 341 | let config = self.config.clone(); | ^^^^^^^^^^^^^^^^^^^ help: try removing the `clone` call: `self.config` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy = note: `#[warn(clippy::clone_on_copy)]` on by default
let errors = self.errors.clone();
self.pool.execute(move || {
Expand All @@ -348,10 +348,11 @@ impl FormatPool {
log.log_with(loga::INFO, "Skipping due to skip comment", ea!());
return Ok(());
}
fs::write(
&file,
process_file_contents(log, &config, &source).context("Error doing formatting")?.as_bytes(),
).context("Error writing formatted code back")?;
let processed = process_file_contents(log, &config, &source).context("Error doing formatting")?;
if source != processed {
log.log_with(loga::INFO, "Writing newly formatted file", ea!());
fs::write(&file, processed.as_bytes()).context("Error writing formatted code back")?;
}
return Ok(());
}).stack_context(log, "Error formatting file");
match res {
Expand Down

0 comments on commit 3c58f09

Please sign in to comment.