Reference
Lint rules
stubs lint checks a workspace's .proto files against these rules: the same checks Stubs runs for an
organisation's lint policy (see Governance). Choose them in
lint in stubs.yaml by category or by ID, and list them with
stubs config ls-lint-rules.
A rule's anchor is its ID, so /docs/lint-rules#FIELD_LOWER_SNAKE_CASE and #field_lower_snake_case both lead to it.
Categories
Each category is a set of rules. MINIMAL, BASIC and STANDARD each include the one before; COMMENTS and
UNARY_RPC are extras to add to them.
MINIMAL
The rules that keep a module buildable and its packages consistent: every file has a package, a package lives in one directory that matches its name, and packages don't import each other in a cycle.
BASIC
MINIMAL, plus the naming and import conventions most Protobuf code follows: PascalCase messages, enums, services
and RPCs, lower_snake_case fields and packages, UPPER_SNAKE_CASE enum values, no public imports, and no unused
ones.
STANDARD
BASIC, plus the rules that keep an API easy to change: enum values prefixed with their enum's name and a zero value
ending in _UNSPECIFIED, packages ending in a version (acme.payments.v1), and each RPC with its own request and
response messages. This is the default.
DEFAULT is an older name for STANDARD, kept so configs that use it still work, which is why rules list it too.
COMMENTS
Every message, field, enum, enum value, oneof, service and RPC has a comment. Not in STANDARD; add it with use.
UNARY_RPC
No streaming RPCs, for APIs that must work where streaming doesn't. Not in STANDARD.
v1beta1 configs also have the older categories FILE_LAYOUT, PACKAGE_AFFINITY, SENSIBLE, STYLE_BASIC,
STYLE_DEFAULT, STYLE_STANDARD and OTHER, shown with each rule below.
Settings
Some rules take settings, in lint:
enum_zero_value_suffixchanges the suffixENUM_ZERO_VALUE_SUFFIXasks for.service_suffixchanges the suffixSERVICE_SUFFIXasks for.
RPC requests and responses
RPC_REQUEST_RESPONSE_UNIQUE, RPC_REQUEST_STANDARD_NAME
and RPC_RESPONSE_STANDARD_NAME ask that each RPC Foo takes a FooRequest and returns
a FooResponse of its own, so either can gain fields without changing other RPCs. Three settings relax them:
rpc_allow_same_request_response: truelets an RPC use one message for both.rpc_allow_google_protobuf_empty_requests: truelets an RPC takegoogle.protobuf.Empty.rpc_allow_google_protobuf_empty_responses: truelets an RPC returngoogle.protobuf.Empty.
Package-wide file options
The PACKAGE_SAME_* rules ask that every file of a package sets each language's package option (go_package,
java_package, csharp_namespace …) to the same value, or leaves it unset in all of them, so a package's generated
code ends up in one place. Managed mode (see managed) can set them for you.
Ignoring a rule
To skip a rule for some files, list them under ignore_only in lint. To skip it at one place, put a comment above
the element:
// buf:lint:ignore FIELD_LOWER_SNAKE_CASE
string legacyId = 1;disallow_comment_ignores: true turns those comments off.
Rules
DIRECTORY_SAME_PACKAGE
Every file in a directory declares the same package. Mixing packages in one directory makes the layout lie about what's inside, and most code generators write one directory per package, so they collide.
Categories: MINIMAL, BASIC, DEFAULT, STANDARD.
In v1beta1 configs: MINIMAL, BASIC, DEFAULT, STANDARD, FILE_LAYOUT.
PACKAGE_DEFINED
Every file declares a package. Without one, its types live in the global namespace, where any other file's types can clash with them.
Categories: MINIMAL, BASIC, DEFAULT, STANDARD.
In v1beta1 configs: MINIMAL, BASIC, DEFAULT, STANDARD, SENSIBLE.
PACKAGE_DIRECTORY_MATCH
A file's directory matches its package: acme.payments.v1 lives in acme/payments/v1/. Then a type's name says where to find it, and import paths are predictable.
Categories: MINIMAL, BASIC, DEFAULT, STANDARD.
In v1beta1 configs: MINIMAL, BASIC, DEFAULT, STANDARD, FILE_LAYOUT.
PACKAGE_NO_IMPORT_CYCLE
Packages don't import each other in a loop (A imports B, B imports A). Many languages can't compile generated code with a cycle between packages.
Categories: MINIMAL, BASIC, DEFAULT, STANDARD.
In v1 configs: none.
Not in v1beta1 configs.
PACKAGE_SAME_DIRECTORY
All the files of a package are in one directory, so a package's types are in one place and generate together.
Categories: MINIMAL, BASIC, DEFAULT, STANDARD.
In v1beta1 configs: MINIMAL, BASIC, DEFAULT, STANDARD, FILE_LAYOUT.
ENUM_FIRST_VALUE_ZERO
An enum's first value is 0. In proto3 and Editions, zero is what an unset field reads as, so it should be the first, deliberate value: usually …_UNSPECIFIED.
Categories: BASIC, DEFAULT, STANDARD.
In v1beta1 configs: OTHER.
ENUM_NO_ALLOW_ALIAS
Enums don't set allow_alias, so each number has one name. With aliases, the name a number decodes to (in JSON, in logs) is ambiguous, and renaming a value safely is harder.
Categories: BASIC, DEFAULT, STANDARD.
In v1beta1 configs: MINIMAL, BASIC, DEFAULT, STANDARD, SENSIBLE.
ENUM_PASCAL_CASE
Enum names are PascalCase, as in PaymentStatus.
Categories: BASIC, DEFAULT, STANDARD.
In v1beta1 configs: BASIC, DEFAULT, STANDARD, STYLE_BASIC, STYLE_DEFAULT, STYLE_STANDARD.
ENUM_VALUE_UPPER_SNAKE_CASE
Enum values are UPPER_SNAKE_CASE, as in PAYMENT_STATUS_SETTLED.
Categories: BASIC, DEFAULT, STANDARD.
In v1beta1 configs: BASIC, DEFAULT, STANDARD, STYLE_BASIC, STYLE_DEFAULT, STYLE_STANDARD.
FIELD_LOWER_SNAKE_CASE
Field names are lower_snake_case, as in amount_minor. Code generators turn that into each language's own style (amountMinor, AmountMinor), and JSON names are derived from it.
Categories: BASIC, DEFAULT, STANDARD.
In v1beta1 configs: BASIC, DEFAULT, STANDARD, STYLE_BASIC, STYLE_DEFAULT, STYLE_STANDARD.
FIELD_NOT_REQUIRED
No field is required (proto2) or LEGACY_REQUIRED (Editions). A required field can never be removed: every reader rejects a message without it, including messages from code that's moved on.
Categories: BASIC, DEFAULT, STANDARD.
Not in v1 or v1beta1 configs.
IMPORT_NO_PUBLIC
No import public. Public imports re-export another file's types, which hides real dependencies and isn't supported the same way by every language.
Categories: BASIC, DEFAULT, STANDARD.
In v1beta1 configs: MINIMAL, BASIC, DEFAULT, STANDARD, SENSIBLE.
IMPORT_USED
Every import is used. An unused import is a dependency for nothing, and some languages' generated code warns or fails on it.
Categories: BASIC, DEFAULT, STANDARD.
Not in v1beta1 configs.
MESSAGE_PASCAL_CASE
Message names are PascalCase, as in CreatePaymentRequest.
Categories: BASIC, DEFAULT, STANDARD.
In v1beta1 configs: BASIC, DEFAULT, STANDARD, STYLE_BASIC, STYLE_DEFAULT, STYLE_STANDARD.
ONEOF_LOWER_SNAKE_CASE
Oneof names are lower_snake_case, as in payment_method.
Categories: BASIC, DEFAULT, STANDARD.
In v1beta1 configs: BASIC, DEFAULT, STANDARD, STYLE_BASIC, STYLE_DEFAULT, STYLE_STANDARD.
PACKAGE_LOWER_SNAKE_CASE
Package names are lower case, with _ within a part and . between parts, as in acme.payment_links.v1.
Categories: BASIC, DEFAULT, STANDARD.
In v1beta1 configs: BASIC, DEFAULT, STANDARD, STYLE_BASIC, STYLE_DEFAULT, STYLE_STANDARD.
PACKAGE_SAME_CSHARP_NAMESPACE
Every file of a package sets csharp_namespace to the same value, or none does, so the package's C# code lands in one namespace.
Categories: BASIC, DEFAULT, STANDARD.
In v1beta1 configs: MINIMAL, BASIC, DEFAULT, STANDARD, PACKAGE_AFFINITY.
PACKAGE_SAME_GO_PACKAGE
Every file of a package sets go_package to the same value, or none does. Go needs a package's files in one directory and package; otherwise the generated code won't compile.
Categories: BASIC, DEFAULT, STANDARD.
In v1beta1 configs: MINIMAL, BASIC, DEFAULT, STANDARD, PACKAGE_AFFINITY.
PACKAGE_SAME_JAVA_MULTIPLE_FILES
Every file of a package sets java_multiple_files the same way, or none does, so its Java classes are laid out consistently.
Categories: BASIC, DEFAULT, STANDARD.
In v1beta1 configs: MINIMAL, BASIC, DEFAULT, STANDARD, PACKAGE_AFFINITY.
PACKAGE_SAME_JAVA_PACKAGE
Every file of a package sets java_package to the same value, or none does, so the package's Java code is in one Java package.
Categories: BASIC, DEFAULT, STANDARD.
In v1beta1 configs: MINIMAL, BASIC, DEFAULT, STANDARD, PACKAGE_AFFINITY.
PACKAGE_SAME_PHP_NAMESPACE
Every file of a package sets php_namespace to the same value, or none does.
Categories: BASIC, DEFAULT, STANDARD.
In v1beta1 configs: MINIMAL, BASIC, DEFAULT, STANDARD, PACKAGE_AFFINITY.
PACKAGE_SAME_RUBY_PACKAGE
Every file of a package sets ruby_package to the same value, or none does.
Categories: BASIC, DEFAULT, STANDARD.
In v1beta1 configs: MINIMAL, BASIC, DEFAULT, STANDARD, PACKAGE_AFFINITY.
PACKAGE_SAME_SWIFT_PREFIX
Every file of a package sets swift_prefix to the same value, or none does.
Categories: BASIC, DEFAULT, STANDARD.
In v1beta1 configs: MINIMAL, BASIC, DEFAULT, STANDARD, PACKAGE_AFFINITY.
RPC_PASCAL_CASE
RPC names are PascalCase, as in CreatePayment.
Categories: BASIC, DEFAULT, STANDARD.
In v1beta1 configs: BASIC, DEFAULT, STANDARD, STYLE_BASIC, STYLE_DEFAULT, STYLE_STANDARD.
SERVICE_PASCAL_CASE
Service names are PascalCase, as in PaymentService.
Categories: BASIC, DEFAULT, STANDARD.
In v1beta1 configs: BASIC, DEFAULT, STANDARD, STYLE_BASIC, STYLE_DEFAULT, STYLE_STANDARD.
SYNTAX_SPECIFIED
Every file says what it's written in: syntax = "proto3"; or an edition. Without it, a file is silently proto2, which is rarely what was meant.
Categories: BASIC, DEFAULT, STANDARD.
Not in v1beta1 configs.
ENUM_VALUE_PREFIX
An enum's values start with the enum's name in UPPER_SNAKE_CASE: PaymentStatus has PAYMENT_STATUS_SETTLED. Enum values share their package's namespace, so two enums in a package can't both have UNKNOWN without a prefix.
Categories: DEFAULT, STANDARD.
In v1beta1 configs: DEFAULT, STANDARD, STYLE_DEFAULT, STYLE_STANDARD.
ENUM_ZERO_VALUE_SUFFIX
An enum's zero value ends in _UNSPECIFIED (or the enum_zero_value_suffix you set), as in PAYMENT_STATUS_UNSPECIFIED. It reads as what it is: the value of a field nobody set.
Categories: DEFAULT, STANDARD.
In v1beta1 configs: DEFAULT, STANDARD, STYLE_DEFAULT, STYLE_STANDARD.
FILE_LOWER_SNAKE_CASE
File names are lower_snake_case.proto, as in payment_links.proto. Some generators turn file names into class or module names, and mixed case breaks on case-insensitive file systems.
Categories: DEFAULT, STANDARD.
In v1beta1 configs: DEFAULT, STANDARD, STYLE_DEFAULT, STYLE_STANDARD.
PACKAGE_VERSION_SUFFIX
A package's last part is a version: v1, or v1alpha1, v1beta1, v1test, v1p1beta1. The version is what lets you make a breaking change by starting v2 next to v1, with no clash.
Categories: DEFAULT, STANDARD.
In v1beta1 configs: DEFAULT, STANDARD, STYLE_DEFAULT, STYLE_STANDARD.
PROTOVALIDATE
protovalidate constraints on fields and messages are valid: each applies to the field's type, they don't contradict each other, and every CEL expression compiles. Mistakes show up here, not as a runtime error.
Categories: DEFAULT, STANDARD.
Not in v1beta1 configs.
RPC_REQUEST_RESPONSE_UNIQUE
Each request and response message belongs to one RPC. When two RPCs share a message, neither can add a field without the other getting it too. See RPC requests and responses for the settings that relax it.
Categories: DEFAULT, STANDARD.
In v1beta1 configs: DEFAULT, STANDARD, STYLE_DEFAULT, STYLE_STANDARD.
RPC_REQUEST_STANDARD_NAME
An RPC's request message is named after it: CreatePayment takes CreatePaymentRequest (or PaymentServiceCreatePaymentRequest). google.protobuf.Empty is allowed with rpc_allow_google_protobuf_empty_requests.
Categories: DEFAULT, STANDARD.
In v1beta1 configs: DEFAULT, STANDARD, STYLE_DEFAULT, STYLE_STANDARD.
RPC_RESPONSE_STANDARD_NAME
An RPC's response message is named after it: CreatePayment returns CreatePaymentResponse (or PaymentServiceCreatePaymentResponse). google.protobuf.Empty is allowed with rpc_allow_google_protobuf_empty_responses.
Categories: DEFAULT, STANDARD.
In v1beta1 configs: DEFAULT, STANDARD, STYLE_DEFAULT, STYLE_STANDARD.
SERVICE_SUFFIX
Service names end in Service (or the service_suffix you set), as in PaymentService, so generated clients and servers are recognisable as such.
Categories: DEFAULT, STANDARD.
In v1beta1 configs: DEFAULT, STANDARD, STYLE_DEFAULT, STYLE_STANDARD.
COMMENT_ENUM
Every enum has a comment above it. Comments become the documentation in generated code and in the API Explorer.
Categories: COMMENTS.
COMMENT_ENUM_VALUE
Every enum value has a comment.
Categories: COMMENTS.
COMMENT_FIELD
Every field has a comment.
Categories: COMMENTS.
COMMENT_MESSAGE
Every message has a comment.
Categories: COMMENTS.
COMMENT_ONEOF
Every oneof has a comment.
Categories: COMMENTS.
COMMENT_RPC
Every RPC has a comment.
Categories: COMMENTS.
COMMENT_SERVICE
Every service has a comment.
Categories: COMMENTS.
RPC_NO_CLIENT_STREAMING
No RPC streams its requests. Client streaming doesn't work from browsers or through many proxies.
Categories: UNARY_RPC.
RPC_NO_SERVER_STREAMING
No RPC streams its responses, for APIs that must work where streaming doesn't, such as some proxies and serverless platforms.
Categories: UNARY_RPC.
IMPORT_NO_WEAK
No import weak. Weak imports are a Google-internal feature most languages don't support.
Categories: none. Deprecated: kept so configs that name it still work.
STABLE_PACKAGE_NO_IMPORT_UNSTABLE
A stable package (v1) doesn't import an unstable one (v1beta1, v1alpha1, v1test). An unstable package can change at any time, and anything stable that depends on it would break with it.
Categories: none.
Not in v1 or v1beta1 configs.
FIELD_NO_DESCRIPTOR
No field is named descriptor (in any case, with any underscores around it). It clashes with the descriptor accessor some languages generate on every message, such as Java's getDescriptor().
Categories: MINIMAL, BASIC, DEFAULT, STANDARD, SENSIBLE (in v1beta1 configs; not in v2).