Add lint rule to prevent stable packages importing unstable packages
A common mistake we see is forgetting a v1alpha import into a v1 package. Has a lint rule preventing this been considered? If not, what do folks here generally use to lint better on top of Buf?
I think the general community would benefit from baking this into the DEFAULT configuration though, because even changing a field from v1alpha.MyType to v1.MyType is breaking, and requires the ignore / commit / unignore / commit dance.
I'm not sure I understand the question or proposal, can you explain a bit more what you are looking for?
@bufdev say I have two protobufs like:
syntax = "proto3";
package examples.v1alpha;
message AlphaDependency {
string foo = 1;
}
syntax = "proto3";
import "examples/v1alpha/dependency.proto"
package examples.v1;
message StableExample {
examples.v1alpha.AlphaDependency dependency = 1;
}
There are two primary problems:
- Buf (by default) allows me to change the v1alpha dependency in incompatible ways, which silently breaks v1
- If I want to promote the v1alpha dependency to v1, the type change in the existing stable file is breaking
- By default,
bufdoes not allow you to make breaking changes to thev1alphapackage, that is an option you have to opt into via https://buf.build/docs/configuration/v2/buf-yaml#ignore_unstable_packages. Ifignore_unstable_packagesis not set, then breaking changes tov1alphawill result in errors when runningbuf breaking. - Changing the type of a field is considered a breaking change, so updating the type of
examples.v1alpha.AlphaDependencyto sayexamples.v1.AlphaDependencywill result in an error when runningbuf breaking. There's no concrete way forbuf breakingto denote that "this was just a package change, the underlying type is exactly the same, do not error", and we wouldn't want to ignore this as a general concern. We could, in theory, do deep type inspection, but this would be source-code-breaking to begin with, and we consider that out of scope. Your mitigation here is to override the breaking change error if you are certain that your change is expected.
Ah yes, understood — we did enable ignore_unstable_packages because we need to evolve alpha versions in breaking ways.
But to be clear, the feature request isn't to inspect the alpha dependency types (although I think this would work with PACKAGE as the breaking configuration type?).
The feature request is:
- when I have a stable proto file
- and I import an unstable proto file into it
- then I get a lint error like "Stable protos may not import unstable protos"
OK I understand the feature request now - thanks for the clarification. I've opened #3010 to discuss this issue further.
This has been added and will go out in a release tomorrow morning.
Thank you all so much! Upgrading now.