-
Notifications
You must be signed in to change notification settings - Fork 25
WIP: Fix requiredfields linter to respect OmitEmpty Ignore policy #202
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
WIP: Fix requiredfields linter to respect OmitEmpty Ignore policy #202
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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
9d9985c to
56359ee
Compare
56359ee to
25c08c5
Compare
25c08c5 to
0304415
Compare
189bf7b to
34a1c28
Compare
34a1c28 to
6f4488a
Compare
| analysistest.RunWithSuggestedFixes(t, testdata, a, "b") | ||
| } | ||
|
|
||
| func TestWhenRequiredWithOmitEmptyIgnorePreferenceConfiguration(t *testing.T) { |
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.
This test doesn't make sense anymore?
| // Force the omitempty policy to suggest a fix. We can only get to this function when the policy is configured to Ignore. | ||
| // Since we absolutely have to add the omitempty tag, we can report it as a suggestion. | ||
| reportShouldAddOmitEmpty(pass, field, OmitEmptyPolicySuggestFix, qualifiedFieldName, "field %s does not allow the zero value. It must have the omitempty tag.", 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.
Are we sure this isn't a valid case?
| }), "pointers_when_required") | ||
| } | ||
|
|
||
| func TestPointersWhenRequiredOmitEmptyIgnore(t *testing.T) { |
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.
No longer makes sense?
The OmitEmpty Ignore policy is designed to suppress style-related omitempty suggestions, but it must still enforce correctness requirements. When a field doesn't allow the zero value (e.g., has MinLength=1 validation), the field absolutely requires the omitempty tag to function correctly - without it, unstructured clients will marshal the zero value which will fail validation. This is a correctness issue, not a style preference, so it must be reported even when the policy is set to Ignore. Changes: - Restored original behavior in checkFieldPropertiesWithoutOmitEmpty to always report fields that don't allow zero values - Force OmitEmptyPolicySuggestFix for these cases regardless of policy - Restored test cases that verify this behavior - Updated test expectations to match correct behavior Fixes kubernetes-sigs#195 Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
6f4488a to
543dfc4
Compare
|
Closing this one for now, I assume we don't have to fix anything if the behavior is intended. |
When the requiredfields linter is configured with omitempty policy set to 'Ignore', violations for missing omitempty tags were still reported because checkFieldPropertiesWithoutOmitEmpty was ignoring the configured policy.
The fix ensures that when omitEmptyPolicy is Ignore, all checks for fields without omitempty are skipped, respecting the user's configuration choice.
Fixes #195