Skip to content

Commit 5bf7d41

Browse files
authored
Merge pull request #151 from JoelSpeed/uniquemarkers-dv-1.35
Teach uniquemarkers about 1.35 DV markers
2 parents 7ddd54c + d5d74cb commit 5bf7d41

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed

pkg/analysis/uniquemarkers/analyzer.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,5 +280,33 @@ func defaultUniqueMarkers() []UniqueMarker {
280280
},
281281
},
282282
// ------
283+
284+
// K8s-specific unique markers
285+
// ------
286+
{
287+
Identifier: markersconsts.K8sFormatMarker,
288+
},
289+
{
290+
Identifier: markersconsts.K8sMinLengthMarker,
291+
},
292+
{
293+
Identifier: markersconsts.K8sMaxLengthMarker,
294+
},
295+
{
296+
Identifier: markersconsts.K8sMinItemsMarker,
297+
},
298+
{
299+
Identifier: markersconsts.K8sMaxItemsMarker,
300+
},
301+
{
302+
Identifier: markersconsts.K8sMinimumMarker,
303+
},
304+
{
305+
Identifier: markersconsts.K8sMaximumMarker,
306+
},
307+
{
308+
Identifier: markersconsts.K8sListTypeMarker,
309+
},
310+
// ------
283311
}
284312
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package a
2+
3+
type K8s struct {
4+
// +k8s:format:=date-time
5+
UniqueFormat string
6+
7+
// +k8s:format:=date-time
8+
// +k8s:format:=password
9+
NonUniqueFormat string // want "field NonUniqueFormat has multiple definitions of marker k8s:format when only a single definition should exist"
10+
11+
// +k8s:minLength:=10
12+
UniqueMinLength string
13+
14+
// +k8s:minLength:=10
15+
// +k8s:minLength:=20
16+
NonUniqueMinLength string // want "field NonUniqueMinLength has multiple definitions of marker k8s:minLength when only a single definition should exist"
17+
18+
// +k8s:maxLength:=100
19+
UniqueMaxLength string
20+
21+
// +k8s:maxLength:=100
22+
// +k8s:maxLength:=200
23+
NonUniqueMaxLength string // want "field NonUniqueMaxLength has multiple definitions of marker k8s:maxLength when only a single definition should exist"
24+
25+
// +k8s:minItems:=10
26+
UniqueMinItems []string
27+
28+
// +k8s:minItems:=10
29+
// +k8s:minItems:=20
30+
NonUniqueMinItems []string // want "field NonUniqueMinItems has multiple definitions of marker k8s:minItems when only a single definition should exist"
31+
32+
// +k8s:maxItems:=100
33+
UniqueMaxItems []string
34+
35+
// +k8s:maxItems:=100
36+
// +k8s:maxItems:=200
37+
NonUniqueMaxItems []string // want "field NonUniqueMaxItems has multiple definitions of marker k8s:maxItems when only a single definition should exist"
38+
39+
// +k8s:listType:=map
40+
UniqueListType []string
41+
42+
// +k8s:listType:=map
43+
// +k8s:listType:=atomic
44+
NonUniqueListType []string // want "field NonUniqueListType has multiple definitions of marker k8s:listType when only a single definition should exist"
45+
}

pkg/markers/markers.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,40 @@ const (
166166

167167
// K8sRequiredMarker is the marker that indicates that a field is required in k8s declarative validation.
168168
K8sRequiredMarker = "k8s:required"
169+
170+
// K8sFormatMarker is the marker that indicates that a field has a format in k8s declarative validation.
171+
K8sFormatMarker = "k8s:format"
172+
173+
// K8sMinLengthMarker is the marker that indicates that a field has a minimum length in k8s declarative validation.
174+
K8sMinLengthMarker = "k8s:minLength"
175+
176+
// K8sMaxLengthMarker is the marker that indicates that a field has a maximum length in k8s declarative validation.
177+
K8sMaxLengthMarker = "k8s:maxLength"
178+
179+
// K8sMinItemsMarker is the marker that indicates that a field has a minimum number of items in k8s declarative validation.
180+
K8sMinItemsMarker = "k8s:minItems"
181+
182+
// K8sMaxItemsMarker is the marker that indicates that a field has a maximum number of items in k8s declarative validation.
183+
K8sMaxItemsMarker = "k8s:maxItems"
184+
185+
// K8sEnumMarker is the marker that indicates that a field has an enum in k8s declarative validation.
186+
K8sEnumMarker = "k8s:enum"
187+
188+
// K8sMinimumMarker is the marker that indicates that a field has a minimum value in k8s declarative validation.
189+
K8sMinimumMarker = "k8s:minimum"
190+
191+
// K8sMaximumMarker is the marker that indicates that a field has a maximum value in k8s declarative validation.
192+
K8sMaximumMarker = "k8s:maximum"
193+
194+
// K8sExclusiveMaximumMarker is the marker that indicates that a field has an exclusive maximum value in k8s declarative validation.
195+
K8sExclusiveMaximumMarker = "k8s:exclusiveMaximum"
196+
197+
// K8sExclusiveMinimumMarker is the marker that indicates that a field has an exclusive minimum value in k8s declarative validation.
198+
K8sExclusiveMinimumMarker = "k8s:exclusiveMinimum"
199+
200+
// K8sListTypeMarker is the marker that indicates that a field is a list in k8s declarative validation.
201+
K8sListTypeMarker = "k8s:listType"
202+
203+
// K8sListMapKeyMarker is the marker that indicates that a field is a map in k8s declarative validation.
204+
K8sListMapKeyMarker = "k8s:listMapKey"
169205
)

0 commit comments

Comments
 (0)