Linter rulesProtobufpackage-defined
package-defined
Since 0.9.0
This rule checks whether every Protobuf file declares a package.
Rule Details
Without a package declaration, the messages, enums and services of a file live in the global
namespace, where they can clash with the declarations of any other file. Most code generators
also derive the names of the generated packages or namespaces from the Protobuf package.
The package-defined rule reports File has no package declaration for every file without a
package statement. The issue is reported at the syntax statement.
Configuration
This rule has no options.
Examples
Good.
syntax = "proto3";
package acme.pets.v1;
message Pet {
string name = 1;
}
Bad. The linter reports File has no package declaration.
syntax = "proto3";
message Pet {
string name = 1;
}
When Not to Use It
We recommend to always enable this rule.
Compatibility
This rule is compatible with proto3 files. proto2 and editions files are rejected by the reader and are not linted.