Skip to content
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

WIP: Add STABLE_PACKAGE_NO_IMPORT_UNSTABLE lint rule #3010

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bufdev
Copy link
Member

@bufdev bufdev commented May 23, 2024

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:

  1. If a.proto imports b.proto, and a.proto has package a.v1:
  • If b.proto has package foo, no failure - cannot determine package stability.
  • If b.proto has package foo.v1, no failure - stable imports stable.
  • If b.proto has package foo.v1beta1, failure - stable imports unstable.
  1. If a.proto has package a:
  • No failure ever - cannot determine package stability.
  1. If a.proto has package a.v1beta1:
  • No failure ever - package is unstable, does not matter what it imports.

If we do decide to go ahead with this, this PR:

  • Needs some discussion as to the rule name.
  • Needs testing.

@bufdev bufdev changed the title WIPP: Add STABLE_PACKAGE_NO_IMPORT_UNSTABLE lint rule WIP: Add STABLE_PACKAGE_NO_IMPORT_UNSTABLE lint rule May 23, 2024
Copy link
Member

@akshayjshah akshayjshah left a 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())
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants