protolint icon indicating copy to clipboard operation
protolint copied to clipboard

ENUM_FIELD_NAMES_ZERO_VALUE_END_WITH rule should not run on Enums if Go project

Open Dentrax opened this issue 3 years ago • 3 comments
trafficstars

By default, Go does not have enum so protoc generates an iota for enums. So we have to end the first item with zero value. This rule throws false-positive:

// protolint:disable ENUM_FIELD_NAMES_ZERO_VALUE_END_WITH
enum Result {
  FOO = 0;
  BAR = 1;
}

protolint version 0.38.2(66f8921)

What do you think?

Dentrax avatar Jul 06 '22 07:07 Dentrax

@Dentrax Thank you for reaching out.

ENUM_FIELD_NAMES_ZERO_VALUE_END_WITH conforms to the style guide.

  • The zero value enum should have the suffix UNSPECIFIED.

protoc generates an iota for enums

Go Reference says that protoc generates the constants without using iota.

I'm not sure what problems you have with the following code in Go project.

const (
        Result_UNSPECIFIED Result = 0
        Result_FOO Result = 1
        Result_BAR   Result = 2
)

Or

const (
        Result_RESULT_UNSPECIFIED Result = 0
        Result_RESULT_FOO Result = 1
        Result_RESULT_BAR   Result = 2
)

yoheimuta avatar Jul 10 '22 11:07 yoheimuta

Oh, thanks for clarification and references! I also want to ask I think Go does not recommend UPPER_SNAKE_CASE since it mostly wants camelCase or PascalCase in variable declaration. (whereas its ok for Java, not sure about Python since it gets angry when not use lower_snake_case) Do you have any thoughts on this?

Dentrax avatar Jul 10 '22 11:07 Dentrax

@Dentrax I have no particular thought on the rule's rationality as long as Google and its broad community define it.

In my understanding, proto files' specification is based on a language agnostic policy. The naming convention for specific languages should be resolved by a compiler and its plugins.

The community has already discussed this topic, so I suggest you check out the link below first.

  • ref. https://github.com/golang/protobuf/issues/555#issuecomment-895474274

yoheimuta avatar Jul 14 '22 03:07 yoheimuta