1+ # copied from https://github.com/crossplane/crossplane/blob/main/.golangci.yml and
2+ # updated slightly for this repository.
13version : " 2"
4+
25output :
36 formats :
47 text :
5- path : stdout
8+ path : stderr
9+
610linters :
7- enable :
8- - asasalint
9- - asciicheck
10- - bidichk
11- - bodyclose
12- - contextcheck
13- - durationcheck
14- - errchkjson
15- - errorlint
16- - exhaustive
17- - gocheckcompilerdirectives
18- - gochecksumtype
19- - goconst
20- - gocritic
11+ default : all
12+ disable :
13+ # These are linters we'd like to enable, but that will be labor intensive to
14+ # make existing code compliant.
15+ - wrapcheck
16+ - varnamelen
17+ - testpackage
18+ - paralleltest
19+ - nilnil
20+ - funcorder
21+
22+ # Below are linters that lint for things we don't value. Each entry below
23+ # this line must have a comment explaining the rationale.
24+
25+ # These linters add whitespace in an attempt to make code more readable.
26+ # This isn't a widely accepted Go best practice, and would be laborious to
27+ # apply to existing code.
28+ - wsl
29+ - wsl_v5
30+ - nlreturn
31+
32+ # Warns about uses of fmt.Sprintf that are less performant than alternatives
33+ # such as string concatenation. We value readability more than performance
34+ # unless performance is measured to be an issue.
35+ - perfsprint
36+
37+ # This linter:
38+ #
39+ # 1. Requires errors.Is/errors.As to test equality.
40+ # 2. Requires all errors be wrapped with fmt.Errorf specifically.
41+ # 3. Disallows errors.New inline - requires package level errors.
42+ #
43+ # 1 is covered by other linters. 2 is covered by wrapcheck, which can also
44+ # handle our use of crossplane-runtime's errors package. 3 is more strict
45+ # than we need. Not every error needs to be tested for equality.
46+ - err113
47+
48+ # These linters duplicate gocognit, but calculate complexity differently.
2149 - gocyclo
22- - gosec
23- - gosmopolitan
24- - loggercheck
25- - makezero
26- - misspell
27- - musttag
28- - nakedret
29- - nilerr
30- - nilnesserr
31- - noctx
32- - nolintlint
33- - prealloc
34- - protogetter
35- - reassign
36- - recvcheck
37- - revive
38- - rowserrcheck
39- - spancheck
40- - sqlclosecheck
41- - testifylint
42- - unconvert
43- - unparam
44- - zerologlint
50+ - cyclop
51+ - nestif
52+ - funlen
53+ - maintidx
54+
55+ # Enforces max line length. It's not idiomatic to enforce a strict limit on
56+ # line length in Go. We'd prefer to lint for things that often cause long
57+ # lines, like functions with too many parameters or long parameter names
58+ # that duplicate their types.
59+ - lll
60+
61+ # Warns about struct instantiations that don't specify every field. Could be
62+ # useful in theory to catch fields that are accidentally omitted. Seems like
63+ # it would have many more false positives than useful catches, though.
64+ - exhaustruct
65+
66+ # Warns about TODO comments. The rationale being they should be issues
67+ # instead. We're okay with using TODO to track minor cleanups for next time
68+ # we touch a particular file.
69+ - godox
70+
71+ # Warns about duplicated code blocks within the same file. Could be useful
72+ # to prompt folks to think about whether code should be broken out into a
73+ # function, but generally we're less worried about DRY and fine with a
74+ # little copying. We don't want to give folks the impression that we require
75+ # every duplicated code block to be factored out into a function.
76+ - dupl
77+
78+ # Warns about returning interfaces rather than concrete types. We do think
79+ # it's best to avoid returning interfaces where possible. However, at the
80+ # time of writing enabling this linter would only catch the (many) cases
81+ # where we must return an interface.
82+ - ireturn
83+
84+ # Warns about returning named variables. We do think it's best to avoid
85+ # returning named variables where possible. However, at the time of writing
86+ # enabling this linter would only catch the (many) cases where returning
87+ # named variables is useful to document what the variables are. For example
88+ # we believe it makes sense to return (ready bool) rather than just (bool)
89+ # to communicate what the bool means.
90+ - nonamedreturns
91+
92+ # Warns about using magic numbers. We do think it's best to avoid magic
93+ # numbers, but we should not be strict about it.
94+ - mnd
95+
96+ # Warns about if err := Foo(); err != nil style error checks. Seems to go
97+ # against idiomatic Go programming, which encourages this approach - e.g.
98+ # to scope errors.
99+ - noinlineerr
45100 settings :
101+ depguard :
102+ rules :
103+ no_third_party_test_libraries :
104+ list-mode : lax
105+ files :
106+ - $test
107+ deny :
108+ - pkg : github.com/stretchr/testify
109+ desc : See https://go.dev/wiki/TestComments#assert-libraries
110+ - pkg : github.com/onsi/ginkgo
111+ desc : See https://go.dev/wiki/TestComments#assert-libraries
112+ - pkg : github.com/onsi/gomega
113+ desc : See https://go.dev/wiki/TestComments#assert-libraries
46114 dupl :
47115 threshold : 100
48116 errcheck :
49117 check-type-assertions : false
50118 check-blank : false
51- exclude-functions :
52- - io/ioutil.ReadFile
53119 goconst :
54120 min-len : 3
55121 min-occurrences : 5
@@ -61,11 +127,11 @@ linters:
61127 paramsOnly : true
62128 rangeValCopy :
63129 sizeThreshold : 32
64- gocyclo :
65- min-complexity : 10
66130 govet :
67131 disable :
68132 - shadow
133+ interfacebloat :
134+ max : 5
69135 lll :
70136 tab-width : 1
71137 nakedret :
@@ -77,60 +143,96 @@ linters:
77143 simple : true
78144 range-loops : true
79145 for-loops : false
146+ tagliatelle :
147+ case :
148+ rules :
149+ json : goCamel
80150 unparam :
81151 check-exported : false
152+ unused :
153+ exported-fields-are-used : true
82154 exclusions :
83155 generated : lax
84156 rules :
85157 - linters :
86- - all
87- path : zz_generated\..+\.go$
88- - linters :
89- - dupl
158+ - containedctx
90159 - errcheck
91- - gocyclo
160+ - forcetypeassert
161+ - gochecknoglobals
162+ - gochecknoinits
163+ - gocognit
92164 - gosec
93165 - scopelint
94166 - unparam
167+ - embeddedstructfieldcheck
95168 path : _test(ing)?\.go
169+
96170 - linters :
97171 - gocritic
98172 path : _test\.go
99173 text : (unnamedResult|exitAfterDefer)
174+
175+ # These are performance optimisations rather than style issues per se.
176+ # They warn when function arguments or range values copy a lot of memory
177+ # rather than using a pointer.
100178 - linters :
101179 - gocritic
102180 text : ' (hugeParam|rangeValCopy):'
181+
182+ # This "TestMain should call os.Exit to set exit code" warning is not clever
183+ # enough to notice that we call a helper method that calls os.Exit.
103184 - linters :
104185 - staticcheck
105186 text : ' SA3000:'
187+
188+ # This is a "potential hardcoded credentials" warning. It's triggered by
189+ # any variable with 'secret' in the same, and thus hits a lot of false
190+ # positives in Kubernetes land where a Secret is an object type.
106191 - linters :
107192 - gosec
108193 text : ' G101:'
194+
195+ # This is an 'errors unhandled' warning that duplicates errcheck.
109196 - linters :
110197 - gosec
111198 text : ' G104:'
199+
200+ # This is about implicit memory aliasing in a range loop.
201+ # This is a false positive with Go v1.22 and above.
202+ - linters :
203+ - gosec
204+ text : ' G601:'
205+
206+ # Some k8s dependencies do not have JSON tags on all fields in structs.
112207 - linters :
113208 - musttag
114209 path : k8s.io/
210+
115211 paths :
212+ - zz_generated\..+\.go$
213+ - .+\.pb.go$
116214 - third_party$
117215 - builtin$
118- - examples$
216+ - example$
217+
119218issues :
120219 max-issues-per-linter : 0
121220 max-same-issues : 0
122221 new : false
222+
123223formatters :
124224 enable :
125225 - gci
126226 - gofmt
227+ - gofumpt
228+ - goimports
127229 settings :
128230 gci :
129231 sections :
130232 - standard
131233 - default
132- - prefix(github.com/crossplane)
133- - prefix(github.com/crossplane-contrib )
234+ - prefix(github.com/crossplane/function-sdk-go )
235+ - prefix(github.com/crossplane/function-template-go )
134236 - blank
135237 - dot
136238 custom-order : true
@@ -139,6 +241,8 @@ formatters:
139241 exclusions :
140242 generated : lax
141243 paths :
244+ - zz_generated\..+\.go$
245+ - .+\.pb.go$
142246 - third_party$
143247 - builtin$
144- - examples $
248+ - example $
0 commit comments