Skip to content

Commit 90a97b3

Browse files
committed
Address comments
- Removed the duplicate `ConflictingMarkers` section from the linters documentation. - Eliminated the optional `Doc` field from the `ConflictingMarkersConfig` struct. - Added a new test case for a subset of conflicting markers in the test data.
1 parent ed134ff commit 90a97b3

File tree

5 files changed

+5
-68
lines changed

5 files changed

+5
-68
lines changed

docs/linters.md

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
- [StatusOptional](#statusoptional) - Ensures status fields are marked as optional
1919
- [StatusSubresource](#statussubresource) - Validates status subresource configuration
2020
- [UniqueMarkers](#uniquemarkers) - Ensures unique marker definitions
21-
- [ConflictingMarkers](#conflictingmarkers) - Detects and reports when mutually exclusive markers are used on the same field
2221

2322
## Conditions
2423

@@ -390,57 +389,3 @@ Taking the example configuration from above:
390389
- Marker definitions of `custom:SomeCustomMarker:fruit=apple,color=red` and `custom:SomeCustomMarker:fruit=orange,color=red` would _not_ violate the uniqueness requirement.
391390

392391
Each entry in `customMarkers` must have a unique `identifier`.
393-
394-
## ConflictingMarkers
395-
396-
The `conflictingmarkers` linter detects and reports when mutually exclusive markers are used on the same field.
397-
This prevents common configuration errors and unexpected behavior in Kubernetes API types.
398-
399-
The linter reports issues when markers from two or more sets of a conflict definition are present on the same field.
400-
It does NOT report issues when multiple markers from the same set are present - only when markers from
401-
different sets within the same conflict definition are found together.
402-
403-
The linter is configurable and allows users to define sets of conflicting markers.
404-
Each conflict set must specify:
405-
- A unique name for the conflict
406-
- Multiple sets of markers that are mutually exclusive with each other (at least 2 sets)
407-
- A description explaining why the markers conflict
408-
409-
### Configuration
410-
411-
```yaml
412-
lintersConfig:
413-
conflictingmarkers:
414-
conflicts:
415-
- name: "optional_vs_required"
416-
sets:
417-
- ["optional", "+kubebuilder:validation:Optional", "+k8s:validation:optional"]
418-
- ["required", "+kubebuilder:validation:Required", "+k8s:validation:required"]
419-
description: "A field cannot be both optional and required"
420-
- name: "default_vs_required"
421-
sets:
422-
- ["default", "+kubebuilder:default"]
423-
- ["required", "+kubebuilder:validation:Required", "+k8s:validation:required"]
424-
description: "A field with a default value cannot be required"
425-
- name: "three_way_conflict"
426-
sets:
427-
- ["marker5", "marker6"]
428-
- ["marker7", "marker8"]
429-
- ["marker9", "marker10"]
430-
description: "Three-way conflict between marker sets"
431-
- name: "mutually_exclusive_validation"
432-
sets:
433-
- ["optional", "+kubebuilder:validation:Optional"]
434-
- ["required", "+kubebuilder:validation:Required"]
435-
- ["default", "+kubebuilder:default"]
436-
description: "A field cannot be optional, required, and have a default value"
437-
- name: "my_custom_conflict"
438-
sets:
439-
- ["custom:marker1", "custom:marker2"]
440-
- ["custom:marker3", "custom:marker4"]
441-
description: "These markers conflict because..."
442-
```
443-
444-
**Note**: This linter is not enabled by default and must be explicitly enabled in the configuration.
445-
446-
The linter does not provide automatic fixes as it cannot determine which conflicting marker should be removed.

pkg/analysis/conflictingmarkers/analyzer.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,9 @@ func newAnalyzer(cfg *ConflictingMarkersConfig) *analysis.Analyzer {
5353
conflictSets: cfg.Conflicts,
5454
}
5555

56-
// Use configured documentation or fall back to default
57-
doc := cfg.Doc
58-
if doc == "" {
59-
doc = "Check that fields do not have conflicting markers from mutually exclusive sets"
60-
}
61-
6256
return &analysis.Analyzer{
6357
Name: name,
64-
Doc: doc,
58+
Doc: "Check that fields do not have conflicting markers from mutually exclusive sets",
6559
Run: a.run,
6660
Requires: []*analysis.Analyzer{inspector.Analyzer},
6761
}

pkg/analysis/conflictingmarkers/config.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ package conflictingmarkers
1717

1818
// ConflictingMarkersConfig contains the configuration for the conflictingmarkers linter.
1919
type ConflictingMarkersConfig struct {
20-
// Doc is the documentation string for the analyzer.
21-
// If not provided, a default description will be used.
22-
Doc string `json:"doc"`
2320
// Conflicts allows users to define sets of conflicting markers.
2421
// Each entry defines a conflict between multiple sets of markers.
2522
Conflicts []ConflictSet `json:"conflicts"`

pkg/analysis/conflictingmarkers/doc.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ Example configuration:
3535
lintersConfig:
3636
3737
conflictingmarkers:
38-
# Optional: Custom documentation for the analyzer
39-
doc: "Custom analyzer description for conflicting markers"
4038
conflicts:
4139
- name: "optional_vs_required"
4240
sets:
@@ -53,7 +51,6 @@ lintersConfig:
5351
```
5452
5553
Configuration options:
56-
- `doc`: Optional custom documentation string for the analyzer. If not provided, a default description will be used.
5754
- `conflicts`: Required list of conflict set definitions.
5855
5956
Note: This linter is not enabled by default and must be explicitly enabled in the configuration.

pkg/analysis/conflictingmarkers/testdata/src/a/a.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,8 @@ type TestStruct struct {
5757
// +marker10
5858
ThreeWayMultipleMarkersField string `json:"threeWayMultipleMarkersField"` // want "field ThreeWayMultipleMarkersField has conflicting markers: three_way_conflict: \\{\\[marker5 marker6\\], \\[marker7 marker8\\], \\[marker10 marker9\\]\\}. Three-way conflict between marker sets"
5959

60+
// Three-way conflict with only subset of sets triggered (sets 1 and 2 only)
61+
// +marker5
62+
// +marker7
63+
SubsetThreeWayConflictField string `json:"subsetThreeWayConflictField"` // want "field SubsetThreeWayConflictField has conflicting markers: three_way_conflict: \\{\\[marker5\\], \\[marker7\\]\\}. Three-way conflict between marker sets"
6064
}

0 commit comments

Comments
 (0)