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

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

Open
daluu opened this issue Jan 29, 2024 · 1 comment
Labels
Milestone

Comments

@daluu
Copy link

daluu commented Jan 29, 2024

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:

  • enhance the line comment logic to support optional delimiting of comment text into sections, with the text before (first) delimiter treated as the value to rename constant name to, and text after that (first) delimiter treated as comments and ignored for the purposes of stringer. Perhaps the delimiter value can also be specified here, with default being either a comma or semicolon. If enabled this delimiting feature, comments can then be both for renaming and other uses. If not enabling this enhanced feature, then stringer's line comment feature behaves as it does currently.

  • offer option of another flag to specify alternative naming than comments. Could we not use something like struct tags to label constants with alternative name for stringer? And if enabled with this flag, stringer parses the struct tags to get the alternate name, otherwise ignores the tags.

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

@daluu daluu added the Proposal label Jan 29, 2024
@gopherbot gopherbot added this to the Proposal milestone Jan 29, 2024
@ianlancetaylor
Copy link
Contributor

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

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

No branches or pull requests

3 participants