From 8c0f665af1255b80e3a7478d67dec03b1159b5f0 Mon Sep 17 00:00:00 2001 From: Benjamin Schimke Date: Tue, 15 Oct 2024 16:14:50 +0200 Subject: [PATCH] Enable bodyclose linter (#729) --- .golangci.yml | 18 +++++++++--------- src/k8s/pkg/client/snapd/refresh_status.go | 1 + src/k8s/pkg/utils/certificate.go | 1 + 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 3920409b8..84cc5a516 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -10,17 +10,12 @@ linters: disable-all: true enable: - gosimple + - asasalint + - asciicheck + - bidichk + - bodyclose # TODO(ben): Enable those linters step by step and fix existing issues. -# - errcheck -# - govet -# - ineffassign -# - staticcheck -# - unused -# - asasalint -# - asciicheck -# - bidichk -# - bodyclose # - canonicalheader # - containedctx # - contextcheck @@ -33,6 +28,7 @@ linters: # - dupword # - durationcheck # - err113 +# - errcheck # - errchkjson # - errname # - errorlint @@ -63,9 +59,11 @@ linters: # - goprintffuncname # - gosec # - gosmopolitan +# - govet # - grouper # - importas # - inamedparam +# - ineffassign # - interfacebloat # - intrange # - ireturn @@ -98,6 +96,7 @@ linters: # - sloglint # - spancheck # - sqlclosecheck +# - staticcheck # - stylecheck # - tagalign # - tagliatelle @@ -109,6 +108,7 @@ linters: # - tparallel # - unconvert # - unparam +# - unused # - usestdlibvars # - varnamelen # - wastedassign diff --git a/src/k8s/pkg/client/snapd/refresh_status.go b/src/k8s/pkg/client/snapd/refresh_status.go index e2feb37a7..b78b287a3 100644 --- a/src/k8s/pkg/client/snapd/refresh_status.go +++ b/src/k8s/pkg/client/snapd/refresh_status.go @@ -17,6 +17,7 @@ func (c *Client) GetRefreshStatus(changeID string) (*types.RefreshStatus, error) if err != nil { return nil, fmt.Errorf("failed to get snapd change status: %w", err) } + defer resp.Body.Close() resBody, err := io.ReadAll(resp.Body) if err != nil { diff --git a/src/k8s/pkg/utils/certificate.go b/src/k8s/pkg/utils/certificate.go index 68067ea55..2cf5fd93a 100644 --- a/src/k8s/pkg/utils/certificate.go +++ b/src/k8s/pkg/utils/certificate.go @@ -85,6 +85,7 @@ func GetRemoteCertificate(address string) (*x509.Certificate, error) { if err != nil { return nil, err } + defer resp.Body.Close() // Retrieve the certificate if resp.TLS == nil || len(resp.TLS.PeerCertificates) == 0 {