Skip to content

Commit 35feb05

Browse files
committed
API changes and linter configurations
1 parent a1ab01a commit 35feb05

15 files changed

+648
-231
lines changed

.golangci-kal.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,54 @@ linters:
1414
settings:
1515
linters:
1616
enable:
17+
- "commentstart" # Ensure comments start with the serialized version of the field name.
18+
- "conditions" # Ensure conditions have the correct json tags and markers.
19+
- "conflictingmarkers"
20+
- "duplicatemarkers" # Ensure there are no exact duplicate markers. for types and fields.
21+
- "forbiddenmarkers" # Ensure that types and fields do not contain any markers that are forbidden.
22+
- "integers" # Ensure only int32 and int64 are used for integers.
23+
- "jsontags" # Ensure every field has a json tag.
24+
- "maxlength" # Ensure all strings and arrays have maximum lengths/maximum items.
25+
- "nobools" # Bools do not evolve over time, should use enums instead.
26+
- "nodurations" # Prevents usage of `Duration` types.
27+
- "nofloats" # Ensure floats are not used.
28+
- "nonullable" # Ensure that types and fields do not have the nullable marker.
1729
- "nophase" # Phase fields are discouraged by the Kube API conventions, use conditions instead.
30+
- "notimestamp" # Prevents usage of 'Timestamp' fields
31+
- "optionalfields" # Ensure that all fields marked as optional adhere to being pointers and
32+
# having the `omitempty` value in their `json` tag where appropriate.
33+
- "optionalorrequired" # Every field should be marked as `+optional` or `+required`.
34+
- "requiredfields" # Required fields should not be pointers, and should not have `omitempty`
35+
- "ssatags" # Ensure array fields have the appropriate listType markers
36+
- "statusoptional" # Ensure all first children within status should be optional.
37+
- "statussubresource" # All root objects that have a `status` field should have a status subresource.
38+
- "uniquemarkers" # Ensure that types and fields do not contain more than a single definition of a marker that should only be present once.
1839
disable:
1940
- "*" # We will manually enable new linters after understanding the impact. Disable all by default.
41+
lintersConfig:
42+
conflictingmarkers:
43+
conflicts:
44+
- name: "default_vs_required"
45+
sets:
46+
- [ "default", "kubebuilder:default" ]
47+
- [ "required", "kubebuilder:validation:Required", "k8s:required" ]
48+
description: "A field with a default value cannot be required"
49+
conditions:
50+
isFirstField: Warn # Require conditions to be the first field in the status struct.
51+
usePatchStrategy: Forbid # Forbid patchStrategy markers on the Conditions field.
52+
useProtobuf: Forbid # We don't use protobuf, so protobuf tags are not required.\
53+
forbiddenmarkers:
54+
markers:
55+
# We don't want to do any defaulting (including OpenAPI) anymore on API fields because we prefer
56+
# to have a clear signal on user intent. This also allows us to easily change the default behavior if necessary.
57+
- identifier: "kubebuilder:default"
58+
- identifier: "default"
59+
optionalfields:
60+
pointers:
61+
preference: WhenRequired # Always | WhenRequired # Whether to always require pointers, or only when required. Defaults to `Always`.
62+
policy: SuggestFix # SuggestFix | Warn # The policy for pointers in optional fields. Defaults to `SuggestFix`.
63+
omitempty:
64+
policy: SuggestFix # SuggestFix | Warn | Ignore # The policy for omitempty in optional fields. Defaults to `SuggestFix`.
2065
exclusions:
2166
generated: strict
2267
paths:

.golangci.yml

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,46 @@ run:
44
linters:
55
default: none
66
enable:
7-
- copyloopvar
8-
- dupl
9-
- errcheck
10-
- ginkgolinter
11-
- goconst
12-
- gocyclo
13-
- govet
14-
- ineffassign
15-
- lll
16-
- misspell
17-
- nakedret
18-
- prealloc
19-
- revive
20-
- staticcheck
21-
- unconvert
22-
- unparam
23-
- unused
7+
- asasalint # warns about passing []any to func(...any) without expanding it
8+
- asciicheck # non ascii symbols
9+
- bidichk # dangerous unicode sequences
10+
- bodyclose # unclosed http bodies
11+
- containedctx # context.Context nested in a struct
12+
- copyloopvar # copying loop variables
13+
- dogsled # too many blank identifiers in assignments
14+
- dupword # duplicate words
15+
- durationcheck # multiplying two durations
16+
- errcheck # unchecked errors
17+
- errchkjson # invalid types passed to json encoder
18+
- forbidigo # allows to block usage of funcs
19+
- ginkgolinter # ginkgo and gomega
20+
- gocritic # bugs, performance, style (we could add custom ones to this one)
21+
- godot # checks that comments end in a period
22+
- godox # block FIXMEs
23+
- goprintffuncname # printft-like functions should be named with f at the end
24+
- gosec # potential security problems
25+
- govet # basically 'go vet'
26+
- importas # consistent import aliases
27+
- ineffassign # ineffectual assignments
28+
- intrange # suggest using integer range in for loops
29+
- loggercheck # check for even key/value pairs in logger calls
30+
- misspell # spelling
31+
- nakedret # naked returns (named return parameters and an empty return)
32+
- nilerr # returning nil after checking err is not nil
33+
- noctx # http requests without context.Context
34+
- nolintlint # badly formatted nolint directives
35+
- nosprintfhostport # using sprintf to construct host:port in a URL
36+
- prealloc # suggest preallocating slices
37+
- predeclared # shadowing predeclared identifiers
38+
- revive # better version of golint
39+
- staticcheck # some of staticcheck's rules
40+
- thelper # test helpers not starting with t.Helper()
41+
- unconvert # unnecessary type conversions
42+
- unparam # unused function parameters
43+
- unused # unused constants, variables,functions, types
44+
- usestdlibvars # using variables/constants from the standard library
45+
- usetesting # report function to be replaced by testing
46+
- whitespace # unnecessary newlines
2447
settings:
2548
revive:
2649
rules:
@@ -36,10 +59,18 @@ linters:
3659
- dupl
3760
- lll
3861
path: internal/*
62+
- linters:
63+
- gosec
64+
path: "test/utils/"
65+
text: "G204"
66+
- linters:
67+
- noctx
68+
path: "test/utils/"
3969
paths:
4070
- third_party$
4171
- builtin$
4272
- examples$
73+
4374
formatters:
4475
enable:
4576
- gofmt

0 commit comments

Comments
 (0)