Skip to content

Commit

Permalink
fix: fix manifest formatter in forc fmt (#686)
Browse files Browse the repository at this point in the history
* fix: format Forc.toml manifests with `forc fmt`

- Fixes an incorrect if/else branching

* style: use `forc fmt` on Forc.toml manifests

* Revert "style: use `forc fmt` on Forc.toml manifests"

This reverts commit 7d78e60.
This is because the PR#683 would create a lot of merge conflicts with
this PR.

* fix: address PR comments
  • Loading branch information
iqdecay authored Jan 23, 2022
1 parent cafa9f0 commit d8dfc61
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions forc/src/ops/forc_fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ fn format_after_build(command: FormatCommand) -> Result<(), FormatError> {
Ok((_, formatted_content)) => {
if command.check {
if *file_content != *formatted_content {
if !contains_edits {
contains_edits = true;
}
contains_edits = true;
println!("\n{:?}\n", file);
display_file_diff(&file_content, &formatted_content)?;
}
Expand All @@ -66,24 +64,21 @@ fn format_after_build(command: FormatCommand) -> Result<(), FormatError> {
}
}
}

// format manifest using taplo formatter
if let Ok(file_content) = fs::read_to_string(&manifest_file) {
let taplo_alphabetize = taplo_fmt::Options {
reorder_keys: true,
..Default::default()
};
let formatted_content = taplo_fmt::format(&file_content, taplo_alphabetize);
if command.check {
if formatted_content != file_content {
if !contains_edits {
contains_edits = true;
}
eprintln!("\nManifest Forc.toml improperly formatted");
display_file_diff(&file_content, &formatted_content)?;
} else {
format_file(&manifest_file, &formatted_content)?;
}
if !command.check {
format_file(&manifest_file, &formatted_content)?;
} else if formatted_content != file_content {
contains_edits = true;
eprintln!("\nManifest Forc.toml improperly formatted");
display_file_diff(&file_content, &formatted_content)?;
} else {
println!("\nManifest Forc.toml properly formatted")
}
}

Expand Down

0 comments on commit d8dfc61

Please # to comment.