Skip to content

Commit

Permalink
Enable errcheck linter
Browse files Browse the repository at this point in the history
  • Loading branch information
phillebaba committed May 14, 2024
1 parent e50770c commit 5611659
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 7 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
- staticcheck
Expand Down Expand Up @@ -41,6 +42,12 @@ linters-settings:
- name: unused-parameter
- name: unreachable-code
- name: redefines-builtin-id
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
5 changes: 4 additions & 1 deletion src/cmd/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ var (
Aliases: []string{"l"},
Short: lang.CmdConnectListShort,
Run: func(_ *cobra.Command, _ []string) {
cluster.NewClusterOrDie().PrintConnectTable()
err := cluster.NewClusterOrDie().PrintConnectTable()
if err != nil {
message.Fatal(err, err.Error())
}
},
}
)
Expand Down
5 changes: 4 additions & 1 deletion src/cmd/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,10 @@ var createPackageRegistryToken = &cobra.Command{

state.ArtifactServer.PushToken = token.Sha1

c.SaveZarfState(state)
err = c.SaveZarfState(state)
if err != nil {
message.Fatal(err, err.Error())
}
}
},
}
Expand Down
1 change: 1 addition & 0 deletions src/internal/agent/http/admission.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func (h *admissionHandler) 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 @@ -26,6 +26,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 @@ -60,6 +60,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"))
}
}
5 changes: 4 additions & 1 deletion src/pkg/cluster/injector.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ func (c *Cluster) loadSeedImages(imagesDir, seedImagesDir string, injectorSeedSr
return seedImages, err
}

crane.SaveOCI(img, seedImagesDir)
err = crane.SaveOCI(img, seedImagesDir)
if err != nil {
return nil, err
}

seedImages = append(seedImages, ref)

Expand Down
1 change: 1 addition & 0 deletions src/pkg/cluster/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ func (c *Cluster) DeleteZarfNamespace() {
spinner := message.NewProgressSpinner("Deleting the zarf namespace from this cluster")
defer spinner.Stop()

// nolint: errcheck // Ignore until refactoring of k8s code is completed
c.DeleteNamespace(context.TODO(), ZarfNamespaceName)
}
1 change: 1 addition & 0 deletions src/pkg/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,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 @@ -151,6 +151,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
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
6 changes: 4 additions & 2 deletions src/test/external/ext_out_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ func (suite *ExtOutClusterTestSuite) Test_2_AuthToPrivateHelmChart() {
URL: chartURL,
}
repoFile.Add(entry)
utils.WriteYaml(repoPath, repoFile, helpers.ReadWriteUser)
err = utils.WriteYaml(repoPath, repoFile, helpers.ReadWriteUser)
suite.NoError(err)

err = exec.CmdWithPrint(zarfBinPath, findImageArgs...)
suite.NoError(err, "Unable to find images, helm auth likely failed")
Expand All @@ -192,7 +193,8 @@ func (suite *ExtOutClusterTestSuite) createHelmChartInGitea(baseURL string, user
podinfoTarballPath := filepath.Join(tempDir, fmt.Sprintf("podinfo-%s.tgz", podInfoVersion))
suite.NoError(err, "Unable to package chart")

utils.DownloadToFile(fmt.Sprintf("https://stefanprodan.github.io/podinfo/podinfo-%s.tgz", podInfoVersion), podinfoTarballPath, "")
err = utils.DownloadToFile(fmt.Sprintf("https://stefanprodan.github.io/podinfo/podinfo-%s.tgz", podInfoVersion), podinfoTarballPath, "")
suite.NoError(err)
url := fmt.Sprintf("%s/api/packages/%s/helm/api/charts", baseURL, username)

file, err := os.Open(podinfoTarballPath)
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 5611659

Please sign in to comment.