Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion docs/linters.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- [ConflictingMarkers](#conflictingmarkers) - Detects mutually exclusive markers on the same field
- [DefaultOrRequired](#defaultorrequired) - Ensures fields marked as required do not have default values
- [DuplicateMarkers](#duplicatemarkers) - Checks for exact duplicates of markers
- [Enums](#enums) - Enforces proper usage of enumerated fields with type aliases and +enum marker
- [DependentTags](#dependenttags) - Enforces dependencies between markers
- [ForbiddenMarkers](#forbiddenmarkers) - Checks that no forbidden markers are present on types/fields.
- [Integers](#integers) - Validates usage of supported integer types
Expand Down Expand Up @@ -235,13 +236,45 @@ will not.
The `duplicatemarkers` linter can automatically fix all markers that are exact match to another markers.
If there are duplicates across fields and their underlying type, the marker on the type will be preferred and the marker on the field will be removed.

## Enums
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are likely to need configuration on this linter for accepted exceptions to the rules here


The `enums` linter enforces that string type aliases used for enumerated values have proper enum markers.

**Enum Marker Types:**
- **CRD Validation Marker** (`+kubebuilder:validation:Enum`): Used for CRD validation in projects with CustomResourceDefinitions. Processed by controller-gen to generate OpenAPI schema validation.
- **Declarative Validation Marker** (`+k8s:enum`): Used in Kubernetes core API types for declarative validation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about plan +enum?


**Enum Marker Modes:**
- **Auto-discovery** (`+k8s:enum` or `+kubebuilder:validation:Enum`): Validates that constants follow PascalCase
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The kubebuilder version doesn't work like this, it must have explicit values

- **Explicit values** (`+kubebuilder:validation:Enum=Value1;Value2`): Skips constant validation

**PascalCase allows:** "Pending", "PhaseRunning", "HTTP", "IPv4" (acronyms and digits).
**PascalCase rejects:** "pending", "phase_pending", "Phase-Failed".

**Note:** The linter only flags string type aliases that have associated constants (indicating enum usage), avoiding false positives for generic string types.

By default, `enums` is enabled.

### Configuration

```yaml
linterConfig:
enums:
# Values exempt from PascalCase validation
allowlist:
- kubectl
- docker
# When true, flags plain string fields (default: false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should default to true, I think this is preferred in Kube API conventions over strings with other validation

requireTypeAliasForEnums: false
```

## ForbiddenMarkers

The `forbiddenmarkers` linter ensures that types and fields do not contain any markers that are forbidden.

By default, `forbiddenmarkers` is not enabled.

### Configuation
### Configuration

It can be configured with a list of marker identifiers and optionally their attributes and values that are forbidden.

Expand Down
Loading