Skip to content
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

refactor: enable errcheck linter #2501

Merged
merged 1 commit into from
Jun 11, 2024
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
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
AustinAbro321 marked this conversation as resolved.
Show resolved Hide resolved
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 @@

// 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

Check warning on line 58 in src/pkg/zoci/push.go

View check run for this annotation

Codecov / codecov/patch

src/pkg/zoci/push.go#L56-L58

Added lines #L56 - L58 were not covered by tests
}

// 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
Loading