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

Unused import detection is broken in protoc-gen-buf-lint when the image contains an incompatible version of protovalidate than the one buf was compiled with #3306

Closed
jchadwick-buf opened this issue Sep 9, 2024 · 1 comment
Assignees
Labels
Bug Something isn't working

Comments

@jchadwick-buf
Copy link
Member

GitHub repository with your minimal reproducible example (do not fill out this field with "github.com/bufbuild/buf" or we will automatically close your issue, see the instructions above!)

https://github.com/jchadwick-buf/protoc-gen-buf-lint-unused-ext-import-issue

Commands

protoc -I . --buf-lint_out=. $(find ./test -name '*.proto')

Output

--buf-lint_out: test/c.proto:5:1:Import "test/a.proto" is unused.

Expected Output

I expect no lint failures.

Anything else?

This is caused because protoplugin uses proto.Unmarshal, using the default proto.UnmarshalOptions. This causes the Resolver to be protoregistry.GlobalTypes, resulting in all of the extensions from gencode imported by the Buf CLI code being prematurely resolved before the reparse phase. In this case, it happens due to protovalidate.

This is blocking bufbuild/protovalidate#246. When the import tracker for protoc-gen-buf-lint tries to mark imports as used, it tries to mark all of the extensions for options as used, but it hits an unexpected case when it sees the extensions for the shared protovalidate constraint, because it resolves to the fullname buf.validate.priv.field, but the PR renames the priv package to shared.

Fixing this will require some kind of modification to protoplugin, but a change that will fix this issue is very likely to change the behavior in other cases, so I think this warrants the creation of a new option in protoplugin.

@jchadwick-buf
Copy link
Member Author

This is fixed at HEAD after merging #3307.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant