oneof-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 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.
Turn the rule off 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.
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;
}
}
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:
oneof-naming: off