enum-no-allow-alias

Since 0.9.0 · In the rulesets: Recommended at warning, Strict at error, All at error

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.

Turn the rule off 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.

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;
}

Turn it off or change its severity

In apigenie.yaml, off turns the rule off and warning or error sets its severity; a rule with options takes the severity and the options as a pair, [warning, options]. lint.protobuf has the details.

commands:
  lint:
    protobuf:
      rules:
        enum-no-allow-alias: off

Related rules

Last updated on View as Markdown
Was this helpful?