@@ -21,36 +21,24 @@ import (
2121 "sigs.k8s.io/kube-api-linter/pkg/markers"
2222)
2323
24- // ScopeConstraint defines where a marker is allowed to be placed using bit flags .
25- type ScopeConstraint uint8
24+ // ScopeConstraint defines where a marker is allowed to be placed.
25+ type ScopeConstraint string
2626
2727const (
2828 // FieldScope indicates the marker can be placed on fields.
29- FieldScope ScopeConstraint = 1 << iota
29+ FieldScope ScopeConstraint = "Field"
3030 // TypeScope indicates the marker can be placed on type definitions.
31- TypeScope
32-
31+ TypeScope ScopeConstraint = "Type"
3332 // AnyScope indicates the marker can be placed on either fields or types.
34- AnyScope = FieldScope | TypeScope
33+ AnyScope ScopeConstraint = "Any"
3534)
3635
37- // String returns a human-readable representation of the scope constraint.
38- func (s ScopeConstraint ) String () string {
39- switch s {
40- case FieldScope :
41- return "field"
42- case TypeScope :
43- return "type"
44- case AnyScope :
45- return "any"
46- default :
47- return "unknown"
48- }
49- }
50-
5136// Allows checks if the given scope is allowed by this constraint.
5237func (s ScopeConstraint ) Allows (scope ScopeConstraint ) bool {
53- return s & scope != 0
38+ if s == AnyScope {
39+ return true
40+ }
41+ return s == scope
5442}
5543
5644// TypeConstraint defines what types a marker can be applied to.
@@ -69,6 +57,10 @@ type TypeConstraint struct {
6957
7058// MarkerScopeRule defines comprehensive scope validation rules for a marker.
7159type MarkerScopeRule struct {
60+ // Name is the marker identifier (e.g., "optional", "kubebuilder:validation:Minimum").
61+ // This field is only used when MarkerScopeRule is part of a list configuration.
62+ Name string `json:"name,omitempty"`
63+
7264 // Scope specifies where the marker can be placed (field vs type).
7365 Scope ScopeConstraint
7466
@@ -89,29 +81,29 @@ type MarkerScopePolicy string
8981
9082const (
9183 // MarkerScopePolicyWarn only reports warnings without suggesting fixes.
92- MarkerScopePolicyWarn MarkerScopePolicy = "warn "
84+ MarkerScopePolicyWarn MarkerScopePolicy = "Warn "
9385
9486 // MarkerScopePolicySuggestFix reports warnings and suggests automatic fixes.
95- MarkerScopePolicySuggestFix MarkerScopePolicy = "suggest_fix "
87+ MarkerScopePolicySuggestFix MarkerScopePolicy = "SuggestFix "
9688)
9789
9890// MarkerScopeConfig contains configuration for marker scope validation.
9991type MarkerScopeConfig struct {
100- // MarkerRules maps marker names to their scope rules with scope and type constraints.
101- // This map can be used to:
92+ // MarkerRules is a list of marker rules with scope and type constraints.
93+ // This list can be used to:
10294 // - Override default rules for built-in markers (from DefaultMarkerRules)
10395 // - Add rules for custom markers not included in DefaultMarkerRules
10496 //
105- // If a marker is not in this map AND not in DefaultMarkerRules(), no scope validation is performed.
106- // If a marker is in both this map and DefaultMarkerRules(), this map takes precedence.
97+ // If a marker is not in this list AND not in DefaultMarkerRules(), no scope validation is performed.
98+ // If a marker is in both this list and DefaultMarkerRules(), this list takes precedence.
10799 //
108100 // Example: Adding a custom marker
109101 // markerRules:
110- // "mycompany:validation:CustomMarker":
102+ // - name: "mycompany:validation:CustomMarker"
111103 // scope: any
112104 // typeConstraint:
113105 // allowedSchemaTypes: ["string"]
114- MarkerRules map [ string ]MarkerScopeRule `json:"markerRules,omitempty"`
106+ MarkerRules [ ]MarkerScopeRule `json:"markerRules,omitempty"`
115107
116108 // AllowDangerousTypes specifies if dangerous types are allowed.
117109 // If true, dangerous types are allowed.
0 commit comments