You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// omitzero is the policy for the `omitzero` tag within the json tag for fields.
34
+
// This defines how the linter should handle optional fields, and whether they should have the omitzero tag or not.
35
+
// By default, all the struct fields will be expected to have the `omitzero` tag when their zero value is not an acceptable user choice.
36
+
// Note, `omitzero` tag is supported in go version starting from go 1.24.
37
+
// Note, Configure omitzero policy to 'Forbid', if using with go version less than go 1.24.
38
+
OmitZeroRequiredFieldsOmitZero`json:"omitzero"`
39
+
}
28
40
29
-
// RequiredFieldsConfig contains configuration for the requiredfields linter.
30
-
typeRequiredFieldsConfigstruct {
31
-
// pointerPolicy is the policy for pointers in required fields.
32
-
// Valid values are "Warn" and "SuggestFix".
33
-
// When set to "Warn", the linter will emit a warning if a required field is a pointer.
34
-
// When set to "SuggestFix", the linter will emit a warning if a required field is a pointer and suggest a fix.
41
+
// RequiredFieldsPointers is the configuration for pointers in required fields.
42
+
typeRequiredFieldsPointersstruct {
43
+
// policy is the policy for the pointer preferences for required fields.
44
+
// Valid values are "SuggestFix" and "Warn".
45
+
// When set to "SuggestFix", the linter will emit a warning and suggest a fix if the field is a pointer and doesn't need to be, or, where it needs to be a pointer, but isn't.
46
+
// When set to "Warn", the linter will emit a warning per the above, but without suggesting a fix.
35
47
// When otherwise not specified, the default value is "SuggestFix".
// RequiredFieldsOmitZeroPolicyForbid indicates that the linter will not consider `omitzero` tags, and will suggest to remove the `omitzero` tag if a field has it.
fieldErrors=append(fieldErrors, field.Invalid(fldPath.Child("policy"), rfc.Policy, fmt.Sprintf("invalid value, must be one of %q, %q or omitted", RequiredFieldsPointerPolicySuggestFix, RequiredFieldsPointerPolicyWarn)))
69
+
}
70
+
71
+
returnfieldErrors
72
+
}
73
+
74
+
// validateOptionFieldsOmitEmpty is used to validate the configuration in the config.OptionalFieldsOmitEmpty struct.
fieldErrors=append(fieldErrors, field.Invalid(fldPath.Child("policy"), rfc.Policy, fmt.Sprintf("invalid value, must be one of %q, %q, %q or omitted", RequiredFieldsOmitEmptyPolicyIgnore, RequiredFieldsOmitEmptyPolicyWarn, RequiredFieldsOmitEmptyPolicySuggestFix)))
82
+
}
83
+
84
+
returnfieldErrors
85
+
}
86
+
87
+
// validateRequiredFieldsOmitZero is used to validate the configuration in the config.RequiredFieldsOmitZero struct.
fieldErrors=append(fieldErrors, field.Invalid(fldPath.Child("pointerPolicy"), rfc.PointerPolicy, fmt.Sprintf("invalid value, must be one of %q, %qor omitted", RequiredFieldPointerWarn, RequiredFieldPointerSuggestFix)))
94
+
fieldErrors=append(fieldErrors, field.Invalid(fldPath.Child("policy"), rfc.Policy, fmt.Sprintf("invalid value, must be one of %q, %q, %q or omitted", RequiredFieldsOmitZeroPolicySuggestFix, RequiredFieldsOmitZeroPolicyWarn, RequiredFieldsOmitZeroPolicyForbid)))
0 commit comments