From 9e613585456f3d6843276bd2a7a89de1a41a45a3 Mon Sep 17 00:00:00 2001 From: 0daryo Date: Thu, 24 Oct 2024 21:11:52 +0900 Subject: [PATCH] Fix compare original and formatted --- format/format.go | 6 ++++-- format/format_test.go | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/format/format.go b/format/format.go index 01761ed3c..8886fd2de 100644 --- a/format/format.go +++ b/format/format.go @@ -93,15 +93,17 @@ func (f *Format) excludeFile(path string) bool { } func (f *Format) format(path string) error { - contents, err := os.ReadFile(path) + original, err := os.ReadFile(path) if err != nil { return err } + contents := make([]byte, len(original)) + copy(contents, original) formatted, err := f.formatter.Format(path, contents) if err != nil { return err } - if bytes.Equal(contents, formatted) { + if bytes.Equal(original, formatted) { // Skip write if no change return nil } diff --git a/format/format_test.go b/format/format_test.go index e73430367..35f625e49 100644 --- a/format/format_test.go +++ b/format/format_test.go @@ -122,8 +122,8 @@ var testFiles = map[string][]byte{ import "net/http" - // @Summary Add a new pet to the store - // @Description get string by ID + // @Summary Add a new pet to the store + // @Description get string by ID func GetStringByInt(w http.ResponseWriter, r *http.Request) { //write your code }`),