file-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 Protobuf file is in lower_snake_case, with the .proto extension.

Rule details

Code generators derive the names of the generated files, and sometimes of classes, from the names of the .proto files. lower_snake_case names such as pet_owner.proto are safe on every file system and in every target language, and are what the Protobuf style guide recommends.

The file-naming rule checks the name of the linted file, without its directory. The name must end with .proto, and the part before the extension must start with a lower-case letter or a digit (as in 2fa.proto), and contain only lower-case letters, digits and single underscores, with no underscore at the end. Otherwise the rule reports:

File name '<name>' should be lower_snake_case.proto

followed by a suggestion such as , e.g. 'pet_store.proto'. To build the suggestion, the part before the extension is split into words at underscores and other separators such as - and ., at lower-to-upper case changes and before the last capital of an acronym, and the words are joined in lower case with underscores.

Files linted without a path are not checked.

The rule uses the path of the linted file, but not its content.

Turn the rule off if the file names are dictated by an existing project layout that you cannot change.

Examples

Good. The file pet_store.proto:

syntax = "proto3";

package acme.pets.v1;

message Pet {
  string name = 1;
}

Bad. The same content in the file PetStore.proto makes the linter report File name 'PetStore.proto' should be lower_snake_case.proto, e.g. 'pet_store.proto', and in the file pet-store.proto, File name 'pet-store.proto' should be lower_snake_case.proto, e.g. 'pet_store.proto'.

syntax = "proto3";

package acme.pets.v1;

message Pet {
  string name = 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:
        file-naming: off

Related rules

Last updated on View as Markdown
Was this helpful?