Debian Codegraph @

.golangci.yml

raw symbols SCIP
1 version: "2"
2 run:
3 # This is needed for precious, which may run multiple instances
4 # in parallel
5 go: "1.24"
6 tests: true
7 allow-parallel-runners: true
8 linters:
9 default: all
10 disable:
11 # The canonical form is not always the most common form for some headers
12 # and there is a small chance that switching existing strings could
13 # break something.
14 - canonicalheader
15
16 - cyclop
17
18 # This forbids stuff like "_, _, _, err := ...". Although I agree that it
19 # is not ideal, the actual uses in our code-base are mostly due to third-
20 # party libraries.
21 - dogsled
22
23 # This seems to primarily go off for table-driven tests for us. I don't
24 # know if more sharing between these tests would actually make the code
25 # easier to follow.
26 - dupl
27
28 # This is very helpful for linting comments, but for strings in code it
29 # is pretty questionable, e.g., we have repeated strings in GeoIP build
30 # code for org names or in test cases. We should consider enabling if
31 # they allow limiting it to certain cases in the future.
32 - dupword
33
34 # We don't follow its policy about not defining dynamic errors.
35 - err113
36
37 # We often don't initialize all of the struct fields. This is fine
38 # generally
39 - exhaustruct
40
41 # We tried this linter but most places we do forced type asserts are
42 # pretty safe, e.g., an atomic.Value when everything is encapsulated
43 # in a small package.
44 - forcetypeassert
45
46 - funlen
47 - gochecknoglobals
48 - gochecknoinits
49
50 # Similar to the exhaustive linter and I don't know that we use these
51 # sorts of sum types
52 - gochecksumtype
53
54 - gocognit
55
56 # We don't want to forbid TODO, FIXME, etc.
57 - godox
58
59 # This only "caught" one thing, and it seemed like a reasonable use
60 # of Han script. Generally, I don't think we want to prevent the use
61 # of particular scripts. The time.Local checks might be useful, but
62 # this didn't actually catch anything of note there.
63 - gosmopolitan
64
65 # Seems too opinionated or at least would require going through all the
66 # interfaces we have.
67 - inamedparam
68
69 # This is an ok rule generally, but we don't return that many interfaces
70 # and where we do, we tend to have a particular reason to do so.
71 - ireturn
72
73 # We use golines instead.
74 - lll
75
76 # Maintainability Index. Seems like it could be a good idea, but a
77 # lot of things fail and we would need to make some decisions about
78 # what to allow.
79 - maintidx
80
81 # Using a const for every number doesn't necessarily increase code clarity,
82 # and it would be a ton of work to move everything to that.
83 - mnd
84
85 # Causes panics, e.g., when processing mmerrors
86 - musttag
87
88 - nestif
89
90 # We do end up with a lot of debates on PRs about nil, nil returns. Such
91 # returns are often surprising, but there seem to be enough valid cases
92 # in our codebase that I am reluctant to enforce this.
93 - nilnil
94
95 # Checks for a new line before a return. Although that often seems helpful,
96 # there are many cases where it is not.
97 - nlreturn
98
99 # We allow inline errors in if statements as long as it stays on a single line.
100 - noinlineerr
101
102 # We occasionally use named returns for documentation, which is helpful.
103 # Named returns are only really a problem when used in conjunction with
104 # a bare return statement. I _think_ Revive's bare-return covers that
105 # case.
106 - nonamedreturns
107
108 # This is not something we want to enforce throughout our code.
109 - paralleltest
110
111 # This seems like premature optimization for most programs.
112 - prealloc
113
114 # We have very few structs with multiple tags and for the couple we had, this
115 # actually made it harder to read.
116 - tagalign
117 # We don't follow this. Sometimes we test internal code.
118 - testpackage
119 # We probably _should_ be doing this!
120 - thelper
121 - varnamelen
122
123 # Although some fixes in this seem good (e.g., err cuddling), I was
124 # not able to disable some of the less desirable whitespace changes.
125 - wsl
126 # This is a new, rewritten version of wsl. It would be worth exploring
127 # the options.
128 - wsl_v5
129
130 settings:
131 # Please note that we only use depguard for blocking packages and
132 # gomodguard for blocking modules.
133 depguard:
134 rules:
135 main:
136 # Allow if package doesn't match the deny list or, if it does, allow
137 # if the allow list rule is more specific (longer).
138 list-mode: lax
139 allow:
140 # This is the modern package for Drive.
141 - google.golang.org/api/drive/v3
142 # This is the modern package for Sheets.
143 - google.golang.org/api/sheets/v4
144 # These package are used by cloud.google.com/go package APIs.
145 - google.golang.org/api/googleapi
146 - google.golang.org/api/iterator
147 - google.golang.org/api/option
148 - google.golang.org/api/transport/http
149 deny:
150 - pkg: github.com/likexian/gokit/assert
151 desc: Use github.com/stretchr/testify/assert
152 - pkg: golang.org/x/exp/maps
153 desc: Use maps instead.
154 - pkg: golang.org/x/exp/slices
155 desc: Use slices instead.
156 - pkg: golang.org/x/exp/slog
157 desc: Use log/slog instead.
158 - pkg: google.golang.org/api
159 desc: These are maintenance mode/deprecated packages. Use cloud.google.com/go packages instead.
160 - pkg: io/ioutil
161 desc: Deprecated. Functions have been moved elsewhere.
162 - pkg: k8s.io/utils/strings/slices
163 desc: Use slices
164 - pkg: math/rand$
165 desc: Use math/rand/v2 or crypto/rand as appropriate.
166 - pkg: sort
167 desc: Use slices instead
168
169 errcheck:
170 # Don't allow setting of error to the blank identifier. If there is a legitimate
171 # reason, there should be a nolint with an explanation.
172 check-blank: true
173 exclude-functions:
174 # If we are rolling back a transaction, we are often already in an error
175 # state.
176 - (*database/sql.Tx).Rollback
177
178 # It is reasonable to ignore errors if Cleanup fails in most cases.
179 - (*github.com/google/renameio/v2.PendingFile).Cleanup
180
181 # We often do not care if unlocking failed as we are exiting anyway.
182 - (*github.com/gofrs/flock.Flock).Unlock
183
184 # We often don't care if removing a file failed (e.g., it doesn't exist)
185 - os.Remove
186 - os.RemoveAll
187
188 errchkjson:
189 report-no-exported: true
190
191 errorlint:
192 errorf: true
193 asserts: true
194 comparison: true
195
196 exhaustive:
197 default-signifies-exhaustive: true
198
199 forbidigo:
200 # Forbid the following identifiers
201 forbid:
202 - pattern: ^atomic.Value$
203 pkg: ^sync/atomic$
204 msg: Use atomic.Pointer instead.
205 - pattern: GeoFeed
206 msg: you should use the `Geofeed` qualifier instead
207 - pattern: Geoip
208 msg: you should use the `GeoIP` qualifier instead
209 - pattern: geoIP
210 msg: you should use the `geoip` qualifier instead
211 - pattern: ^hubSpot
212 msg: you should use the `hubspot` qualifier instead
213 - pattern: Maxmind
214 msg: you should use the `MaxMind` qualifier instead
215 - pattern: ^maxMind
216 msg: you should use the `maxmind` qualifier instead
217 - pattern: Minfraud
218 msg: you should use the `MinFraud` qualifier instead
219 - pattern: ^minFraud
220 msg: you should use the `minfraud` qualifier instead
221 - pattern: "[Uu]ser[iI][dD]"
222 msg: you should use the `accountID` or the `AccountID` qualifier instead
223 - pattern: WithEnterpriseURLs
224 msg: Use ghe.NewClient instead.
225 - pattern: ^bigquery.NewClient
226 msg: you should use mmgcloud.NewBigQueryClient instead.
227 - pattern: ^drive.NewService
228 msg: you should use mmgdrive.NewGDrive instead.
229 - pattern: ^filepath.Walk$
230 msg: you should use filepath.WalkDir instead as it doesn't call os.Lstat on every entry.
231 - pattern: ^math.Min$
232 msg: you should use the min built-in instead.
233 - pattern: ^mux.Vars$
234 msg: use req.PathValue instead.
235 - pattern: ^net.ParseCIDR
236 msg: you should use netip.ParsePrefix unless you really need a *net.IPNet
237 - pattern: ^net.ParseIP
238 msg: you should use netip.ParseAddr unless you really need a net.IP
239 - pattern: ^pgtype.NewMap
240 msg: you should use mmdatabase.NewTypeMap instead
241 - pattern: ^sheets.NewService
242 msg: you should use mmgcloud.NewSheetsService instead.
243 - pattern: ^storage.NewClient
244 msg: you should use gstorage.NewClient instead. This sets the HTTP client settings that we need for internal use.
245 - pattern: ^os.IsNotExist
246 msg: As per their docs, new code should use errors.Is(err, fs.ErrNotExist).
247 - pattern: ^os.IsExist
248 msg: As per their docs, new code should use errors.Is(err, fs.ErrExist)
249 - pattern: ^net.LookupIP
250 msg: You should use net.Resolver functions instead.
251 - pattern: ^net.LookupCNAME
252 msg: You should use net.Resolver functions instead.
253 - pattern: ^net.LookupHost
254 msg: You should use net.Resolver functions instead.
255 - pattern: ^net.LookupPort
256 msg: You should use net.Resolver functions instead.
257 - pattern: ^net.LookupTXT
258 msg: You should use net.Resolver functions instead.
259 - pattern: ^net.LookupAddr
260 msg: You should use net.Resolver functions instead.
261 - pattern: ^net.LookupMX
262 msg: You should use net.Resolver functions instead.
263 - pattern: ^net.LookupNS
264 msg: You should use net.Resolver functions instead.
265 - pattern: ^net.LookupSRV
266 msg: You should use net.Resolver functions instead.
267
268 funcorder:
269 constructor: true
270 # Don't require that public methods come first. The rule might make sense
271 # but we have a significant amount of existing code that violates this.
272 struct-method: false
273
274 gocritic:
275 enable-all: true
276 disabled-checks:
277 # Revive's defer rule already captures this. This caught no extra cases.
278 - deferInLoop
279
280 # Given that all of our code runs on Linux and the / separate should
281 # work fine, this seems less important.
282 - filepathJoin
283
284 # This might be good, but we would have to revisit a lot of code.
285 - hugeParam
286
287 # This might be good, but I don't think we want to encourage
288 # significant changes to regexes as we port stuff from Perl.
289 - regexpSimplify
290
291 # This seems like it might also be good, but a lot of existing code
292 # fails.
293 - sloppyReassign
294
295 # I am not sure we would want this linter and a lot of existing
296 # code fails.
297 - unnamedResult
298
299 # Covered by nolintlint
300 - whyNoLint
301
302 gomoddirectives:
303 replace-allow-list:
304 # We want to use an old version due to race conditions in the latest
305 # release.
306 - github.com/fsnotify/fsnotify
307 # We want to use an old version due to a logging issue.
308 - github.com/snowflakedb/gosnowflake
309 toolchain-forbidden: true
310 go-version-pattern: \d\.\d+(\.0)?
311
312 # IMPORTANT: gomodguard blocks _modules_, not arbitrary packages. Be
313 # sure to use the module path from the go.mod file for these.
314 # See https://github.com/ryancurrah/gomodguard/issues/12
315 gomodguard:
316 blocked:
317 modules:
318 - github.com/avct/uasurfer:
319 recommendations:
320 - github.com/xavivars/uasurfer
321 reason: The original avct module appears abandoned.
322 - github.com/BurntSushi/toml:
323 recommendations:
324 - github.com/pelletier/go-toml/v2
325 reason: This library panics frequently on invalid input.
326 - github.com/pelletier/go-toml:
327 recommendations:
328 - github.com/pelletier/go-toml/v2
329 reason: This is an outdated version.
330 - github.com/gofrs/uuid:
331 recommendations:
332 - github.com/google/uuid
333 - github.com/gofrs/uuid/v5:
334 recommendations:
335 - github.com/google/uuid
336 - github.com/satori/go.uuid:
337 recommendations:
338 - github.com/google/uuid
339 - github.com/google/uuid:
340 recommendations:
341 - github.com/google/uuid
342 - github.com/lib/pq:
343 recommendations:
344 - github.com/jackc/pgx
345 reason: This library is no longer actively maintained.
346 - github.com/neilotoole/errgroup:
347 recommendations:
348 - golang.org/x/sync/errgroup
349 reason: This library can lead to subtle deadlocks in certain use cases.
350 - github.com/pariz/gountries:
351 reason: This library's data is not actively maintained. Use GeoInfo data.
352 github.com/pkg/errors:
353 recommendations:
354 - errors
355 reason: pkg/errors is no longer maintained.
356 - github.com/RackSec/srslog:
357 recommendations:
358 - log/syslog
359 reason: This library's data is not actively maintained.
360 - github.com/ua-parser/uap-go:
361 recommendations:
362 - github.com/xavivars/uasurfer
363 reason: The performance of this library is absolutely abysmal.
364 - github.com/ugorji/go:
365 recommendations:
366 - encoding/json
367 - github.com/mailru/easyjson
368 reason: This library is poorly maintained. We should default to using encoding/json and use easyjson where performance really matters.
369 - github.com/zeebo/assert:
370 recommendations:
371 - github.com/stretchr/testify/assert
372 reason: Use github.com/stretchr/testify/assert
373 - gopkg.in/yaml.v2:
374 recommendations:
375 - github.com/goccy/go-yaml
376 reason: Not actively maintained.
377 - gopkg.in/yaml.v3:
378 recommendations:
379 - github.com/goccy/go-yaml
380 reason: Not actively maintained.
381 - gotest.tools/v3:
382 recommendations:
383 - github.com/stretchr/testify/assert
384 reason: Use github.com/stretchr/testify/assert
385 - inet.af/netaddr:
386 recommendations:
387 - net/netip
388 - go4.org/netipx
389 reason: inet.af/netaddr has been deprecated.
390 versions:
391 - github.com/jackc/pgconn:
392 reason: Use github.com/jackc/pgx/v5
393 - github.com/jackc/pgtype:
394 reason: Use github.com/jackc/pgx/v5
395 - github.com/jackc/pgx:
396 version: < 5.0.0
397 reason: Use github.com/jackc/pgx/v5
398
399 gosec:
400 excludes:
401 # G104 - "Audit errors not checked." We use errcheck for this.
402 - G104
403
404 # G306 - "Expect WriteFile permissions to be 0600 or less".
405 - G306
406
407 # Prohibits defer (*os.File).Close, which we allow when reading from file.
408 - G307
409
410 # We use md5 in geoipupdate
411 - G401
412 - G501
413
414 # no longer relevant with 1.22
415 - G601
416
417 govet:
418 disable:
419 # Although it is very useful in particular cases where we are trying to
420 # use as little memory as possible, there are even more cases where
421 # other organizations may make more sense.
422 - fieldalignment
423 enable-all: true
424 settings:
425 shadow:
426 strict: true
427
428 loggercheck:
429 # although it seems like this should remove the need for our custom
430 # Ruleguard check, it misses things that seems to catch. However, it
431 # is possible that this will catch things that misses as that check
432 # is very simple.
433 no-printf-like: true
434
435 misspell:
436 locale: US
437 extra-words:
438 - typo: marshall
439 correction: marshal
440 - typo: marshalling
441 correction: marshaling
442 - typo: marshalls
443 correction: marshals
444 - typo: unmarshall
445 correction: unmarshal
446 - typo: unmarshalling
447 correction: unmarshaling
448 - typo: unmarshalls
449 correction: unmarshals
450
451 nolintlint:
452 require-explanation: true
453 require-specific: true
454 allow-no-explanation:
455 - misspell
456 allow-unused: false
457
458 revive:
459 severity: warning
460 enable-all-rules: true
461 rules:
462 # This might be nice but it is so common that it is hard
463 # to enable.
464 - name: add-constant
465 disabled: true
466
467 - name: argument-limit
468 disabled: true
469
470 - name: cognitive-complexity
471 disabled: true
472
473 - name: comment-spacings
474 arguments:
475 - easyjson
476 - nolint
477 disabled: false
478
479 # Probably a good rule, but we have a lot of names that
480 # only have case differences.
481 - name: confusing-naming
482 disabled: true
483
484 - name: cyclomatic
485 disabled: true
486
487 # Although being consistent might be nice, I don't know that it
488 # is worth the effort enabling this rule. It doesn't have an
489 # autofix option.
490 - name: enforce-repeated-arg-type-style
491 arguments:
492 - short
493 disabled: true
494
495 - name: enforce-map-style
496 arguments:
497 - literal
498 disabled: false
499
500 # We have very few of these as we force nil slices in most places,
501 # but there are a couple of cases.
502 - name: enforce-slice-style
503 arguments:
504 - literal
505 disabled: false
506
507 - name: file-header
508 disabled: true
509
510 # We have a lot of flag parameters. This linter probably makes
511 # a good point, but we would need some cleanup or a lot of nolints.
512 - name: flag-parameter
513 disabled: true
514
515 - name: function-length
516 disabled: true
517
518 - name: function-result-limit
519 disabled: true
520
521 - name: line-length-limit
522 disabled: true
523
524 - name: max-public-structs
525 disabled: true
526
527 # We frequently use nested structs, particularly in tests.
528 - name: nested-structs
529 disabled: true
530
531 # This doesn't make sense with 1.22 loop var changes.
532 - name: range-val-address
533 disabled: true
534
535 # This flags things that do not seem like a problem, e.g. "sixHours".
536 - name: time-naming
537 disabled: true
538
539 # This causes a ton of failures. Many are fairly safe. It might be nice to
540 # enable, but probably not worth the effort.
541 - name: unchecked-type-assertion
542 disabled: true
543
544 # This seems to give many false positives.
545 - name: unconditional-recursion
546 disabled: true
547
548 # This is covered elsewhere and we want to ignore some
549 # functions such as fmt.Fprintf.
550 - name: unhandled-error
551 disabled: true
552
553 # We generally have unused receivers in tests for meeting the
554 # requirements of an interface.
555 - name: unused-receiver
556 disabled: true
557
558 # This rule seems generally good, but it is unstable. If there is a
559 # package that violates it, you cannot just add a nolint to the file
560 # that it first complains about. You need to add nolints to _every_
561 # file in that package or otherwise it will randomly faily. This in
562 # turn causes issues for nolintlint as that will randomly think all
563 # but one of those nolints are unnecessary. More discussion on Slack:
564 # https://maxmind.slack.com/archives/C07ER81BQ4T/p1751312286948379
565 #
566 # TODO: reenable if this is fixed.
567 - name: var-naming
568 disabled: true
569
570 sloglint:
571 # Enforce not mixing key-value pairs and attributes.
572 no-mixed-args: true
573
574 # Enforce not using global loggers.
575 no-global: all
576
577 # Enforce a snake case for keys.
578 key-naming-case: snake
579
580 # Make sure we don't use reserved keys.
581 forbidden-keys:
582 # These are included by our handler.
583 - time
584 - level
585 - logged_from
586 - message
587
588 # We don't use these two, but they are slog defaults. It would
589 # be better to avoid using them to reduce confusion and to make
590 # it easier to potentially use the defaults in the future.
591 - msg
592 - source
593
594 staticcheck:
595 checks:
596 - all
597
598 # SA1019: Using a deprecated function, variable, constant or field
599 #
600 # This is disabled as it interacts poorly with golangci-lint's caching.
601 # I believe https://github.com/golangci/golangci-lint-action/issues/420
602 # is the same underlying issue.
603 - -SA1019
604
605 # SA5008: unknown JSON option "intern" - easyjson specific option.
606 - -SA5008
607
608 tagliatelle:
609 case:
610 rules:
611 avro: snake
612 bson: snake
613 env: upperSnake
614 envconfig: upperSnake
615 json: snake
616 mapstructure: snake
617 xml: snake
618 yaml: snake
619
620 testifylint:
621 enable-all: true
622
623 unparam:
624 check-exported: true
625
626 usestdlibvars:
627 time-layout: true
628
629 usetesting:
630 os-temp-dir: true
631
632 wrapcheck:
633 ignore-sigs:
634 - .Errorf(
635 - errgroup.NewMultiError(
636 - errors.Join(
637 - errors.New(
638 - .Wait(
639 - .WithStack(
640 - .Wrap(
641 - .Wrapf(
642 - v5.Retry[T any](
643
644 exclusions:
645 generated: lax
646 # Warning on unused exclusions does not work well when running golangci-lint
647 # from precious as most exclusions will not be used for a particular directory.
648 # It is worth manually enabling this when cleaning up the config file though.
649 warn-unused: false
650 rules:
651 # This rule doesn't really make sense for tests where we don't have an open
652 # connection and we might be passing around the response for other reasons.
653 - linters:
654 - bodyclose
655 path: _test.go
656
657 # There are many cases where we want to just close resources and ignore the
658 # error (e.g., for defer f.Close on a read). errcheck removed its built-in
659 # wildcard ignore. I tried listing all of the cases, but it was too many
660 # and some were very specific.
661 - linters:
662 - errcheck
663 source: \.Close
664
665 # This refers to a minFraud field, not the MaxMind Account ID
666 - linters:
667 - forbidigo
668 source: "[Aa]ccountUserID|Account\\.UserID"
669
670 # we include both a source and text exclusion as the source exclusion
671 # misses matches where forbidigo reports the error on the first line
672 # of a chunk of a function call even though the use is on a later line.
673 - linters:
674 - forbidigo
675 text: "[Aa]ccountUserID|Account\\.UserID"
676
677 # The nolintlint linter behaves oddly with ruleguard rules
678 - linters:
679 - gocritic
680 source: // *no-ruleguard
681
682 # The contextcheck linter also uses "nolint" in a slightly different way,
683 # leading to falso positives from nolintlint.
684 - linters:
685 - nolintlint
686 source: //nolint:contextcheck //.*
687
688 # These are usually fine to shadow and not allowing shadowing for them can
689 # make the code unnecessarily verbose.
690 - linters:
691 - govet
692 text: 'shadow: declaration of "(ctx|err|ok)" shadows declaration'
693
694 - linters:
695 - contextcheck
696 # With recent changes to the linter, there were a lot of failures in
697 # the tests and it wasn't clear to me that fixing them would actually
698 # improve the readability.
699 - goconst
700 - nilerr
701 - wrapcheck
702 path: _test.go
703
704 # ST1016 - methods on the same type should have the same receiver name.
705 # easyjson doesn't interact well with this.
706 - linters:
707 - staticcheck
708 text: ST1016
709
710 - linters:
711 - wrapcheck
712 text: github.com/maxmind/mmdbinspect
713
714 paths:
715 - _easyjson\.go$
716 - _xgb2code\.go$
717 - _json2vector\.go$
718 - geoip-build/mmcsv
719
720 formatters:
721 enable:
722 - gci
723 - gofumpt
724 - goimports
725 - golines
726
727 settings:
728 gci:
729 sections:
730 - standard
731 - default
732 - prefix(github.com/maxmind/mmdbinspect)
733
734 gofumpt:
735 module-path: github.com/maxmind/mmdbinspect
736 extra-rules: true
737
738 goimports:
739 local-prefixes:
740 - github.com/maxmind/mmdbinspect
741
742 golines:
743 shorten-comments: true
744
745 exclusions:
746 generated: lax
747 # Warning on unused exclusions does not work well when running golangci-lint
748 # from precious as most exclusions will not be used for a particular directory.
749 # It is worth manually enabling this when cleaning up the config file though.
750 warn-unused: false