Skip to content

Commit 0209587

Browse files
Added enums linter
modified: docs/linters.md new file: pkg/analysis/enums/analyzer.go new file: pkg/analysis/enums/analyzer_test.go new file: pkg/analysis/enums/config.go new file: pkg/analysis/enums/doc.go new file: pkg/analysis/enums/initializer.go new file: pkg/analysis/enums/testdata/src/a/a.go new file: pkg/analysis/enums/testdata/src/b/b.go modified: pkg/registration/doc.go
1 parent f87b38e commit 0209587

File tree

9 files changed

+750
-1
lines changed

9 files changed

+750
-1
lines changed

docs/linters.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- [ConflictingMarkers](#conflictingmarkers) - Detects mutually exclusive markers on the same field
77
- [DefaultOrRequired](#defaultorrequired) - Ensures fields marked as required do not have default values
88
- [DuplicateMarkers](#duplicatemarkers) - Checks for exact duplicates of markers
9+
- [Enums](#enums) - Enforces proper usage of enumerated fields with type aliases and +enum marker
910
- [DependentTags](#dependenttags) - Enforces dependencies between markers
1011
- [ForbiddenMarkers](#forbiddenmarkers) - Checks that no forbidden markers are present on types/fields.
1112
- [Integers](#integers) - Validates usage of supported integer types
@@ -235,13 +236,34 @@ will not.
235236
The `duplicatemarkers` linter can automatically fix all markers that are exact match to another markers.
236237
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.
237238

239+
## Enums
240+
241+
The `enums` linter enforces that enumerated fields use type aliases with the `+enum` marker and that enum values follow PascalCase naming conventions.
242+
243+
This provides better API evolution, self-documentation, and validation compared to plain strings.
244+
245+
By default, `enums` is not enabled.
246+
247+
### Configuration
248+
249+
```yaml
250+
linterConfig:
251+
enums:
252+
allowlist:
253+
- kubectl
254+
- docker
255+
- helm
256+
```
257+
258+
The `allowlist` field contains enum values that should be exempt from PascalCase validation, such as command-line executable names.
259+
238260
## ForbiddenMarkers
239261

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

242264
By default, `forbiddenmarkers` is not enabled.
243265

244-
### Configuation
266+
### Configuration
245267

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

0 commit comments

Comments
 (0)