golangci-lint: update to v1.49.0

Remove the "deadcode", "structcheck", and "varcheck" linters, as they are
deprecated:

    WARN [runner] The linter 'deadcode' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter.  Replaced by unused.
    WARN [runner] The linter 'structcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter.  Replaced by unused.
    WARN [runner] The linter 'varcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter.  Replaced by unused.
    WARN [linters context] structcheck is disabled because of generics. You can track the evolution of the generics support by following the https://github.com/golangci/golangci-lint/issues/2649.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-09-03 23:20:23 +02:00
parent 8520b322aa
commit 2f1c382a6d
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
10 changed files with 37 additions and 39 deletions

View File

@ -202,7 +202,8 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
PREFIX=/build /install.sh containerd PREFIX=/build /install.sh containerd
FROM base AS golangci_lint FROM base AS golangci_lint
ARG GOLANGCI_LINT_VERSION=v1.46.2 # FIXME: when updating golangci-lint, remove the temporary "nolint" in https://github.com/moby/moby/blob/7860686a8df15eea9def9e6189c6f9eca031bb6f/libnetwork/networkdb/cluster.go#L246
ARG GOLANGCI_LINT_VERSION=v1.49.0
RUN --mount=type=cache,target=/root/.cache/go-build \ RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \ --mount=type=cache,target=/go/pkg/mod \
GOBIN=/build/ GO111MODULE=on go install "github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINT_VERSION}" \ GOBIN=/build/ GO111MODULE=on go install "github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINT_VERSION}" \

View File

@ -5,7 +5,6 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
//nolint:structcheck
type driverQuota struct { type driverQuota struct {
quotaCtl *quota.Control quotaCtl *quota.Control
quotaOpt quota.Quota quotaOpt quota.Quota

View File

@ -39,7 +39,7 @@ const (
// Journal is a handle to an open journald journal. // Journal is a handle to an open journald journal.
type Journal struct { type Journal struct {
j *C.sd_journal j *C.sd_journal
noCopy noCopy //nolint:structcheck,unused // Exists only to mark values uncopyable for `go vet`. noCopy noCopy //nolint:unused // Exists only to mark values uncopyable for `go vet`.
} }
// Open opens the log journal for reading. // Open opens the log journal for reading.

View File

@ -63,7 +63,7 @@ type journald struct {
// Overrides for unit tests. // Overrides for unit tests.
sendToJournal func(message string, priority journal.Priority, vars map[string]string) error sendToJournal func(message string, priority journal.Priority, vars map[string]string) error
journalReadDir string //nolint:structcheck,unused // Referenced in read.go, which has more restrictive build constraints. journalReadDir string //nolint:unused // Referenced in read.go, which has more restrictive build constraints.
readSyncTimeout time.Duration readSyncTimeout time.Duration
} }

View File

@ -1,6 +1,5 @@
linters: linters:
enable: enable:
- deadcode
- depguard - depguard
- goimports - goimports
- gosec - gosec
@ -10,11 +9,9 @@ linters:
- misspell - misspell
- revive - revive
- staticcheck - staticcheck
- structcheck
- typecheck - typecheck
- unconvert - unconvert
- unused - unused
- varcheck
disable: disable:
- errcheck - errcheck
@ -36,6 +33,11 @@ linters-settings:
# The io/ioutil package has been deprecated. # The io/ioutil package has been deprecated.
# https://go.dev/doc/go1.16#ioutil # https://go.dev/doc/go1.16#ioutil
- io/ioutil - io/ioutil
revive:
rules:
# FIXME make sure all packages have a description. Currently, there's many packages without.
- name: package-comments
disabled: true
issues: issues:
# The default exclusion rules are a bit too permissive, so copying the relevant ones below # The default exclusion rules are a bit too permissive, so copying the relevant ones below
exclude-use-default: false exclude-use-default: false
@ -111,19 +113,6 @@ issues:
- text: "SA1019: httputil.ErrPersistEOF" - text: "SA1019: httputil.ErrPersistEOF"
linters: linters:
- staticcheck - staticcheck
# This code is doing some fun stuff with reflect and it trips up the linter.
- text: "field `foo` is unused"
path: "libnetwork/options/options_test.go"
linters:
- structcheck
- unused
# This field is only used on windows but is defined in a platform agnostic file.
# The linter doesn't understand that the field is used.
- text: "`resolverOnce` is unused"
path: libnetwork/network.go
linters:
- structcheck
- unused
# Maximum issues count per one linter. Set to 0 to disable. Default is 50. # Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-issues-per-linter: 0 max-issues-per-linter: 0

View File

@ -222,7 +222,7 @@ type network struct {
dbExists bool dbExists bool
persist bool persist bool
drvOnce *sync.Once drvOnce *sync.Once
resolverOnce sync.Once resolverOnce sync.Once //nolint:nolintlint,unused // only used on windows
resolver []Resolver resolver []Resolver
internal bool internal bool
attachable bool attachable bool

View File

@ -78,18 +78,24 @@ func TestGenerateMissingField(t *testing.T) {
if _, ok := err.(NoSuchFieldError); !ok { if _, ok := err.(NoSuchFieldError); !ok {
t.Fatalf("expected NoSuchFieldError, got %#v", err) t.Fatalf("expected NoSuchFieldError, got %#v", err)
} else if expected := "no field"; !strings.Contains(err.Error(), expected) { }
const expected = "no field"
if !strings.Contains(err.Error(), expected) {
t.Fatalf("expected %q in error message, got %s", expected, err.Error()) t.Fatalf("expected %q in error message, got %s", expected, err.Error())
} }
} }
func TestFieldCannotBeSet(t *testing.T) { func TestFieldCannotBeSet(t *testing.T) {
type Model struct{ foo int } //nolint:structcheck type Model struct{ foo int } //nolint:nolintlint,unused // un-exported field is used to test error-handling
_, err := GenerateFromModel(Generic{"foo": "bar"}, Model{}) _, err := GenerateFromModel(Generic{"foo": "bar"}, Model{})
if _, ok := err.(CannotSetFieldError); !ok { if _, ok := err.(CannotSetFieldError); !ok {
t.Fatalf("expected CannotSetFieldError, got %#v", err) t.Fatalf("expected CannotSetFieldError, got %#v", err)
} else if expected := "cannot set field"; !strings.Contains(err.Error(), expected) { }
const expected = "cannot set field"
if !strings.Contains(err.Error(), expected) {
t.Fatalf("expected %q in error message, got %s", expected, err.Error()) t.Fatalf("expected %q in error message, got %s", expected, err.Error())
} }
} }
@ -100,7 +106,10 @@ func TestTypeMismatchError(t *testing.T) {
if _, ok := err.(TypeMismatchError); !ok { if _, ok := err.(TypeMismatchError); !ok {
t.Fatalf("expected TypeMismatchError, got %#v", err) t.Fatalf("expected TypeMismatchError, got %#v", err)
} else if expected := "type mismatch"; !strings.Contains(err.Error(), expected) { }
const expected = "type mismatch"
if !strings.Contains(err.Error(), expected) {
t.Fatalf("expected %q in error message, got %s", expected, err.Error()) t.Fatalf("expected %q in error message, got %s", expected, err.Error())
} }
} }

View File

@ -93,12 +93,12 @@ type sandbox struct {
// These are the container configs used to customize container /etc/hosts file. // These are the container configs used to customize container /etc/hosts file.
type hostsPathConfig struct { type hostsPathConfig struct {
// Note(cpuguy83): The linter is drunk and says none of these fields are used while they are // Note(cpuguy83): The linter is drunk and says none of these fields are used while they are
hostName string //nolint:structcheck hostName string
domainName string //nolint:structcheck domainName string
hostsPath string //nolint:structcheck hostsPath string
originHostsPath string //nolint:structcheck originHostsPath string
extraHosts []extraHost //nolint:structcheck extraHosts []extraHost
parentUpdates []parentUpdate //nolint:structcheck parentUpdates []parentUpdate
} }
type parentUpdate struct { type parentUpdate struct {
@ -115,12 +115,12 @@ type extraHost struct {
// These are the container configs used to customize container /etc/resolv.conf file. // These are the container configs used to customize container /etc/resolv.conf file.
type resolvConfPathConfig struct { type resolvConfPathConfig struct {
// Note(cpuguy83): The linter is drunk and says none of these fields are used while they are // Note(cpuguy83): The linter is drunk and says none of these fields are used while they are
resolvConfPath string //nolint:structcheck resolvConfPath string
originResolvConfPath string //nolint:structcheck originResolvConfPath string
resolvConfHashFile string //nolint:structcheck resolvConfHashFile string
dnsList []string //nolint:structcheck dnsList []string
dnsSearchList []string //nolint:structcheck dnsSearchList []string
dnsOptionsList []string //nolint:structcheck dnsOptionsList []string
} }
type containerConfig struct { type containerConfig struct {

View File

@ -16,7 +16,7 @@ import (
// Same as DM_DEVICE_* enum values from libdevmapper.h // Same as DM_DEVICE_* enum values from libdevmapper.h
// //
//nolint:deadcode,unused,varcheck //nolint:unused
const ( const (
deviceCreate TaskType = iota deviceCreate TaskType = iota
deviceReload deviceReload

View File

@ -22,7 +22,7 @@ const extName = "VolumeDriver"
// This interface is only defined to generate the proxy objects. // This interface is only defined to generate the proxy objects.
// It's not intended to be public or reused. // It's not intended to be public or reused.
// //
//nolint:deadcode,unused,varcheck //nolint:unused
type volumeDriver interface { type volumeDriver interface {
// Create a volume with the given name // Create a volume with the given name
Create(name string, opts map[string]string) (err error) Create(name string, opts map[string]string) (err error)