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

field name contains a number #2868

Closed
zdevwu opened this issue Apr 4, 2024 · 2 comments
Closed

field name contains a number #2868

zdevwu opened this issue Apr 4, 2024 · 2 comments

Comments

@zdevwu
Copy link

zdevwu commented Apr 4, 2024

Hi,

I don't see the rule for field name contains a number being enforce when using the DEFAULT lint configuration. The rule is mentioned in https://protobuf.dev/programming-guides/style/

If your field name contains a number, the number should appear after the letter instead of after the underscore. For example, use song_name1 instead of song_name_1

When field name like song_name_1 or song_1_name is used, there is no obvious problem when generating javascript and java code, but it is strange that only golang decides to keep the underscore. So the golang code looks like:

if msg.GetSongName_1() == "new song" {
  ...
}
if msg.GetSong_1Name() == "new song" {
  ...
}

I can't find an option to turn on the linter to spot the problem, is there any?

@zdevwu
Copy link
Author

zdevwu commented Apr 5, 2024

I noticed the commend in here:

	// We allow both effectively by not passing the option
	//return stringutil.ToLowerSnakeCase(s, stringutil.SnakeCaseWithNewWordOnDigits())

would an option be introduced to enforce the rule defined in the style guide?

@bufdev
Copy link
Member

bufdev commented May 18, 2024

Thanks for the feedback. We don't want to modify our field name rules for something this minor, as modifying them would be a breaking change for our users. Adding a new rule just for this seems a bit out of scope. We are working on custom lint plugins for the buf CLI, however, and this may be a good candidate for a custom lint plugin if you'd like to enforce that down the road. Stay tuned.

Note that buf doesn't necessarily follow Google's style guide - see https://buf.build/docs/best-practices/style-guide for our recommendations.

@bufdev bufdev closed this as completed May 18, 2024
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

No branches or pull requests

2 participants