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

Proof-of-concept to allow initialisms to be set through flags. #89

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

cory-miller
Copy link

@cory-miller cory-miller commented Feb 20, 2025

Showcasing what I see in #90

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most relevant part of the change is here and the strcase.go file below.

Copy link
Owner

@cludden cludden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @cory-miller, this is great! Thanks for the submission, I like where this is going.

I have a few small changes/nits that I think would ago a long ways in improving the overall UX of this new plugin option:

  1. Rename InitialismsStrCase []string to IgnoreAcronyms []string and the ignore-strcase-initialisms to ignore-acronyms or even just Acronyms/acronyms and sort alphabetically for consistency with the other Config fields
  2. move the actual registration logic (i.e. strcase.ConfigureAcronym() out of toCamel/toLowerCamel and into the plugin's Run method
  3. remove the .idea directory and consider adding an entry to .gitignore
  4. bonus points for updating the docs and changelog

Let me know your thoughts!

Comment on lines 17 to 26

s := fmt.Sprintf(format, args...)

for _, initialism := range svc.cfg.InitialismsStrCase {
if strings.Contains(s, initialism) {
strcase.ConfigureAcronym(s, s)
}
}

return strcase.ToCamel(s)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of calling ConfigureAcronym everytime toCamel and toLowerCamel are called, consolidate and move this logic into the plugin's Run method

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So unfortunately I don't think strcase works in the way you'd expect. Instead of letting you mask particular parts of the input, you have to mask everything. It might be easier to illustrate with an example:

https://go.dev/play/p/8UUJHeOxQSo

Maybe that should be a bug on the strcase part. I'm not sure what the intended behavior is.

@cory-miller
Copy link
Author

@cludden I took care of 1, 3, and 4 from #89 (review) and left a comment in #89 (comment).

Another option I thought of - when calling out to the protogen library and the GoName field is provided back. I'm wondering why these are changed at all. I am not sure but think that for max compatibility you would want to make sure that the protogen output is not altered. Since the input to strcase is New%sClient and similar where the unformatted part comes from the protogen part, perhaps removing strcase is an option. I'm not sure the history on where this came in, or if strcase is used by this tool outside of the protogen parts.

@cory-miller cory-miller requested a review from cludden February 21, 2025 13:30
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.

2 participants