import-no-public

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

This rule checks whether a Protobuf file uses import public.

Rule details

A public import makes the declarations of the imported file visible to every file that imports the importing one. It is meant as a temporary measure when moving declarations between files, but it hides the real dependencies of the importers, and several code generators support it poorly or not at all.

The import-no-public rule reports Import '<import>' should not be public for every import public statement.

Turn the rule off while moving declarations from one file to another, when a public import keeps the existing importers working. To allow a single import, add an // apigenie-lint-disable import-no-public comment to it.

Examples

Good.

syntax = "proto3";

package acme.pets.v1;

import "google/protobuf/timestamp.proto";

message Pet {
  string name = 1;
  google.protobuf.Timestamp born_at = 2;
}

Bad. The linter reports Import 'google/protobuf/timestamp.proto' should not be public.

syntax = "proto3";

package acme.pets.v1;

import public "google/protobuf/timestamp.proto";

message Pet {
  string name = 1;
  google.protobuf.Timestamp born_at = 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:
        import-no-public: off

Related rules

Last updated on View as Markdown
Was this helpful?