golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.99k stars 17.67k forks source link

proposal: x/tools/cmd/stringer: add -tag flag for constant name remapping, or improve line comment support #65354

Open daluu opened 9 months ago

daluu commented 9 months ago

Proposal Details

Per the current implementation & documentation for stringer, we have a way to rename/remap constant names when we return them as string via -linecomment flag. But I can see cases, where comments are used for other explanatory purposes, and I'm not sure how I see you can combine a comment to both be used to rename constants with stringer, as well as preserve the other uses of the comment. I don't see how stringer currently handles that in the code:

https://cs.opensource.google/go/x/tools/+/refs/tags/v0.17.0:cmd/stringer/stringer.go;l=465

This is what I propose with 2 options to enhance the constant naming feature:

If there is already such functionality that I overlooked, please enlighten me.

ianlancetaylor commented 9 months ago

Can you give a couple of small examples? I don't understand the description.