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
+33-22Lines changed: 33 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -433,33 +433,52 @@ The linter includes built-in rules for all standard kubebuilder markers and k8s
433
433
434
434
### Configuration
435
435
436
-
You can customize marker rules or add support for custom markers:
436
+
You can customize marker rules or add support for custom markers.
437
+
438
+
**Scope values:**
439
+
-`Field`: Marker can only be applied to struct fields
440
+
-`Type`: Marker can only be applied to type definitions
441
+
-`Any`: Marker can be applied to either fields or type definitions
442
+
443
+
**Type constraints:**
444
+
445
+
The `typeConstraint` field allows you to restrict which Go types a marker can be applied to. This ensures that markers are only used with compatible data types (e.g., numeric markers like `Minimum` are only applied to integer/number types).
446
+
447
+
**Type constraint fields:**
448
+
-`allowedSchemaTypes`: List of allowed OpenAPI schema types (`integer`, `number`, `string`, `boolean`, `array`, `object`)
449
+
-`elementConstraint`: Nested constraint for array element types (only valid when `allowedSchemaTypes` includes `array`)
450
+
-`strictTypeConstraint`: When `true`, markers with `AnyScope` and type constraints applied to fields using named types must be declared on the type definition instead of the field. Defaults to `false`.
451
+
452
+
**Configuration example:**
437
453
438
454
```yaml
439
455
lintersConfig:
440
456
markerscope:
441
457
policy: Warn | SuggestFix # The policy for marker scope violations. Defaults to `Warn`.
442
458
allowDangerousTypes: false # Allow dangerous number types (float32, float64). Defaults to `false`.
443
-
markerRules:
444
-
# Override default rule for a built-in marker
445
-
- name: "optional"
459
+
460
+
# Override default rules for built-in markers
461
+
overrideMarkers:
462
+
- identifier: "optional"
446
463
scope: Field # or: Type, Any
447
464
448
-
# Add a custom marker with scope constraint only
449
-
- name: "mycompany:validation:CustomMarker"
465
+
# Add rules for custom markers
466
+
customMarkers:
467
+
# Custom marker with scope constraint only
468
+
- identifier: "mycompany:validation:CustomMarker"
450
469
scope: Any
451
470
452
-
#Add a custom marker with scope and type constraints
453
-
- name: "mycompany:validation:NumericLimit"
471
+
#Custom marker with scope and type constraints
472
+
- identifier: "mycompany:validation:NumericLimit"
454
473
scope: Any
455
474
strictTypeConstraint: true # Require declaration on type definition for named types
456
475
typeConstraint:
457
476
allowedSchemaTypes:
458
477
- integer
459
478
- number
460
479
461
-
#Add a custom array items marker with element type constraint
462
-
- name: "mycompany:validation:items:StringFormat"
480
+
#Custom array items marker with element type constraint
- `Field`: FieldScope - marker can only be on fields
474
-
- `Type`: TypeScope - marker can only be on types
475
-
- `Any`: AnyScope - marker can be on fields or types
476
-
477
-
**Type constraint fields:**
478
-
- `allowedSchemaTypes`: List of allowed OpenAPI schema types (`integer`, `number`, `string`, `boolean`, `array`, `object`)
479
-
- `elementConstraint`: Nested constraint for array element types (only valid when `allowedSchemaTypes` includes `array`)
480
-
- `strictTypeConstraint`: When `true`, markers with `AnyScope` and type constraints applied to fields using named types must be declared on the type definition instead of the field. Defaults to `false`.
481
-
482
-
If a marker is not in `markerRules` and not in the default rules, no validation is performed for that marker.
483
-
If a marker is in both `markerRules` and the default rules, your configuration takes precedence.
491
+
**Configuration notes:**
492
+
- Use `overrideMarkers` to customize the behavior of built-in kubebuilder/controller-runtime markers
493
+
- Use `customMarkers` to add validation for your own custom markers
494
+
- If a marker is not in either list and not in the default rules, no validation is performed for that marker
0 commit comments