Skip to content

enum-first-value-zero

Protobufcorrectnessno fixdefault: warnprotobuf/buf-standard

Reports an enum whose first value is not 0. Proto3 and editions with open enums require it; proto2 files (also those with no syntax) are checked only with the proto2 option.

In proto3 the default of an enum field is the first value, and the value that a reader sees when the field is not set. It has to be 0, and a first value that means something real (ACTIVE = 1 and a hidden 0) makes unset data look valid.

To fix, make the first value 0 and name it for “not set”.

Reported
...
}
enum FirstNotZero {
FIRST_NOT_ZERO_ONE = 1;
FIRST_NOT_ZERO_UNSPECIFIED = 0;
}
...
protobuf:
lint:
rules:
enum-first-value-zero:
level: warn # off, warn (default), error
options:
proto2: false
Option Type Default Description
proto2 bool false Check proto2 files too, as buf does.

Enabled by the presets: protobuf/buf-standard.

Suppress one line with sudsy-disable-next-line enum-first-value-zero in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
buf ENUM_FIRST_VALUE_ZERO full