-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
cmd/vet: reject flag.Parse during func init #33190
Comments
A vet check would be very helpful, if it’s accomplishable, as the current output is confusing and misleading. Example:
I'm honestly a bit shocked that such a change went through. This (IMHO) is worse than the original problem being fixed. |
Due to a recent change in go1.13 (golang/go#21051), parsing of flags inside `init` functions causes tests to fail. This change moves `flag.Parse` inside `main.main`. For more information see golang/go#33190
Due to a recent change in go1.13 (golang/go#21051), parsing of flags inside `init` functions causes tests to fail. This change moves `flag.Parse` inside `main.main`. For more information see golang/go#33190
I can work on this |
Change https://golang.org/cl/218757 mentions this issue: |
Reviving this issue: the suggested fix would be very useful IMO (I was going to open an identical issue) Additionally, the documentation of
When following this guidance, calling |
In #31859, @cespare suggested rejecting flag.Parse during func init, which is always incorrect (other packages not yet initialized may want to define flags).
We could add a special runtime hook of some kind to allow flag to see whether main.main has started, but that would be unfortunate.
There also may be lots of code in the wild that does parse flags during init and kind of works out OK, and if it's working well enough we don't want to break it unnecessarily.
A vet check, on by default during go test, seems like the perfect compromise to me.
The text was updated successfully, but these errors were encountered: