Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compare original and formatted #1915

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions format/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

@0daryo 0daryo Oct 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only space between // and @ should be formatted.
Before my fix. Test fails.

% go test -run TestFormat_Format -v                                                                                                                                     
=== RUN   TestFormat_Format
    format_test.go:16: 
                Error Trace:    format_test.go:16
                Error:          Should be true
                Test:           TestFormat_Format
--- FAIL: TestFormat_Format (0.00s)
FAIL
exit status 1

func GetStringByInt(w http.ResponseWriter, r *http.Request) {
//write your code
}`),
Expand Down
Loading