-
Notifications
You must be signed in to change notification settings - Fork 21
Fix JSON tag linting for list types #171
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
base: main
Are you sure you want to change the base?
Fix JSON tag linting for list types #171
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: saschagrunert The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
The linter was incorrectly skipping JSON tag validation for list types (structs with TypeMeta, ListMeta, and Items fields). This allowed list types with missing or incorrect JSON tags to pass validation, which could cause serialization/deserialization issues. Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
896a0d7 to
7b5248f
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
| // inspectFieldsIncludingListTypes iterates over fields in structs, including list types. | ||
| // This is a custom implementation that bypasses the inspector's InspectFields helper | ||
| // to ensure list types are also linted for proper JSON tags. | ||
| func (a *analyzer) inspectFieldsIncludingListTypes( |
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.
Looks like we will iterate over all the fields we iterated on in the normal inspector again by doing this, is that right?
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.
Yes, one alternative was to change the normal inspector, but that would affect all linters, which is why I decided to keep the change scoped to jsontags.
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 guess if we are iterating again, we may as well just skip the first pass no?
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.
The alternative is to somehow have options to how the inspector iterates (maybe adding a CheckFieldsIncludingListTypes) and using that here instead? Then internally there can be some sharing?
The linter was incorrectly skipping JSON tag validation for list types (structs with TypeMeta, ListMeta, and Items fields). This allowed list types with missing or incorrect JSON tags to pass validation, which could cause serialization/deserialization issues.
Fixes #147