Skip to content

Commit

Permalink
refactor: enable errcheck linter (#2501)
Browse files Browse the repository at this point in the history
## Description

This change enables the errcheck linter which requires all returned
errors to be checked.

## Related Issue

Part of #2503
Depends on #2499 

## Checklist before merging

- [x] Test, docs, adr added or updated as needed
- [x] [Contributor Guide
Steps](https://github.com/defenseunicorns/zarf/blob/main/.github/CONTRIBUTING.md#developer-workflow)
followed
  • Loading branch information
phillebaba committed Jun 11, 2024
1 parent fd45291 commit 18e910d
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ run:
linters:
disable-all: true
enable:
- errcheck
- gosimple
- govet
- ineffassign
Expand Down Expand Up @@ -54,6 +55,12 @@ linters-settings:
- name: redefines-builtin-id
testifylint:
enable-all: true
errcheck:
exclude-functions:
- (*github.com/spf13/cobra.Command).Help
- (*github.com/spf13/cobra.Command).MarkFlagRequired
- (*github.com/spf13/pflag.FlagSet).MarkHidden
- (*github.com/spf13/pflag.FlagSet).MarkDeprecated
issues:
# Revive rules that are disabled by default.
include:
Expand Down
2 changes: 2 additions & 0 deletions src/internal/agent/http/admission/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func (h *Handler) Serve(hook operations.Hook) http.HandlerFunc {
return
}
w.WriteHeader(http.StatusInternalServerError)
//nolint:errcheck // ignore
w.Write(jsonResponse)
return
}
Expand Down Expand Up @@ -124,6 +125,7 @@ func (h *Handler) Serve(hook operations.Hook) http.HandlerFunc {

message.Infof(lang.AgentInfoWebhookAllowed, r.URL.Path, review.Request.Operation, result.Allowed)
w.WriteHeader(http.StatusOK)
//nolint: errcheck // ignore
w.Write(jsonResponse)
}
}
1 change: 1 addition & 0 deletions src/internal/agent/http/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func ProxyHandler() http.HandlerFunc {
if err != nil {
message.Debugf("%#v", err)
w.WriteHeader(http.StatusInternalServerError)
//nolint: errcheck // ignore
w.Write([]byte(lang.AgentErrUnableTransform))
return
}
Expand Down
1 change: 1 addition & 0 deletions src/internal/agent/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func NewProxyServer(port string) *http.Server {
func healthz() http.HandlerFunc {
return func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
//nolint: errcheck // ignore
w.Write([]byte("ok"))
}
}
1 change: 1 addition & 0 deletions src/pkg/cluster/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func TestInitZarfState(t *testing.T) {
Name: "default",
},
}
//nolint:errcheck // ignore
cs.CoreV1().ServiceAccounts(ns.Name).Create(ctx, sa, metav1.CreateOptions{})
break
}
Expand Down
6 changes: 4 additions & 2 deletions src/pkg/cluster/zarf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ func TestGetDeployedPackage(t *testing.T) {
"data": b,
},
}
c.Clientset.CoreV1().Secrets("zarf").Create(ctx, &secret, metav1.CreateOptions{})
_, err = c.Clientset.CoreV1().Secrets("zarf").Create(ctx, &secret, metav1.CreateOptions{})
require.NoError(t, err)
actual, err := c.GetDeployedPackage(ctx, p.Name)
require.NoError(t, err)
require.Equal(t, p, *actual)
Expand All @@ -242,7 +243,8 @@ func TestGetDeployedPackage(t *testing.T) {
},
},
}
c.Clientset.CoreV1().Secrets("zarf").Create(ctx, &nonPackageSecret, metav1.CreateOptions{})
_, err := c.Clientset.CoreV1().Secrets("zarf").Create(ctx, &nonPackageSecret, metav1.CreateOptions{})
require.NoError(t, err)

actualList, err := c.GetDeployedZarfPackages(ctx)
require.NoError(t, err)
Expand Down
1 change: 1 addition & 0 deletions src/pkg/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ func Table(header []string, data [][]string) {
table = append(table, pterm.TableData{row}...)
}

//nolint:errcheck // never returns an error
pterm.DefaultTable.WithHasHeader().WithData(table).Render()
}

Expand Down
1 change: 1 addition & 0 deletions src/pkg/packager/lint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func fillComponentTemplate(validator *Validator, node *composer.Node, createOpts
// [DEPRECATION] Set the Package Variable syntax as well for backward compatibility
setVarsAndWarn(types.ZarfPackageVariablePrefix, true)

//nolint: errcheck // This error should bubble up
utils.ReloadYamlTemplate(node, templateMap)
}

Expand Down
1 change: 1 addition & 0 deletions src/pkg/packager/sources/new_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func TestPackageSource(t *testing.T) {
return
}
defer f.Close()
//nolint:errcheck // ignore
io.Copy(rw, f)
}))
t.Cleanup(func() { ts.Close() })
Expand Down
1 change: 1 addition & 0 deletions src/pkg/utils/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func TestDownloadToFile(t *testing.T) {
rw.WriteHeader(http.StatusNotFound)
return
}
//nolint:errcheck // ignore
rw.Write([]byte(content))
}))
t.Cleanup(func() { srv.Close() })
Expand Down
3 changes: 2 additions & 1 deletion src/pkg/variables/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ func TestReplaceTextTemplate(t *testing.T) {
f, _ := os.Create(tc.path)
defer f.Close()

f.WriteString(start)
_, err := f.WriteString(start)
require.NoError(t, err)
}

gotErr := tc.vc.ReplaceTextTemplate(tc.path)
Expand Down
5 changes: 4 additions & 1 deletion src/pkg/zoci/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ func (r *Remote) PublishPackage(ctx context.Context, pkg *types.ZarfPackage, pat

// assumes referrers API is not supported since OCI artifact
// media type is not supported
r.Repo().SetReferrersCapability(false)
err = r.Repo().SetReferrersCapability(false)
if err != nil {
return err
}

// push the manifest config
manifestConfigDesc, err := r.CreateAndPushManifestConfig(ctx, annotations, ZarfConfigMediaType)
Expand Down
3 changes: 2 additions & 1 deletion src/test/nightly/ecr_publish_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ func TestECRPublishing(t *testing.T) {
t.Log("E2E: Testing component actions")

// Work from the root directory of the project
os.Chdir("../../../")
err := os.Chdir("../../../")
require.NoError(t, err)

// Create a tmpDir for us to use during this test
tmpDir := t.TempDir()
Expand Down

0 comments on commit 18e910d

Please sign in to comment.