|
2 | 2 |
|
3 | 3 | - [Conditions](#conditions) - Checks that `Conditions` fields are correctly formatted
|
4 | 4 | - [CommentStart](#commentstart) - Ensures comments start with the serialized form of the type
|
| 5 | +- [ConflictingMarkers](#conflictingmarkers) - Detects mutually exclusive markers on the same field |
5 | 6 | - [DuplicateMarkers](#duplicatemarkers) - Checks for exact duplicates of markers
|
6 | 7 | - [Integers](#integers) - Validates usage of supported integer types
|
7 | 8 | - [JSONTags](#jsontags) - Ensures proper JSON tag formatting
|
@@ -73,6 +74,60 @@ The `commentstart` linter can automatically fix comments that do not start with
|
73 | 74 |
|
74 | 75 | When the `json` tag is present, and matches the first word of the field comment in all but casing, the linter will suggest that the comment be updated to match the `json` tag.
|
75 | 76 |
|
| 77 | +## ConflictingMarkers |
| 78 | + |
| 79 | +The `conflictingmarkers` linter detects and reports when mutually exclusive markers are used on the same field. |
| 80 | +This prevents common configuration errors and unexpected behavior in Kubernetes API types. |
| 81 | + |
| 82 | +The linter reports issues when markers from both sets of a conflict pair are present on the same field. |
| 83 | +It does NOT report issues when multiple markers from the same set are present - only when markers from |
| 84 | +different sets within the same conflict definition are found together. |
| 85 | + |
| 86 | +The linter is configurable and allows users to define sets of conflicting markers. |
| 87 | +Each conflict set must specify: |
| 88 | +- A unique name for the conflict |
| 89 | +- Two sets of markers that are mutually exclusive |
| 90 | +- A description explaining why the markers conflict |
| 91 | + |
| 92 | +### Configuration |
| 93 | + |
| 94 | +```yaml |
| 95 | +lintersConfig: |
| 96 | + conflictingmarkers: |
| 97 | + conflicts: |
| 98 | + - name: "optional_vs_required" |
| 99 | + setA: |
| 100 | + - "optional" |
| 101 | + - "+kubebuilder:validation:Optional" |
| 102 | + - "+k8s:validation:optional" |
| 103 | + setB: |
| 104 | + - "required" |
| 105 | + - "+kubebuilder:validation:Required" |
| 106 | + - "+k8s:validation:required" |
| 107 | + description: "A field cannot be both optional and required" |
| 108 | + - name: "default_vs_required" |
| 109 | + setA: |
| 110 | + - "default" |
| 111 | + - "+kubebuilder:default" |
| 112 | + setB: |
| 113 | + - "required" |
| 114 | + - "+kubebuilder:validation:Required" |
| 115 | + - "+k8s:validation:required" |
| 116 | + description: "A field with a default value cannot be required" |
| 117 | + - name: "my_custom_conflict" |
| 118 | + setA: |
| 119 | + - "custom:marker1" |
| 120 | + - "custom:marker2" |
| 121 | + setB: |
| 122 | + - "custom:marker3" |
| 123 | + - "custom:marker4" |
| 124 | + description: "These markers conflict because..." |
| 125 | +``` |
| 126 | + |
| 127 | +**Note**: This linter is not enabled by default and must be explicitly enabled in the configuration. |
| 128 | + |
| 129 | +The linter does not provide automatic fixes as it cannot determine which conflicting marker should be removed. |
| 130 | + |
76 | 131 | ## DuplicateMarkers
|
77 | 132 |
|
78 | 133 | The duplicatemarkers linter checks for exact duplicates of markers for types and fields.
|
|
0 commit comments