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

generator: use go/format to format the output pre-writing to a file #46

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

myitcv
Copy link

@myitcv myitcv commented Aug 1, 2018

Ensures output is automatically formatted correctly, according to the version of Go being used (because this ends up being called via go run)

@dmitshur
Copy link
Member

dmitshur commented Aug 2, 2018

Thanks for the PR. (Please ignore the CI failure, it happens due to a current Travis CI issue.) Let's discuss the design first.

Some important background information on why a call to format.Source wasn't already present. That was a conscious design decision. This generator has been deliberately designed such that it should not be necessary to run format.Source on the final output, because it generates Go code that is already gofmt-compatible.

There are tests that ensure this is so, see here.

This behavior breaks in the upcoming Go 1.11 release because of gofmt changes, which I'm guessing is what you ran into, prompting this PR.

My current plan to resolve it is by updating the output format to be compatible with gofmt of Go 1.11 when that version comes out. See the go1.11 branch which implements it. I am also considering an alternative fix of adding a blank line separating the vfsgen۰CompressedFileInfo: f, and gr: gr, lines. It has the advantage of being gofmt-compatible with both Go 1.11 and 1.10, but the disadvantage of being suboptimal code style.

Ideally, I'd like to resolve the underlying issue without having to use go/format as long as it's viable, and I believe that's the case. Let me know what you think.

@myitcv
Copy link
Author

myitcv commented Aug 5, 2018

Thanks for the background.

Ideally, I'd like to resolve the underlying issue without having to use go/format as long as it's viable, and I believe that's the case. Let me know what you think.

Is there a reason you don't want to use go/format? Is it performance related?

@dmitshur
Copy link
Member

dmitshur commented Aug 7, 2018

If the output is already gofmted, running format.Source on it is a no-op.

@myitcv
Copy link
Author

myitcv commented Aug 7, 2018

Yes, but that's after the effect of having got to that point by hand (and written/maintained tests). Then there's the slight wrinkle of well-formatted code slightly changing between versions, i.e. the issue behind this PR.

It just feels to me like the benefit of using go/format (you don't need to think/do too much with the output) outweighs the cost (the marginal additional runtime, particularly in the context of the fact we use go run here).

But I can see it's not clear cut one way or the other.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants