Linter rulesProtobufenum-no-allow-alias
enum-no-allow-alias
Since 0.9.0
This rule checks whether any enum sets the allow_alias option.
Rule Details
With option allow_alias = true;, several values of an enum can share a number. Only one of the
names survives serialization, though: the JSON and text formats always write the first name of
the number, so a client that sends one name may read back another. Aliases also make renaming
values harder than it looks, since both names have to be kept in sync with every consumer.
The enum-no-allow-alias rule reports Enum '<enum>' should not allow aliases at the
allow_alias option of every enum that sets it to true.
Configuration
This rule has no options.
Examples
Good.
syntax = "proto3";
package acme.pets.v1;
enum PetKind {
PET_KIND_UNSPECIFIED = 0;
PET_KIND_DOG = 1;
PET_KIND_CAT = 2;
}
Bad. The linter reports Enum 'PetKind' should not allow aliases.
syntax = "proto3";
package acme.pets.v1;
enum PetKind {
option allow_alias = true;
PET_KIND_UNSPECIFIED = 0;
PET_KIND_DOG = 1;
PET_KIND_HOUND = 1;
PET_KIND_CAT = 2;
}
When Not to Use It
You may disable this rule while renaming enum values: an alias lets the old and the new name
coexist until all clients have moved to the new one. To allow a single enum, add an
// apigenie-lint-disable enum-no-allow-alias comment to the enum.
Compatibility
This rule is compatible with proto3 files. proto2 and editions files are rejected by the reader and are not linted.