-
Notifications
You must be signed in to change notification settings - Fork 278
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
Add analyzer to enforce usage of VT versions of marshalling and unmarshalling #2043
Conversation
a1aa797
to
f4deb83
Compare
Had a conversation with @josephschorr where it'd be nice to have a sort of snapshot test that serializes a schema out to protobuf bytes using both VT and non-VT, and then the test deserializes using the opposite and then asserts that they agree, with the idea being that it's a snapshot test that will alert us if our serialization or deserialization changes meaningfully. |
"golang.org/x/tools/go/ast/inspector" | ||
) | ||
|
||
func sliceMap(s []string, f func(value string) string) []string { |
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 think there's a function for this in the lo library we import some places
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.
Is it named the same? I copied this code from an existing analyzer.
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.
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, just 2 nits
"golang.org/x/tools/go/ast/inspector" | ||
) | ||
|
||
func sliceMap(s []string, f func(value string) string) []string { |
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.
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.
linter seems to be failing in CI, but changes look good to me!
33b9ec0
to
62d23b2
Compare
a842708
to
3043ca3
Compare
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
ebffc47
to
3950fbf
Compare
3950fbf
to
0dd3667
Compare
Description
Calling
proto.Marshal
requires calling reflection code, where theVT
methods are called directly and are more efficient. This adds a linter that enforces that.Note
The exclusions ended up being fairly broad because of the size of the excluded packages. One thing that was discussed was implementing
// nolint
comments for this analyzer, but that would require either writing that manually into the analyzer or making use of a package that provides that functionality, and I wasn't sure whether we wanted to take that on right now.Changes
Testing
Review the code. See that lints go green.