Linter rulesProtobufoneof-naming

oneof-naming

Since 0.9.0

This rule checks whether the name of every oneof of a Protobuf file is in lower_snake_case.

Rule Details

Code generators derive the names of the accessors and case enums of oneofs from their Protobuf names, assuming lower_snake_case, like for fields.

The oneof-naming rule checks every oneof, and reports Oneof name '<name>' should be lower_snake_case for every name that is not in lower_snake_case. A name is in lower_snake_case when it starts with a lower-case letter and contains only lower-case letters, digits and single underscores, with no underscore at the end, such as owner_name or address_2.

When the name converted to lower_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 lower case with underscores, so ownerName becomes owner_name and HTTPServer becomes http_server.

Configuration

This rule has no options.

Examples

Good.

syntax = "proto3";

package acme.pets.v1;

message Pet {
  string name = 1;
  oneof owner_contact {
    string email = 2;
    string phone = 3;
  }
}

Bad. The linter reports Oneof name 'ownerContact' should be lower_snake_case, e.g. 'owner_contact'.

syntax = "proto3";

package acme.pets.v1;

message Pet {
  string name = 1;
  oneof ownerContact {
    string email = 2;
    string phone = 3;
  }
}

When Not to Use It

You may disable this rule if the names are part of an existing API that you cannot rename. To allow a single oneof, add an // apigenie-lint-disable oneof-naming comment to it.

Compatibility

This rule is compatible with proto3 files. proto2 and editions files are rejected by the reader and are not linted.

Related rules