Skip to content

chore: migrate to golangci-lint/v2 #1431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
380 changes: 192 additions & 188 deletions .github/config/golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,204 +1,208 @@
version: "2"
run:
timeout: 10m
issues-exit-code: 2
tests: false
allow-parallel-runners: true
issues-exit-code: 2


linters:
enable-all: true
default: all
disable:
# We are working on it
- wrapcheck

# Logical next step
- forcetypeassert # Priority: that can lead to serious crashes.
- revive # Too many issues.
# It's important to at least address:
# - no camel_case
# - no this and self
# - receiver name a should be consistent
- gomoddirectives # Replacement statements are not allowed in a library.
# if it has a replace statement, other can't use the
# library at all (go does not allow that)
- godox # TODO/FIXME/BUG should not be in the code-base without
# a related GitHub issue.
# Added an exclude-rules for that, if a TODO/FIXME/BUG
# line has an URL on the line, it counts as valid mark.
- errcheck # Too many issues.
- stylecheck # Too many issues.
# No snake_case in Go.
# convert_ComponentReferences_from should be convertComponentReferencesFrom
- prealloc # Performance.
- exportloopref
- nilerr # There a few places where we don't return with an error
# in an 'if err != nil {}' block. If it's intentional,
# we should add a '//nolint: nilerr // Reason why...'
- nlreturn # Use empty line at least before return/break/continue.
- err113 # Do not define dynamic errors with Errorf.
- varnamelen # m, d, p < These are not so meaningful variables.
- testpackage # Blackbox testing is preferred.
- funlen # Break long functions.
- gomnd # Give constant values a name with constants.
- ireturn # Accept interface, return concrete.
- nestif # Some nexted if statements are 8 or 9 deep.
- dupl # Check code duplications.
- cyclop # Complex functions are not good.
- gochecknoinits # Init functions cause an import to have side effects,
# and side effects are hard to test,
# reduce readability and increase the complexity of code.
- gocyclo # We shouldn't have functions with complexity 51
- gocognit # Another complexity check, they check different things.
- containedctx # Struct should not contain context, action does.
- nilnil # A function should return either something valuable
# or an error, but both value and error as nil is
# useless. Like when I call it, why is it nil? Tell me
# in an error why.
- bodyclose
- unparam
- nonamedreturns # Either named return, or use simply `return`.

# Opinionated (we may want to keep it disabled)
- containedctx
- contextcheck
- cyclop
- depguard
- dogsled
- dupl
- err113
- errcheck
- errname
- exhaustive
- exhaustruct
- forcetypeassert
- funcorder
- funlen
- gochecknoglobals
- lll
- paralleltest
- tagliatelle
- wsl
- interfacebloat
- gochecknoinits
- gocognit
- gocyclo
- godot
- godox
- gomoddirectives
- iface
- inamedparam
- interfacebloat
- intrange
- ireturn
- lll
- loggercheck
- mirror
- mnd
- perfsprint


# Disabled with reason
- nakedret
- depguard
- mirror
- dogsled
- exhaustruct # Doesn't really make sense.
- exhaustive # Doesn't really make sense.
- loggercheck # Doesn't really make sense.
- goimports # acts weirdly, dci handles imports anyway
- intrange # Confusing, since manipulating a range variable in a loop does not change the number of
# iterations. Thus, an integer range is constant.

# Disabled because of generics in go 1.18
- contextcheck
- nestif
- nilerr
- nilnil
- nlreturn
- nonamedreturns
- paralleltest
- perfsprint
- prealloc
- recvcheck
- revive
- rowserrcheck
- sqlclosecheck
- tagliatelle
- testpackage
- unparam
- varnamelen
- wastedassign

# Disabled because of deprecation
- execinquery

# Seriously, who wants every comment to end in a period???
- godot

# migrating to go 1.24 causes issues with new linters, but we're going to re-wrtie the code anyway
- errname
- iface
- recvcheck
- typecheck

linters-settings:
gci:
sections:
- standard
- blank
- dot
- default
- prefix(ocm.software/ocm)
custom-order: true
funlen:
lines: 110
statements: 60
cyclop:
max-complexity: 15
skip-tests: true
nolintlint:
allow-unused: false
require-explanation: true
require-specific: false
varnamelen:
ignore-names:
- err
- wg
- id
lll:
line-length: 120
gosec:
exclude-generated: true
gocritic:
disabled-checks:
- elseif

issues:
max-issues-per-linter: 0
max-same-issues: 0
exclude-dirs:
- "hack"
# External code from containerd/containerd
- "api/tech/docker"
exclude:
- composites
exclude-rules:
- path: cmds/
linters:
- forbidigo
- text: "should not use dot imports|don't use an underscore in package name"
linters:
- golint
- source: "https://"
linters:
- lll
- text: "shadow: declaration of \"err\""
linters:
- govet
- text: "shadow: declaration of \"ok\""
linters:
- govet
- path: _test\.go
linters:
- err113
- gocyclo
- errcheck
- gosec
- dupl
- funlen
- scopelint
- text: "Spec.DeepCopyInto undefined"
linters:
- typecheck
- text: "G601: Implicit memory aliasing in for loop"
# Ignored cos why not, that was the request.
linters:
- gosec
- source: "// .* #\\d+"
linters:
- godox
- path: ignore/.*\.go
linters:
- dupword
# Deprecated algorithms and fields for extra identity field defaulting
# TODO: To be removed once v1 + v2 are removed.
- path: "cmds/.*|api/.*"
linters:
- staticcheck
text: "SA1019: jsonv1.Algorithm is deprecated"
- path: "cmds/.*|api/.*"
linters:
- staticcheck
text: "SA1019: compdesc.JsonNormalisationV1 is deprecated"
- path: "cmds/.*|api/.*"
linters:
- wrapcheck
- wsl
settings:
cyclop:
max-complexity: 15
funlen:
lines: 110
statements: 60
gocritic:
disabled-checks:
- elseif
lll:
line-length: 120
nolintlint:
require-explanation: true
require-specific: false
allow-unused: false
varnamelen:
ignore-names:
- err
- wg
- id
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- forbidigo
path: cmds/
- linters:
- golint
text: should not use dot imports|don't use an underscore in package name
- linters:
- lll
source: https://
- linters:
- govet
text: 'shadow: declaration of "err"'
- linters:
- govet
text: 'shadow: declaration of "ok"'
- linters:
- dupl
- err113
- errcheck
- funlen
- gocyclo
- gosec
- scopelint
path: _test\.go
- linters:
- gosec
text: 'G601: Implicit memory aliasing in for loop'
- linters:
- godox
source: '// .* #\d+'
- linters:
- dupword
path: ignore/.*\.go
- linters:
- staticcheck
path: cmds/.*|api/.*
text: 'SA1019: jsonv1.Algorithm is deprecated'
- linters:
- staticcheck
path: cmds/.*|api/.*
text: 'SA1019: compdesc.JsonNormalisationV1 is deprecated'
- linters:
- staticcheck
path: cmds/.*|api/.*
text: 'SA1019: jsonv2.Algorithm is deprecated'
- linters:
- staticcheck
path: cmds/.*|api/.*
text: 'SA1019: compdesc.JsonNormalisationV2 is deprecated'
- linters:
- staticcheck
path: cmds/.*|api/.*
text: 'SA1019: legacy.DefaultingOfVersionIntoExtraIdentityForDescriptor is deprecated'
- linters:
- staticcheck
path: cmds/.*|api/.*
text: 'QF1008: could remove embedded field'
- linters:
- staticcheck
path: cmds/.*|api/.*
text: 'ST1006: receiver name should'
- linters:
- staticcheck
path: cmds/.*|api/.*
text: 'ST1001: should not use dot imports'
- linters:
- staticcheck
text: "SA1019: jsonv2.Algorithm is deprecated"
- path: "cmds/.*|api/.*"
linters:
path: cmds/.*|api/.*
text: 'ST1005: error strings should not'
- linters:
- staticcheck
text: "SA1019: compdesc.JsonNormalisationV2 is deprecated"
- path: "cmds/.*|api/.*"
linters:
path: cmds/.*|api/.*
text: 'QF1001: could apply De Morgan'
- linters:
- staticcheck
text: "SA1019: legacy.DefaultingOfVersionIntoExtraIdentityForDescriptor is deprecated"

path: cmds/.*|api/.*
text: 'QF1012: Use fmt.Fprintf'
- linters:
- staticcheck
path: cmds/.*|api/.*
text: 'QF1003: could use tagged switch'
- linters:
- staticcheck
path: cmds/.*|api/.*
text: 'QF1009: probably want to use time.Time.Equal'
- path: (.+)\.go$
text: composites
- linters:
- cyclop
path: (.+)_test\.go
paths:
- hack
- api/tech/docker
- third_party$
- builtin$
- examples/*
issues:
max-issues-per-linter: 0
max-same-issues: 0
formatters:
enable:
- gci
- gofmt
- gofumpt
settings:
gci:
sections:
- standard
- blank
- dot
- default
- prefix(ocm.software/ocm)
custom-order: true
exclusions:
generated: lax
paths:
- hack
- api/tech/docker
- third_party$
- builtin$
- examples/*
Loading
Loading