enum-first-value-zero
What it does
Section titled “What it does”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.
Why it matters
Section titled “Why it matters”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”.
Example
Section titled “Example”...}
enum FirstNotZero { FIRST_NOT_ZERO_ONE = 1; FIRST_NOT_ZERO_UNSPECIFIED = 0;}
...Configuration
Section titled “Configuration”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.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| buf | ENUM_FIRST_VALUE_ZERO |
full |