enum-value-naming

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

This rule checks whether the name of every enum value of a Protobuf file is in UPPER_SNAKE_CASE.

Rule details

Enum values are constants, and UPPER_SNAKE_CASE is how most target languages write constants. It is also what the Protobuf style guide recommends.

The enum-value-naming rule checks every enum value, and reports Enum value name '<name>' should be UPPER_SNAKE_CASE for every name that is not in UPPER_SNAKE_CASE. A name is in UPPER_SNAKE_CASE when it starts with an upper-case letter and contains only upper-case letters, digits and single underscores, with no underscore at the end, such as PET_KIND_DOG.

When the name converted to UPPER_SNAKE_CASE differs from the original and is itself valid, the message ends with a suggestion, for example , e.g. '<converted>'. To convert a name, it is split into words at underscores and other separators, at lower-to-upper case changes and before the last capital of an acronym, and the words are joined in upper case with underscores, so petKindDog becomes PET_KIND_DOG.

Turn the rule off if the names are part of an existing API that you cannot rename. To allow a single enum value, add an // apigenie-lint-disable enum-value-naming comment to it.

Examples

Good.

syntax = "proto3";

package acme.pets.v1;

enum PetKind {
  PET_KIND_UNSPECIFIED = 0;
  PET_KIND_DOG = 1;
}

Bad. The linter reports Enum value name 'petKindDog' should be UPPER_SNAKE_CASE, e.g. 'PET_KIND_DOG'.

syntax = "proto3";

package acme.pets.v1;

enum PetKind {
  PET_KIND_UNSPECIFIED = 0;
  petKindDog = 1;
}

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-value-naming: off

Related rules

Was this helpful?