package-defined

Since 0.9.0 · In the rulesets: Recommended at error, Strict at error, All at error

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.

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;
}

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:
        package-defined: off

Related rules

Last updated on View as Markdown
Was this helpful?