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
@@ -346,39 +346,113 @@ lintersConfig:
346
346
347
347
## MarkerScope
348
348
349
-
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.
349
+
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.
350
+
351
+
The linter performs two levels of validation:
352
+
353
+
1. **Scope validation**: Ensures markers are placed on the correct location (field vs type)
354
+
2. **Type constraint validation**: Ensures markers are applied to compatible data types (e.g., numeric markers on numeric types only)
355
+
356
+
### Scope Types
350
357
351
358
The linter defines different scope types for markers:
352
359
353
-
- **Field-only markers**: Can only be applied to struct fields (e.g., `required`, `kubebuilder:validation:Required`)
354
-
- **Type-only markers**: Can only be applied to type definitions
355
-
- **Type or Map/Slice fields**: Can be applied to type definitions, map fields, or slice fields (e.g., `kubebuilder:validation:MinProperties`)
356
-
- **Field or Type markers**: Can be applied to either fields or type definitions
360
+
- **FieldScope**: Can only be applied to struct fields (e.g., `optional`, `required`, `nullable`)
361
+
- **TypeScope**: Can only be applied to type definitions (e.g., `kubebuilder:validation:items:ExactlyOneOf`)
362
+
- **AnyScope**: Can be applied to either fields or type definitions (e.g., `kubebuilder:validation:Minimum`, `kubebuilder:validation:Pattern`)
363
+
364
+
### Type Constraints
365
+
366
+
The linter validates that markers are applied to compatible OpenAPI schema types:
367
+
368
+
- **Numeric markers** (`Minimum`, `Maximum`, `MultipleOf`): Only for `integer` or `number` types
369
+
- **String markers** (`Pattern`, `MinLength`, `MaxLength`): Only for `string` types
370
+
- **Array markers** (`MinItems`, `MaxItems`, `UniqueItems`): Only for `array` types
371
+
- **Object markers** (`MinProperties`, `MaxProperties`): Only for `object` types (struct/map)
372
+
- **Array items markers** (`items:Minimum`, `items:Pattern`, etc.): Apply constraints to array element types
0 commit comments