Skip to content

Commit 46b1ad2

Browse files
Kieron Brownekieron-dev
Kieron Browne
authored andcommitted
Run staticcheck explicitly in make lint
It is currently part of golangci-lint, but seems to have configuration issues. If we run is directly, we can control it better, including using the recommended `//lint:ignore` directives. This also fixes or ignores staticcheck issues in the code
1 parent d0f67a2 commit 46b1ad2

File tree

14 files changed

+40
-28
lines changed

14 files changed

+40
-28
lines changed

.golangci.yml

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ linters:
2626
- dupl
2727
- ginkgolinter
2828

29+
disable:
30+
- staticcheck # we run this separately
31+
2932
issues:
3033
exclude-rules:
3134
- path: _test\.go

Makefile

+8-2
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,20 @@ fmt: install-gofumpt install-shfmt
4242
vet: ## Run go vet against code.
4343
go vet ./...
4444

45-
lint: fmt vet gosec
45+
lint: fmt vet gosec staticcheck
4646
golangci-lint run -v
4747

4848
gosec: install-gosec
4949
$(GOSEC) --exclude=G101,G304,G401,G404,G505 --exclude-dir=tests ./...
5050

51+
staticcheck: install-staticcheck
52+
$(STATICCHECK) ./...
53+
5154
test: lint
5255
@for comp in $(COMPONENTS); do make -C $$comp test; done
5356
make test-tools
5457
make test-e2e
5558

56-
5759
test-tools:
5860
./scripts/run-tests.sh tools
5961

@@ -79,5 +81,9 @@ GOSEC = $(shell go env GOPATH)/bin/gosec
7981
install-gosec:
8082
go install github.com/securego/gosec/v2/cmd/gosec@latest
8183

84+
STATICCHECK = $(shell go env GOPATH)/bin/staticcheck
85+
install-staticcheck:
86+
go install honnef.co/go/tools/cmd/staticcheck@latest
87+
8288
vendir-update-dependencies: install-vendir
8389
$(VENDIR) sync --chdir tests

api/actions/manifest/normalizer.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,21 @@ func procValIfSet[T any](appVal, procVal *T) *T {
4343

4444
func fixDeprecatedFields(appInfo *payloads.ManifestApplication) {
4545
if appInfo.DiskQuota == nil {
46-
//nolint:staticcheck
46+
//lint:ignore SA1019 we have to deal with this deprecation
4747
appInfo.DiskQuota = appInfo.AltDiskQuota
4848
}
4949

5050
for i := range appInfo.Processes {
5151
if appInfo.Processes[i].DiskQuota == nil {
52-
//nolint:staticcheck
52+
//lint:ignore SA1019 we have to deal with this deprecation
5353
appInfo.Processes[i].DiskQuota = appInfo.Processes[i].AltDiskQuota
5454
}
5555
}
5656

57-
if hasBuildpackSet(appInfo.Buildpack) { // nolint: staticcheck
58-
appInfo.Buildpacks = append(appInfo.Buildpacks, appInfo.Buildpack) // nolint: staticcheck
57+
//lint:ignore SA1019 we have to deal with this deprecation
58+
if hasBuildpackSet(appInfo.Buildpack) {
59+
//lint:ignore SA1019 we have to deal with this deprecation
60+
appInfo.Buildpacks = append(appInfo.Buildpacks, appInfo.Buildpack)
5961
}
6062
}
6163

api/actions/manifest/normalizer_test.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ var _ = Describe("Normalizer", func() {
8080

8181
When("deprecated 'buildpack' is specified", func() {
8282
BeforeEach(func() {
83-
appInfo.Buildpack = "deprecated-buildpack" // nolint: staticcheck
83+
//lint:ignore SA1019 we have to deal with this deprecation
84+
appInfo.Buildpack = "deprecated-buildpack"
8485
})
8586

8687
It("adds it to the buildpacks list", func() {
@@ -91,7 +92,8 @@ var _ = Describe("Normalizer", func() {
9192

9293
When("set to 'default'", func() {
9394
BeforeEach(func() {
94-
appInfo.Buildpack = "default" // nolint: staticcheck
95+
//lint:ignore SA1019 we have to deal with this deprecation
96+
appInfo.Buildpack = "default"
9597
})
9698

9799
It("ignores it", func() {
@@ -103,7 +105,8 @@ var _ = Describe("Normalizer", func() {
103105

104106
When("set to 'null'", func() {
105107
BeforeEach(func() {
106-
appInfo.Buildpack = "null" // nolint: staticcheck
108+
//lint:ignore SA1019 we have to deal with this deprecation
109+
appInfo.Buildpack = "null"
107110
})
108111

109112
It("ignores it", func() {
@@ -370,7 +373,7 @@ var _ = Describe("Normalizer", func() {
370373

371374
When("disk-quota is set on app", func() {
372375
BeforeEach(func() {
373-
//nolint:staticcheck
376+
//lint:ignore SA1019 we have to deal with this deprecation
374377
appInfo.AltDiskQuota = tools.PtrTo("123M")
375378
})
376379

api/authorization/testhelpers/client_cert.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package testhelpers
22

33
import (
4-
. "github.com/onsi/gomega"
4+
. "github.com/onsi/gomega" //lint:ignore ST1001 this is a test file
55
"sigs.k8s.io/controller-runtime/pkg/envtest"
66
)
77

api/config/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (c *APIConfig) validate() error {
108108

109109
if c.UserCertificateExpirationWarningDuration != "" {
110110
if _, err := time.ParseDuration(c.UserCertificateExpirationWarningDuration); err != nil {
111-
return errors.New(`Invalid duration format for userCertificateExpirationWarningDuration. Use a format like "48h"`)
111+
return errors.New(`invalid duration format for userCertificateExpirationWarningDuration. Use a format like "48h"`)
112112
}
113113
}
114114

api/config/config_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ var _ = Describe("Config", func() {
173173
})
174174

175175
It("returns an error", func() {
176-
Expect(loadErr).To(MatchError(ContainSubstring("Invalid duration format")))
176+
Expect(loadErr).To(MatchError(ContainSubstring("invalid duration format")))
177177
})
178178
})
179179

api/errors/errors.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,12 @@ type RollingDeployNotSupportedError struct {
338338
apiError
339339
}
340340

341-
func NewRollingDeployNotSupportedError(cause error) RollingDeployNotSupportedError {
341+
func NewRollingDeployNotSupportedError(runnerName string) RollingDeployNotSupportedError {
342+
detail := fmt.Sprintf("The configured runner '%s' does not support rolling deploys", runnerName)
342343
return RollingDeployNotSupportedError{
343344
apiError: apiError{
344-
cause: cause,
345345
title: "CF-RollingDeployNotSupported",
346-
detail: cause.Error(),
346+
detail: detail,
347347
code: 42000,
348348
httpStatus: http.StatusBadRequest,
349349
},

api/handlers/deployment.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package handlers
33
import (
44
"context"
55
"errors"
6-
"fmt"
76
"net/http"
87
"net/url"
98

@@ -74,15 +73,13 @@ func (h *Deployment) create(r *http.Request) (*routing.Response, error) {
7473
var notFoundErr apierrors.NotFoundError
7574
if errors.As(err, &notFoundErr) {
7675
logger.Info("Could not find RunnerInfo", "runner", h.runnerName, "error", err)
77-
ret := fmt.Errorf("The configured runner '%s' does not support rolling deploys", h.runnerName)
78-
return nil, apierrors.NewRollingDeployNotSupportedError(ret)
76+
return nil, apierrors.NewRollingDeployNotSupportedError(h.runnerName)
7977
}
8078
return nil, apierrors.LogAndReturn(logger, apierrors.ForbiddenAsNotFound(err), "Error getting runner info in repository")
8179
}
8280

8381
if !runnerInfo.Capabilities.RollingDeploy {
84-
err = fmt.Errorf("The configured runner '%s' does not support rolling deploys", h.runnerName)
85-
return nil, apierrors.LogAndReturn(logger, apierrors.NewRollingDeployNotSupportedError(err), "runner does not support rolling deploys", "name", h.runnerName)
82+
return nil, apierrors.LogAndReturn(logger, apierrors.NewRollingDeployNotSupportedError(h.runnerName), "runner does not support rolling deploys", "name", h.runnerName)
8683
}
8784

8885
deploymentCreateMessage := payload.ToMessage()

scripts/helmdoc/main.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"strings"
99

1010
"golang.org/x/exp/maps"
11+
"golang.org/x/text/cases"
12+
"golang.org/x/text/language"
1113
)
1214

1315
func printDocForSchema(schema map[string]any, indentLevel int) {
@@ -34,8 +36,7 @@ func printDocForSchema(schema map[string]any, indentLevel int) {
3436
if typeStr == "object" {
3537
typeStr = ""
3638
} else {
37-
// nolint:staticcheck
38-
typeStr = " (_" + strings.Title(typeStr) + "_)"
39+
typeStr = " (_" + cases.Title(language.AmericanEnglish).String(typeStr) + "_)"
3940
}
4041

4142
fmt.Printf("%s- `%s`%s:%s\n", indentStr, name, typeStr, desc)

tests/helpers/cache_syncing_client.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package helpers
33
import (
44
"context"
55

6-
. "github.com/onsi/ginkgo/v2"
7-
. "github.com/onsi/gomega"
6+
. "github.com/onsi/ginkgo/v2" //lint:ignore ST1001 this is a test file
7+
. "github.com/onsi/gomega" //lint:ignore ST1001 this is a test file
88
"k8s.io/apimachinery/pkg/runtime"
99
"sigs.k8s.io/controller-runtime/pkg/client"
1010
)

tests/helpers/cert_auth_header.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"math/big"
1111
"time"
1212

13-
. "github.com/onsi/gomega"
13+
. "github.com/onsi/gomega" //lint:ignore ST1001 this is a test file
1414
)
1515

1616
func CreateCertificatePEM() []byte {

tests/helpers/eventually_should_hold.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package helpers
22

33
import (
4-
. "github.com/onsi/gomega"
4+
. "github.com/onsi/gomega" //lint:ignore ST1001 this is a test file
55
)
66

77
func EventuallyShouldHold(condition func(g Gomega)) {

tests/matchers/wraps_error.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"errors"
55
"fmt"
66

7-
. "github.com/onsi/gomega"
7+
. "github.com/onsi/gomega" //lint:ignore ST1001 this is a test file
88
"github.com/onsi/gomega/format"
99
"github.com/onsi/gomega/types"
1010
)

0 commit comments

Comments
 (0)