Skip to content

Commit 336a3d9

Browse files
Fix minor staticcheck errors (#2913)
* Fix minor staticcheck errors * Increase timeout * Increase timeout * wip
1 parent fa23328 commit 336a3d9

File tree

18 files changed

+42
-72
lines changed

18 files changed

+42
-72
lines changed

.golangci.yml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@ issues:
88
max-issues-per-linter: 0
99
max-same-issues: 0
1010

11-
output:
12-
formats:
13-
text:
14-
print-issued-lines: true
15-
print-linter-name: true
16-
1711
linters:
1812
default: none
1913
enable:
@@ -25,12 +19,27 @@ linters:
2519
- unconvert # Detect redundant type conversions
2620
- unused # Detect unused constants, variables, functions and types
2721
- cyclop # Check code complexity
22+
- staticcheck # Check set of rules from staticcheck
2823
settings:
2924
unused:
30-
# Mark all struct fields that have been written to as used.
31-
field-writes-are-uses: false
25+
field-writes-are-uses: false # Mark all struct fields that have been written to as used.
3226
cyclop:
3327
max-complexity: 30
28+
staticcheck:
29+
checks:
30+
- "all"
31+
- "-QF1008" # Omit embedded fields from selector expression.
32+
- "-ST1000" # Incorrect or missing package comment.
33+
- "-ST1005" # Incorrectly formatted error string.
34+
- "-S1009" # Omit redundant nil check on slices, maps, and channels.
35+
- "-ST1019" # Importing the same package multiple times.
36+
- "-SA4009" # # A function argument is overwritten before its first use.
37+
- "-S1008" # Simplify returning boolean expression.
38+
- "-SA1029" # Inappropriate key in call to 'context.WithValue'.
39+
- "-SA1019" # Using a deprecated function, variable, constant or field.
40+
- "-ST1003" # Poorly chosen identifier.
41+
- "-ST1020" # The documentation of an exported function should start with the function's name.
42+
- "-ST1012" # Poorly chosen name for error variable.
3443
formatters:
3544
enable:
3645
- goimports

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
GOLINT_VER = v2.8.0
22
ifeq (,$(GOLINT_TIMEOUT))
3-
GOLINT_TIMEOUT=2m
3+
GOLINT_TIMEOUT=4m
44
endif
55

66
ifndef ARTIFACTS

internal/archive/service.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ func NewService(db storage.BrokerStorage, dryRun bool, performDeletion bool, bat
3131
}
3232
}
3333

34-
func (s *Service) Run() (error, int, int) {
34+
func (s *Service) Run() (int, int, error) {
3535
l := slog.New(slog.NewJSONHandler(os.Stdout, nil))
3636

3737
instanceIDs, err := s.instances.ListDeletedInstanceIDs(s.batchSize)
3838
if err != nil {
3939
slog.Error(fmt.Sprintf("Unable to get instance IDs: %s", err.Error()))
40-
return err, 0, 0
40+
return 0, 0, err
4141
}
4242
l.Info(fmt.Sprintf("Got %d instance IDs to process", len(instanceIDs)))
4343

@@ -51,10 +51,10 @@ func (s *Service) Run() (error, int, int) {
5151
if errInstance == nil {
5252
logger.Error(fmt.Sprintf("the instance (createdAt: %s, planName: %s) still exists, aborting the process",
5353
instance.InstanceID, instance.CreatedAt))
54-
return fmt.Errorf("instance exists"), numberOfInstancesProcessed, numberOfOperationsDeleted
54+
return numberOfInstancesProcessed, numberOfOperationsDeleted, fmt.Errorf("instance exists")
5555
}
5656
if !dberr.IsNotFound(errInstance) {
57-
return errInstance, numberOfInstancesProcessed, numberOfOperationsDeleted
57+
return numberOfInstancesProcessed, numberOfOperationsDeleted, errInstance
5858
}
5959

6060
operations, err := s.operations.ListOperationsByInstanceID(instanceId)
@@ -110,5 +110,5 @@ func (s *Service) Run() (error, int, int) {
110110
numberOfInstancesProcessed++
111111
}
112112

113-
return nil, numberOfInstancesProcessed, numberOfOperationsDeleted
113+
return numberOfInstancesProcessed, numberOfOperationsDeleted, nil
114114
}

internal/archive/service_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestService_Run(t *testing.T) {
2828
service := NewService(db, false, true, 10)
2929

3030
// when
31-
err, numberOfInstancesProcessed, numberOfOperationsDeleted := service.Run()
31+
numberOfInstancesProcessed, numberOfOperationsDeleted, err := service.Run()
3232

3333
// then
3434
require.NoError(t, err)

internal/broker/bind_create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (b *BindingContext) CreatedBy() string {
6262
}
6363

6464
type BindingParams struct {
65-
ExpirationSeconds int `json:"expiration_seconds,omit"`
65+
ExpirationSeconds int `json:"expiration_seconds,omitempty"`
6666
}
6767

6868
type Credentials struct {

internal/cis/fake_server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111

1212
func TestCisFakeServer(t *testing.T) {
1313
srv, err := NewFakeServer()
14-
defer srv.Close()
1514
require.NoError(t, err)
15+
defer srv.Close()
1616

1717
client := srv.Client()
1818

internal/docker_helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func NewDockerHandler() (*DockerHelper, error) {
2727
if err != nil {
2828
return nil, err
2929
}
30-
fmt.Println(fmt.Sprintf("host is -> %s", dockerClient.DaemonHost()))
30+
fmt.Println("host is ->", dockerClient.DaemonHost())
3131

3232
return &DockerHelper{
3333
client: dockerClient,

internal/error/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type ErrorReporter interface {
2020
GetComponent() Component
2121
}
2222

23-
// error reporter
23+
// LastError holds information about the most recent error.
2424
type LastError struct {
2525
Message string `json:"message,omitempty"`
2626
Reason Reason `json:"reason,omitempty"`

internal/error/temporary_error.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ func IsTemporaryError(err error) bool {
3434
return ok && nfe.Temporary()
3535
}
3636

37-
// can be used for temporary error
38-
// but still storing the original error in case returned to Execute
37+
// WrapTemporaryError can be used for temporary errors,
38+
// but still stores the original error in case it's returned to Execute.
3939
type WrapTemporaryError struct {
4040
err error
4141
}
@@ -48,8 +48,8 @@ func WrapNewTemporaryError(err error) *WrapTemporaryError {
4848
return &WrapTemporaryError{err: err}
4949
}
5050

51-
func (te WrapTemporaryError) Error() string { return te.err.Error() }
52-
func (WrapTemporaryError) Temporary() bool { return true }
51+
func (wte WrapTemporaryError) Error() string { return wte.err.Error() }
52+
func (WrapTemporaryError) Temporary() bool { return true }
5353

5454
func (wte WrapTemporaryError) GetReason() Reason {
5555
return ReasonForError(wte.err, NotSet).GetReason()

internal/expiration/handler.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ func (h *handler) expireInstance(w http.ResponseWriter, req *http.Request) {
9999

100100
res := expirationResponse{suspensionOpID}
101101
httputil.WriteResponse(w, http.StatusAccepted, res)
102-
103-
return
104102
}
105103

106104
func (h *handler) setInstanceExpirationTime(instance *internal.Instance, log *slog.Logger) (*internal.Instance, error) {

0 commit comments

Comments
 (0)