field-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 field of a Protobuf file is in lower_snake_case.
Rule details
Code generators derive the accessor names and the JSON names of fields from their Protobuf
names, assuming lower_snake_case: owner_name becomes ownerName in JSON and
getOwnerName() in Java. Other conventions produce surprising names, and can make the JSON
names of two fields collide.
The field-naming rule checks every field, including the fields of oneofs, map fields and
extension fields, and reports Field 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
field, add an // apigenie-lint-disable field-naming comment to it.
Examples
Good.
syntax = "proto3";
package acme.pets.v1;
message Pet {
string owner_name = 1;
map<string, string> labels = 2;
}
Bad. The linter reports Field name 'ownerName' should be lower_snake_case, e.g. 'owner_name'.
syntax = "proto3";
package acme.pets.v1;
message Pet {
string ownerName = 1;
map<string, string> labels = 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:
field-naming: off