yoheimuta / protolint

A pluggable linter and fixer to enforce Protocol Buffer style and conventions.
MIT License
551 stars 50 forks source link

Rule for first value of enum should have numeric value zero? #423

Open jordanbbaker opened 1 month ago

jordanbbaker commented 1 month ago

Did I miss this ? Did not see it in the list of rules but I came away from the protobuf.dev best practices guides thinking that is is important.

Do I need to create a custom rule for this?

yoheimuta commented 1 month ago

@jordanbbaker protolint doesn't have the rule for first value of enum should have numeric value zero.

I understand that proto enums require the first value to be zero, and so the following file cannot be compiled.

syntax = "proto3";
package examplePb;

enum enumAllowingAlias {
    UNKNOWN = 1;
    STARTED = 2;
    RUNNING = 3;
}
$ protoc -I=./ --go_out=./ ./_example/proto/simple.proto
_example/proto/simple.proto:7:15: The first enum value must be zero for open enums.

protolint does not have support for the checks that protoc does.

jordanbbaker commented 1 month ago

Thanks very much for the detailed response.

It makes sense in the context of the scope of protolint.

The context in my case is in establishing some automated pre-commit hook for protobufs. It sounds like it would be best to use both protolint and protoc to verify the sanity of the committed files.

yoheimuta commented 1 month ago

I see your point, so I'm willing to accept this feature when someone can prepare for it.