Skip to content

Commit 207a829

Browse files
Merge pull request #2522 from JoelSpeed/separate-serialization
Use separate serialization linting config for Machine API provider types
2 parents ba715f8 + 46535f0 commit 207a829

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

.golangci.go-validated.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
version: "2"
2+
linters:
3+
default: none
4+
enable:
5+
- kubeapilinter
6+
settings:
7+
custom:
8+
kubeapilinter:
9+
path: tools/_output/bin/kube-api-linter.so
10+
description: kubeapilinter is the Kube-API-Linter and lints Kube like APIs based on API conventions and best practices.
11+
settings:
12+
linters:
13+
enable:
14+
- optionalfields
15+
disable:
16+
- "*"
17+
lintersConfig:
18+
optionalfields:
19+
pointers:
20+
preference: Always
21+
policy: SuggestFix
22+
omitEmpty:
23+
# This will force omitempty on optional fields.
24+
# This is in line with upstream guidance where optional fields should be omitted
25+
# from the serialized output unless they are non-zero.
26+
policy: SuggestFix
27+
omitzero:
28+
# This will force omitzero on optional struct fields.
29+
# This means they can be omitted correctly and prevents the need for pointers to structs.
30+
policy: SuggestFix
31+
exclusions:
32+
generated: lax
33+
presets:
34+
- comments
35+
- common-false-positives
36+
- legacy
37+
- std-error-handling
38+
paths:
39+
- third_party$
40+
- builtin$
41+
- examples$
42+
rules:
43+
- linters:
44+
- kubeapilinter
45+
# This regex must always be updated in tandem with the regex in .golangci.yaml that prevents `optionalfields` from being applied to the files in the path-except.
46+
path-except: machine/v1beta1/(types_awsprovider.go|types_azureprovider.go|types_gcpprovider.go|types_vsphereprovider.go)|machine/v1alpha1/types_openstack.go
47+
issues:
48+
# We have a lot of existing issues.
49+
# Want to make sure that those adding new fields have an
50+
# opportunity to fix them when running the linter locally.
51+
max-issues-per-linter: 1000
52+
formatters:
53+
exclusions:
54+
generated: lax
55+
paths:
56+
- third_party$
57+
- builtin$
58+
- examples$

.golangci.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ linters:
7373
- third_party$
7474
- builtin$
7575
- examples$
76+
rules:
77+
- linters:
78+
- kubeapilinter
79+
# This regex must always be updated in tandem with the regex in .golangci.go-validated.yaml that prevents `optionalfields` from being applied to the files in the path.
80+
path: machine/v1beta1/(types_awsprovider.go|types_azureprovider.go|types_gcpprovider.go|types_vsphereprovider.go)|machine/v1alpha1/types_openstack.go
81+
text: "optionalfields"
7682
issues:
7783
# We have a lot of existing issues.
7884
# Want to make sure that those adding new fields have an

hack/golangci-lint.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,11 @@ if [[ ${HOME} == "/" ]]; then
1515
HOME="/tmp"
1616
fi
1717

18+
# We have two separate configs so that we can have different config for types that are go-validated vs openapi validated.
19+
# Init sets errexit so we must unset that for the rest of this script to correctly propagate the exit code.
20+
set +e
21+
1822
"${GOLANGCI_LINT}" $@
23+
status=$?
24+
25+
"${GOLANGCI_LINT}" $@ --config=.golangci.go-validated.yaml && exit ${status}

0 commit comments

Comments
 (0)