-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: cmd/go: introduce go.gen file for //go:generate comments #33375
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
Comments
If your goal is to make the comments easier to find, why not a cmd/go arg to list all such comments? Also how is this better than just putting all your generate comments into a single file called |
A simple grep search viz., |
Or we could encourage a convention of putting them in a file named gen.go. I'm not seeing a reason for go.gen. |
That would definitely help, but still doesn't invalidate my proposal.
That doesn't help if you're on Windows where @AlexRouSg @ianlancetaylor Yep, if I think I still see value on |
|
Note that if we change the convention, we can't get rid of the old one. We'll just have two conventions. That's typically not an improvement. There is value in having all the go:generate lines in one place, and there is also value in having all the go:generate lines next to the things they are related to (like putting go:generate stringer lines next to the type they generate a String method for). Enforcing one is probably not right. If you want to use a gen.go, great. We probably shouldn't force everyone, and we can't change all the existing usage even if we wanted to. I don't see how we can adopt this proposal at this point. Am I missing something? |
@andreynering You can list commands with |
Based on #33375 (comment), it sounds like this is a likely decline (adds a second way to do something without being able to remove the first one; increased complexity). The only comment since then, by @andreynering, was answered by @sapk. (Also, in all seriousness, one of the first things I do on a Windows box is find a way to install a grep implementation.) Leaving open for a week for final comments. |
Marked this last week as likely decline w/ call for last comments (#33375 (comment)). |
The problem with
//go:generate
comments is that they are too "hidden" in the source code. You have to search the whole project for these comments in order to know what will happen when you rungo generate ./...
.This kind of thing should be centralized and easy to find. I propose that
go generate
should also run commands available on ago.gen
file (this name is to follow the current convention ofgo.mod
andgo.sum
). This file would look like this:(Examples extracted from the official go generate blog post). Each line is a separated command, there's no special syntax there.
//go:generate
comments should keep working, this is just an alternative way to define commands.The text was updated successfully, but these errors were encountered: