Merge pull request #470 from alixander/fmt-save

only write fmt if changed
This commit is contained in:
Alexander Wang 2022-12-19 13:26:13 -08:00 committed by GitHub
commit c912cae80a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View file

@ -3,3 +3,5 @@
#### Improvements 🧹
#### Bugfixes ⛑️
- `d2 fmt` only rewrites if it has changes, instead of always rewriting. [#470](https://github.com/terrastruct/d2/pull/470)

7
fmt.go
View file

@ -33,5 +33,10 @@ func fmtCmd(ctx context.Context, ms *xmain.State) (err error) {
return err
}
return ms.WritePath(inputPath, []byte(d2format.Format(m)))
output := []byte(d2format.Format(m))
if !bytes.Equal(output, input) {
return ms.WritePath(inputPath, output)
}
return nil
}