diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index f3c0d2a77..55bafe4af 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -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) diff --git a/fmt.go b/fmt.go index e3a755a79..58a4f671b 100644 --- a/fmt.go +++ b/fmt.go @@ -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 }