You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/linters.md
+91-17Lines changed: 91 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -292,39 +292,113 @@ lintersConfig:
292
292
293
293
## MarkerScope
294
294
295
-
The `markerscope` linter validates that markers are applied in the correct scope. It ensures that markers are placed on appropriate Go language constructs (types, fields) according to their intended usage.
295
+
The `markerscope` linter validates that markers are applied in the correct scope and to the correct types. It ensures that markers are placed on appropriate Go language constructs (types, fields) and applied to compatible data types according to their intended usage.
296
+
297
+
The linter performs two levels of validation:
298
+
299
+
1. **Scope validation**: Ensures markers are placed on the correct location (field vs type)
300
+
2. **Type constraint validation**: Ensures markers are applied to compatible data types (e.g., numeric markers on numeric types only)
301
+
302
+
### Scope Types
296
303
297
304
The linter defines different scope types for markers:
298
305
299
-
- **Field-only markers**: Can only be applied to struct fields (e.g., `required`, `kubebuilder:validation:Required`)
300
-
- **Type-only markers**: Can only be applied to type definitions
301
-
- **Type or Map/Slice fields**: Can be applied to type definitions, map fields, or slice fields (e.g., `kubebuilder:validation:MinProperties`)
302
-
- **Field or Type markers**: Can be applied to either fields or type definitions
306
+
- **FieldScope**: Can only be applied to struct fields (e.g., `optional`, `required`, `nullable`)
307
+
- **TypeScope**: Can only be applied to type definitions (e.g., `kubebuilder:validation:items:ExactlyOneOf`)
308
+
- **AnyScope**: Can be applied to either fields or type definitions (e.g., `kubebuilder:validation:Minimum`, `kubebuilder:validation:Pattern`)
309
+
310
+
### Type Constraints
311
+
312
+
The linter validates that markers are applied to compatible OpenAPI schema types:
313
+
314
+
- **Numeric markers** (`Minimum`, `Maximum`, `MultipleOf`): Only for `integer` or `number` types
315
+
- **String markers** (`Pattern`, `MinLength`, `MaxLength`): Only for `string` types
316
+
- **Array markers** (`MinItems`, `MaxItems`, `UniqueItems`): Only for `array` types
317
+
- **Object markers** (`MinProperties`, `MaxProperties`): Only for `object` types (struct/map)
318
+
- **Array items markers** (`items:Minimum`, `items:Pattern`, etc.): Apply constraints to array element types
0 commit comments