bufbuild / buf

The best way of working with Protocol Buffers.
https://buf.build
Apache License 2.0
8.87k stars 265 forks source link

Lint: One top level entity (message, enum, service) per file #3254

Open ngbrown opened 3 weeks ago

ngbrown commented 3 weeks ago

Feature

The Protocol Buffers Documentation has in their guide the 1-1-1 Rule:

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.

bufdev commented 3 weeks ago

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!