-
Notifications
You must be signed in to change notification settings - Fork 348
Open
Labels
FeatureNew feature or requestNew feature or request
Description
Feature
The protocol buffers documentation recommends using optional / explicit presence fields over implicit fields for maximum compatibility with protobuf editions and proto2. It would be nice to be able to enforce this official recommendation with a lint rule to prevent implicit presence fields from accidentally being added to a schema. For example:
syntax = "proto3";
enum Baz {
BAZ_UNSPECIFIED = 0;
BAZ_ONE = 1;
}
message Foo {
// Error: `Field "bar" should be declared "optional".`.
int32 bar = 1;
// Error: `Field "baz" should be declared "optional".`
Baz baz = 2;
// No error; messages always have explicit presence in proto3.
Foo foo = 3;
// No error; messages always have explicit presence in proto3.
optional Foo foo2 = 4;
}edition = "2023";
enum Baz {
BAZ_UNSPECIFIED = 0;
BAZ_ONE = 1;
}
message Foo {
// No error; int32 has explicit presence by default in edition 2023.
int32 bar = 1;
// No error; enums have explicit presence by default in edition 2023.
Baz baz = 2;
// Error: `Field "quux" should use explicit presence.`
string quux = 3 [features.field_presence = IMPLICIT];
// No error; field explicitly uses explicit presence, although the annotation
// is unnecessary in edition 2023.
uint64 quux2 = 4 [fetaures.field_presence = EXPLICIT];
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
FeatureNew feature or requestNew feature or request