-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
protoc-gen-go: remove generated dependency on github.com/golang/protobuf #1077
Comments
The only reason the newly generated The |
It is, it's just extra work, I guess, that didn't need to be done previously. It seems like if something is deprecated it should be possible to switch whole cloth to something new but that's not currently possible. |
The challenge that's specific to protobufs in Go is the existence of a global registry for all messages linked into a binary. We need to ensure that if someone uses the new I'm not sure there's much we can do here other than one of the following:
None of the options seem great. |
I’m kind of confused why |
Presumably you can edit the generator to generate code that does not trigger the linter. |
Kevin has the right idea here. Just because code has been generated doesn't mean that it is a) free of mistakes b) impossible to change. I think we can agree that if generated code has a clear bug, then the bug should be flagged. I extend that logic to the use of deprecated code: if something is deprecated, it shouldn't be used anymore. I think most people agree with me on that. That's why we're flagging generated code.¹
This is a poor choice if the generated code co-exists with other code in the same package, as disabling the check on this scale risks missing genuine offenders. A more appropriate solution might be to use a
I am not opposed to handling this in staticcheck itself, requiring no work on your part. Staticcheck can detect specific code generators if they have unique ¹: Note that there is also a class of checks in staticcheck that do not check generated code. For example, generated code is not expected to abide by most style guidelines. |
Is there an existing precedence for special-casing certain popular libraries and whatnot in |
There are a number of special cases, yes. It is somewhat of a burden, but minimizing the amount of unhelpful diagnostics is one of the design goals. I would rather modify staticcheck than argue for a change in someone else's code that isn't objectively better. Overall, the number of instances of "well, this is a unique situation that has no better solution" are few and the slippery slope isn't very steep. Moving the marker to a different package that isn't deprecated would be easier for me, but if you think that's too heavy-handed, then I'd rather add an exception than argue the case. |
Bumping into this now as well, and have disabled SA1019 to work around it. If possible, it would be great to get a workaround on the staticcheck side "at least for a few months" until the dependency is phased out. |
…proto specially github.com/golang/protobuf has deprecated the proto package, but their protoc-gen-go still imports the package and uses one of its constants, "to enforce a weak dependency on a sufficiently new version of the legacy package". Staticcheck would flag the import of this deprecated package in all code generated by protoc-gen-go. Instead of forcing the project to change their project structure, we choose to ignore such imports in code generated by protoc-gen-go. The import still gets flagged in code not generated by protoc-gen-go. Upstream issue: golang/protobuf#1077
dominikh/go-tools@7e758a3 should address the issue. |
Thanks @dominikh. I'm going to re-purpose this issue to be about the eventual removal of the generated "weak" dependency on |
…proto specially github.com/golang/protobuf has deprecated the proto package, but their protoc-gen-go still imports the package and uses one of its constants, "to enforce a weak dependency on a sufficiently new version of the legacy package". Staticcheck would flag the import of this deprecated package in all code generated by protoc-gen-go. Instead of forcing the project to change their project structure, we choose to ignore such imports in code generated by protoc-gen-go. The import still gets flagged in code not generated by protoc-gen-go. Upstream issue: golang/protobuf#1077
I hit this issue today, and I think it's OK to remove this check (or at the very least have a Having to have both versions of the protobuf library in |
In #1077 (comment), I suggested that we remove this generated hard dependency in 6 months. It's been 7 months since the initial |
The generated code still imports |
EDIT: Oh, I see. It looks like a line was missed in the CL that closed this issue. |
That line is an unused constant in the implementation of protoc-gen-go itself. Thanks for pointing that out, I'll remove it. The logic for actually emitting a generated dependency has been removed. See https://go-review.googlesource.com/c/protobuf/+/259901 |
The logic that formerly depended on this was deleted in https://golang.org/cl/259901. This is dead code now. Updates golang/protobuf#1077 Change-Id: Ieb1b14243d9503b1baac7026c6ce226923873405 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/260817 Trust: Joe Tsai <thebrokentoaster@gmail.com> Reviewed-by: Damien Neil <dneil@google.com>
@dsnet could you kindly make a new release since this issue has been resolved? such as 1.26.0 |
For someone new to the go and grpc world this error is frustrating, I have read the entire issue and there is no talk about a possible workaround. |
@dsnet what's our timeline for releasing a new version of |
This or next week. |
v1.26.0 is released. |
golang/protobuf#1077 is fixed Signed-off-by: Joe Richey <joerichey@google.com>
golang/protobuf#1077 package github.com/golang/protobuf/proto is deprecated: Use the "google.golang.org/protobuf/proto" package instead. (SA1019)
Staticcheck is a popular tool for vetting Go source code. For example, the golang.org/x/tools project includes it in the workflow for
lsp
.Attempting to run staticcheck on generated
.pb.go
files yields the following error:This makes it more difficult to use staticcheck as part of a workflow that includes generated proto files. Further, it's not clear that this situation can be resolved by end users; the generated files are going to import golang/protobuf for some time still.
The text was updated successfully, but these errors were encountered: