File tree 2 files changed +33
-0
lines changed
pkg/analysis/requiredfields 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -179,6 +179,28 @@ The `optionalorrequired` linter can automatically fix fields that are using the
179
179
180
180
It will also remove the secondary marker where both the preferred and secondary marker are present on a field.
181
181
182
+ # # RequiredFields
183
+
184
+ The `requiredfields` linter checks that fields that are marked as required, follow the convention of not being pointers,
185
+ and not having an `omitempty` value in their `json` tag.
186
+
187
+ # ## Configuration
188
+
189
+ ` ` ` yaml
190
+ lintersConfig:
191
+ requiredFields:
192
+ pointerPolicy: Warn | SuggestFix # The policy for pointers in required fields. Defaults to ` SuggestFix`.
193
+ ```
194
+
195
+ ### Fixes (via standalone binary only)
196
+
197
+ The ` requiredfields ` linter can automatically fix fields that are marked as required, but are pointers.
198
+
199
+ It will suggest to remove the pointer from the field, and update the ` json ` tag to remove the ` omitempty ` value.
200
+
201
+ If you prefer not to suggest fixes for pointers in required fields, you can change the ` pointerPolicy ` to ` Warn ` .
202
+ The linter will then only suggest to remove the ` omitempty ` value from the ` json ` tag.
203
+
182
204
# Contributing
183
205
184
206
New linters can be added by following the [ New Linter] [ new-linter ] guide.
Original file line number Diff line number Diff line change
1
+ /*
2
+ requiredFields is a linter to check that fields that are marked as required are not pointers, and do not have the omitempty tag.
3
+ The linter will check for fields that are marked as required using the +required marker, or the +kubebuilder:validation:Required marker.
4
+
5
+ The linter will suggest to remove the omitempty tag from fields that are marked as required, but have the omitempty tag.
6
+ The linter will suggest to remove the pointer type from fields that are marked as required.
7
+
8
+ If you have a large, existing codebase, you may not want to automatically fix all of the pointer issues.
9
+ In this case, you can configure the linter not to suggest fixing the pointer issues by setting the `pointerPolicy` option to `Warn`.
10
+ */
11
+ package requiredfields
You can’t perform that action at this time.
0 commit comments