shurcooL / vfsgen

Takes an input http.FileSystem (likely at go generate time) and generates Go code that statically implements it.
MIT License
981 stars 83 forks source link

Generated code seems to be different style than `go fmt` wants #57

Closed DavidJFelix closed 6 years ago

DavidJFelix commented 6 years ago

Information

I'm not actually sure what rules go fmt is using to handle column alignment, but it seems like it has a limit to how much the two lines it tries to match are differing. When I run go fmt it modifies generated code to fit the go standard style.

Using:

go version 
go1.10.3 darwin/amd64`

Expected

go generate will generate code that go fmt does not attempt to change.

Actual

go generate creates this line

        return &vfsgen۰CompressedFile{
            vfsgen۰CompressedFileInfo: f,
            gr:                        gr,
        }, nil{{end}}{{if .HasFile}}

which go fmt will change to:

        return &vfsgen۰CompressedFile{
            vfsgen۰CompressedFileInfo: f,
            gr: gr,
        }, nil

Reproduce

Run go fmt on code generated by vfsgen.

dmitshur commented 6 years ago

Hi @DavidJFelix, thanks for reporting.

This is expected behavior. The reason you're seeing a difference is because you're using gofmt from Go 1.10. There have been changes to gofmt formatting behavior from Go 1.10 to Go 1.11, and the current version of vfsgen aims to generate code compatible with gofmt from Go 1.11 (the current release).

If you use gofmt from Go 1.11, there should not be any formatting issues with the generated code.

See commit message of commit 02ddb050ef6bbe4c2900677ac0df7e9e336d7032 for more details.

DavidJFelix commented 6 years ago

yep. I see it now. I upgraded to 11 and it goes away. Also saw an issue in go's code about different gofmt versions outputting different values with the issue marked "Unfortunate" 🤣 I'll close this. Thanks for the fast response.