buf icon indicating copy to clipboard operation
buf copied to clipboard

Enforce specific type usage via lint

Open AlexeiZenin opened this issue 4 years ago • 2 comments

Currently we have some best practices in our org that we would want to enforce on specific types users should use for primitives or wrapper types such as StringValue.

Would it be possible for Buf to add support for some custom rules which could be configured to allow enforcing all int64 types are sint64 for example?

There are many types in Protobuf 3 which leads to confusion and bad decisions taken on part by an unsuspecting user (see https://stackoverflow.com/questions/765916/is-there-ever-a-good-time-to-use-int32-instead-of-sint32-in-google-protocol-buff).

If this could be configurable that would be great. The granularity would be to disallow certain datatypes from appearing or another way could be doing an allowed type list as well (StringValue, IntValue, sint64, etc).

This would help us enforce these rules through automation rather than through documentation, word of mouth or PR review.

AlexeiZenin avatar May 17 '21 16:05 AlexeiZenin

I think this would be a great addition to be able to configure "undesirable" types. For example the use of google.protobuf.Struct or google.protobuf.Any might not be desired for particular applications, as it introduces ambiguity, and might want to be prevented in particular design scenarios.

If there was a configurable linter option to provide a list of disallowed types, it would help a lot.

aantono avatar May 26 '21 15:05 aantono

We can consider this, it's a little out of scope but I see the use case.

bufdev avatar Jul 31 '21 16:07 bufdev

Tracking on https://github.com/bufbuild/buf/issues/29

bufdev avatar Nov 27 '23 17:11 bufdev