-
Notifications
You must be signed in to change notification settings - Fork 309
Add STABLE_PACKAGE_NO_IMPORT_UNSTABLE lint rule #3010
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like a valuable check to me!
Organizations with many existing violations of this rule may have a hard time adopting it, but that shouldn't stop us from offering it.
continue | ||
} | ||
if packageVersion.StabilityLevel() != protoversion.StabilityLevelStable { | ||
add(fileImport, fileImport.Location(), nil, `This file has package %q that represents a stable version, but it imports %q, which has package %q that represents an unstable version. Stable packages should not depend on unstable packages.`, file.Package(), fileImport.Import(), fileImport.File().Package()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we shorten the error text?
This file is in stable package %q, so it should not depend on %q from unstable package %q.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just doc golfing but less text is always nice, e.g. Stable package %q cannot import unstable file %q.
The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).
|
|
||
package api.v1; | ||
|
||
import "api/v1alpha/bar.proto"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An import on a stable package, and a package with no stability level, should also be added (both should not result in failures)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changelog needs to be updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I'm not yet sure if we want to add this into mainline. Opening this for discussion.
This is re: #2986.
This adds a
STABLE_PACKAGE_NO_IMPORT_UNSTABLE
lint rule, with no category, that will produce a lint failure if an stable package imports a file with an unstable package. For example:a.proto
importsb.proto
, anda.proto
has packagea.v1
:b.proto
has packagefoo
, no failure - cannot determine package stability.b.proto
has packagefoo.v1
, no failure - stable imports stable.b.proto
has packagefoo.v1beta1
, failure - stable imports unstable.a.proto
has packagea
:a.proto
has packagea.v1beta1
:If we do decide to go ahead with this, this PR: