Skip to content

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

Merged
merged 12 commits into from
Aug 14, 2024

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 requested review from akshayjshah, jhump and doriable May 23, 2024 15:35
@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
Contributor

@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
Contributor

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.

Copy link

@noahseger noahseger Jul 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 @akshayjshah @bufdev

I'm just doc golfing but less text is always nice, e.g. Stable package %q cannot import unstable file %q.

@doriable doriable changed the title WIP: Add STABLE_PACKAGE_NO_IMPORT_UNSTABLE lint rule Add STABLE_PACKAGE_NO_IMPORT_UNSTABLE lint rule Aug 1, 2024
Copy link
Contributor

github-actions bot commented Aug 1, 2024

The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedAug 14, 2024, 4:48 PM


package api.v1;

import "api/v1alpha/bar.proto";
Copy link
Member Author

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)

Copy link
Member Author

@bufdev bufdev left a 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

Copy link
Member Author

@bufdev bufdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bufdev bufdev merged commit 9d377ce into main Aug 14, 2024
11 checks passed
@bufdev bufdev deleted the stable-package-no-import-unstable branch August 14, 2024 17:18
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.

4 participants