Lint: One top level entity (message, enum, service) per file
Feature
The Protocol Buffers Documentation has in their guide the 1-1-1 Rule:
- One
proto_libraryrule - One source
.protofile - One top-level entity (message, enum, or extension)
And states: "When defining a proto schema, you should have a single message, enum, extension, service, or group of cyclic dependencies per file."
It would be great if the buf lint command would check for this. It would be fairly straight forward for one enum or service per file. For messages that are cyclic, it could be a bit more challenging, but I've never made such a message, so most messages should be one per file.
The 1-1-1 methodology sounds impractical, and isn't something we would recommend to our users at all. To start with, you shouldn't be moving files generally - doing so can cause breaking changes in source code. Moving files wouldn't be a concern at Google though, but that gets to the point: 1-1-1 feels like something for Google, but not for the rest of us.
Regardless, reasonable people can disagree, which is why we are currently working on buf plugins for lint and breaking change detection! This will let you write your own rules, including for rules that the Buf team disagrees with. We will keep you up to date when this is available!
Custom lint and breaking plugins are now available, the reference issue and docs:
- https://github.com/bufbuild/buf/issues/29
- https://buf.build/docs/cli/buf-plugins/tutorial-create-buf-plugin/
Going to close this issue since authoring custom check plugins is now released.