Skip to content

Commit

Permalink
build: Bump golangci-lint and enable more linters (#678)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmidyson authored Apr 8, 2024
1 parent 02c4944 commit c0d73ff
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 33 deletions.
22 changes: 20 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,54 @@ run:
linters:
disable-all: true
enable:
- asciicheck
- bidichk
- bodyclose
- containedctx
- contextcheck
- copyloopvar
- decorder
- depguard
- dogsled
- durationcheck
- errcheck
- errchkjson
- errname
- gocheckcompilerdirectives
- gochecknoinits
- errorlint
- exhaustive
- gci
- ginkgolinter
- gocheckcompilerdirectives
- gochecknoinits
- gochecksumtype
- goconst
- gocritic
- gocyclo
- godot
- gofumpt
- gomoddirectives
- gosec
- gosimple
- govet
- ineffassign
- interfacebloat
- intrange
- lll
- loggercheck
- mirror
- misspell
- musttag
- nestif
- nilerr
- nolintlint
- nosprintfhostport
- prealloc
- reassign
- staticcheck
- stylecheck
- tenv
- testableexamples
- testifylint
- thelper
- tparallel
- typecheck
Expand Down
9 changes: 5 additions & 4 deletions archive/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"archive/tar"
"bytes"
"compress/gzip"
"errors"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -40,7 +41,7 @@ func TestArchiveDirectorySuccess(t *testing.T) {
tr := tar.NewReader(gzr)
for {
hdr, err := tr.Next()
if err == io.EOF {
if errors.Is(err, io.EOF) {
break // End of archive
}
require.NoError(t, err, "error reading listing from tarball")
Expand All @@ -51,7 +52,7 @@ func TestArchiveDirectorySuccess(t *testing.T) {
_, err = io.CopyN(&buf, tr, 1024)
require.Condition(
t,
func() (success bool) { return err == nil || err == io.EOF },
func() (success bool) { return err == nil || errors.Is(err, io.EOF) },
"error reading content from tarball",
)
archivedContents[hdr.Name] = buf.String()
Expand Down Expand Up @@ -81,7 +82,7 @@ func TestArchiveDirectoryToTarSuccess(t *testing.T) {
tr := tar.NewReader(f)
for {
hdr, err := tr.Next()
if err == io.EOF {
if errors.Is(err, io.EOF) {
break // End of archive
}
require.NoError(t, err, "error reading listing from tarball")
Expand All @@ -92,7 +93,7 @@ func TestArchiveDirectoryToTarSuccess(t *testing.T) {
_, err = io.CopyN(&buf, tr, 1024)
require.Condition(
t,
func() (success bool) { return err == nil || err == io.EOF },
func() (success bool) { return err == nil || errors.Is(err, io.EOF) },
"error reading content from tarball",
)
archivedContents[hdr.Name] = buf.String()
Expand Down
4 changes: 2 additions & 2 deletions cmd/mindthegap/create/helmbundle/helm_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func NewCommand(out output.Output) *cobra.Command {
)
if err != nil {
out.EndOperationWithStatus(output.Failure())
return fmt.Errorf("failed to create Helm chart bundle: %v", err)
return fmt.Errorf("failed to create Helm chart bundle: %w", err)
}

if err := helmClient.PushHelmChartToOCIRegistry(
Expand Down Expand Up @@ -199,7 +199,7 @@ func NewCommand(out output.Output) *cobra.Command {
)
if err != nil {
out.EndOperationWithStatus(output.Failure())
return fmt.Errorf("failed to create Helm chart bundle: %v", err)
return fmt.Errorf("failed to create Helm chart bundle: %w", err)
}

chrt, err := helm.LoadChart(downloaded)
Expand Down
3 changes: 1 addition & 2 deletions cmd/mindthegap/flags/custom_flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ func Test_parsePossibleURI(t *testing.T) {
expectedPath: "/dkp",
},
}
for ti := range tests {
tt := tests[ti]
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
scheme, address, host, path, _ := parsePossibleURI(tt.in)
Expand Down
2 changes: 1 addition & 1 deletion cmd/mindthegap/push/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func pushImages(
) error {
puller, err := remote.NewPuller(destRemoteOpts...)
if err != nil {
return nil
return err
}

// Sort registries for deterministic ordering.
Expand Down
4 changes: 3 additions & 1 deletion cmd/mindthegap/serve/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package bundle

import (
"errors"
"fmt"
"net/http"
"os"
Expand Down Expand Up @@ -102,7 +103,8 @@ func NewCommand(
out.Infof("Listening on %s\n", reg.Address())

go func() {
if err := reg.ListenAndServe(); err != nil && err != http.ErrServerClosed {
if err := reg.ListenAndServe(); err != nil &&
!errors.Is(err, http.ErrServerClosed) {
out.Error(err, "error serving Docker registry")
os.Exit(2)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/mindthegap/utils/glob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ func TestFilesWithGlobs(t *testing.T) {
expectedOutput: combinedCreatedFiles,
},
}
for ti := range tests {
tt := tests[ti]
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
out, err := FilesWithGlobs(tt.in)
Expand Down
6 changes: 2 additions & 4 deletions config/helm_charts_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ func TestParseHelmChartsFile(t *testing.T) {
},
},
}}
for ti := range tests {
tt := tests[ti]
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
ext := "yaml"
Expand Down Expand Up @@ -324,8 +323,7 @@ func TestMergeHelmConfig(t *testing.T) {
},
}

for ti := range tests {
tt := tests[ti]
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got := tt.src.Merge(tt.with)
Expand Down
2 changes: 0 additions & 2 deletions docker/ecr/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func TestIsECRRegistry(t *testing.T) {
want: true,
}}
for _, tt := range tests {
tt := tt // Capture range variable.
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := IsECRRegistry(tt.registryAddress); got != tt.want {
Expand Down Expand Up @@ -102,7 +101,6 @@ func TestParseECRRegistry(t *testing.T) {
wantRegion: "",
}}
for _, tt := range tests {
tt := tt // Capture range variable.
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
gotID, gotFips, gotRegion, gotErr := ParseECRRegistry(tt.registryAddress)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

module github.com/mesosphere/mindthegap

go 1.21
go 1.22

require (
github.com/aws/aws-sdk-go-v2 v1.26.1
Expand Down
12 changes: 6 additions & 6 deletions hack/flakes/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion hack/flakes/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
flake-utils.lib.eachDefaultSystem (system:
with nixpkgs.legacyPackages.${system}; rec {
packages = rec {
golangci-lint = pkgs.golangci-lint.override { buildGoModule = buildGo121Module; };
golangci-lint = pkgs.golangci-lint.override { buildGoModule = buildGo122Module; };

go-mod-upgrade = buildGo121Module rec {
name = "go-mod-upgrade";
Expand Down
2 changes: 0 additions & 2 deletions images/authnhelpers/static_keychain.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ type staticHelper struct {
authConfig *types.DockerAuthConfig
}

var _ authn.Helper = staticHelper{}

func (h staticHelper) Get(serverURL string) (username, password string, err error) {
if h.authConfig != nil && serverURL == h.registry {
password := h.authConfig.Password
Expand Down
2 changes: 1 addition & 1 deletion images/httputils/configurable_tls_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TLSConfiguredRoundTripper(
if tr.TLSClientConfig.RootCAs == nil {
systemPool, err := tlsconfig.SystemCertPool()
if err != nil {
return nil, fmt.Errorf("unable to get system cert pool: %v", err)
return nil, fmt.Errorf("unable to get system cert pool: %w", err)
}
tr.TLSClientConfig.RootCAs = systemPool
}
Expand Down
2 changes: 0 additions & 2 deletions images/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ func TestManifestListForImage_RemoteIndex(t *testing.T) {
},
}}
for _, tt := range tests {
tt := tt // Capture range variable
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
svr := httptest.NewServer(
Expand Down Expand Up @@ -411,7 +410,6 @@ func TestManifestListForImage_RemoteImage(t *testing.T) {
},
}}
for _, tt := range tests {
tt := tt // Capture range variable
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit c0d73ff

Please sign in to comment.