buf
buf copied to clipboard
field name contains a number
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?
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?
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.