Skip to content

Commit 8e61d13

Browse files
Add golangci-lint configuration + fix lint errors
- Add a configuration file for golangci-lint - Update golangci-lint in CI - Fix errors (spelling, order of imports, error messages)
1 parent 742ac1c commit 8e61d13

File tree

15 files changed

+81
-36
lines changed

15 files changed

+81
-36
lines changed

.github/workflows/pr-check.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- name: golangci-lint
1313
uses: golangci/golangci-lint-action@v2
1414
with:
15-
version: v1.34
15+
version: v1.41.1
1616

1717
build:
1818
name: Test & Build

.golangci.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
issues:
2+
exclude-use-default: true
3+
max-issues-per-linter: 50
4+
max-same-issues: 0 # disable
5+
6+
linters-settings:
7+
8+
staticcheck:
9+
go: "1.15"
10+
checks: [ "all" ]
11+
12+
stylecheck:
13+
go: "1.15"
14+
checks: [ "all" ]
15+
16+
goimports:
17+
local-prefixes: github.com/apalia/cloudstack-csi-driver
18+
19+
misspell:
20+
locale: US
21+
22+
linters:
23+
disable-all: true
24+
enable:
25+
- deadcode
26+
- errcheck
27+
- gosimple
28+
- govet
29+
- ineffassign
30+
- staticcheck
31+
- stylecheck
32+
- goimports
33+
- structcheck
34+
- typecheck
35+
- unused
36+
- varcheck
37+
- misspell

cmd/cloudstack-csi-driver/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ import (
1212
"os"
1313
"path"
1414

15-
"github.com/apalia/cloudstack-csi-driver/pkg/cloud"
16-
"github.com/apalia/cloudstack-csi-driver/pkg/driver"
1715
"go.uber.org/zap"
1816
"go.uber.org/zap/zapcore"
17+
18+
"github.com/apalia/cloudstack-csi-driver/pkg/cloud"
19+
"github.com/apalia/cloudstack-csi-driver/pkg/driver"
1920
)
2021

2122
var (

pkg/cloud/cloud.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ type VM struct {
4747

4848
// Specific errors
4949
var (
50-
ErrNotFound = errors.New("Not found")
51-
ErrTooManyResults = errors.New("Too many results")
50+
ErrNotFound = errors.New("not found")
51+
ErrTooManyResults = errors.New("too many results")
5252
)
5353

5454
// client is the implementation of Interface.

pkg/cloud/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type csConfig struct {
3434
func ReadConfig(configFilePath string) (*Config, error) {
3535
cfg := &csConfig{}
3636
if err := gcfg.ReadFileInto(cfg, configFilePath); err != nil {
37-
return nil, fmt.Errorf("Could not parse CloudStack config: %w", err)
37+
return nil, fmt.Errorf("could not parse CloudStack config: %w", err)
3838
}
3939

4040
return &Config{

pkg/cloud/fake/fake.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ package fake
55
import (
66
"context"
77

8+
"github.com/hashicorp/go-uuid"
9+
810
"github.com/apalia/cloudstack-csi-driver/pkg/cloud"
911
"github.com/apalia/cloudstack-csi-driver/pkg/util"
10-
"github.com/hashicorp/go-uuid"
1112
)
1213

1314
const zoneID = "a1887604-237c-4212-a9cd-94620b7880fa"

pkg/driver/controller.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import (
55
"fmt"
66
"math/rand"
77

8-
"github.com/apalia/cloudstack-csi-driver/pkg/cloud"
9-
"github.com/apalia/cloudstack-csi-driver/pkg/util"
108
"github.com/container-storage-interface/spec/lib/go/csi"
119
"google.golang.org/grpc/codes"
1210
"google.golang.org/grpc/status"
11+
12+
"github.com/apalia/cloudstack-csi-driver/pkg/cloud"
13+
"github.com/apalia/cloudstack-csi-driver/pkg/util"
1314
)
1415

1516
// onlyVolumeCapAccessMode is the only volume capability access
@@ -177,7 +178,7 @@ func determineSize(req *csi.CreateVolumeRequest) (int64, error) {
177178

178179
if limit := capRange.GetLimitBytes(); limit > 0 {
179180
if util.GigaBytesToBytes(sizeInGB) > limit {
180-
return 0, fmt.Errorf("After round-up, volume size %v GB exceeds the limit specified of %v bytes", sizeInGB, limit)
181+
return 0, fmt.Errorf("after round-up, volume size %v GB exceeds the limit specified of %v bytes", sizeInGB, limit)
181182
}
182183
}
183184
}

pkg/driver/driver.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
package driver
55

66
import (
7+
"go.uber.org/zap"
8+
79
"github.com/apalia/cloudstack-csi-driver/pkg/cloud"
810
"github.com/apalia/cloudstack-csi-driver/pkg/mount"
9-
"go.uber.org/zap"
1011
)
1112

1213
// Interface is the CloudStack CSI driver interface.

pkg/driver/node.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import (
66
"os"
77
"path/filepath"
88

9-
"github.com/apalia/cloudstack-csi-driver/pkg/cloud"
10-
"github.com/apalia/cloudstack-csi-driver/pkg/mount"
119
"github.com/container-storage-interface/spec/lib/go/csi"
1210
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
1311
"google.golang.org/grpc/codes"
1412
"google.golang.org/grpc/status"
13+
14+
"github.com/apalia/cloudstack-csi-driver/pkg/cloud"
15+
"github.com/apalia/cloudstack-csi-driver/pkg/mount"
1516
)
1617

1718
const (

pkg/driver/server.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ func (cs *cloudstackDriver) serve(ids csi.IdentityServer, ctrls csi.ControllerSe
2424
addr = "/" + addr
2525
}
2626
if err := os.Remove(addr); err != nil && !os.IsNotExist(err) {
27-
return fmt.Errorf("Failed to remove %s, error: %s", addr, err.Error())
27+
return fmt.Errorf("failed to remove %s, error: %s", addr, err.Error())
2828
}
2929
}
3030

3131
listener, err := net.Listen(proto, addr)
3232
if err != nil {
33-
return fmt.Errorf("Failed to listen: %w", err)
33+
return fmt.Errorf("failed to listen: %w", err)
3434
}
3535

3636
// Log every request and payloads (request + response)
@@ -66,5 +66,5 @@ func parseEndpoint(ep string) (string, string, error) {
6666
return s[0], s[1], nil
6767
}
6868
}
69-
return "", "", fmt.Errorf("Invalid endpoint: %v", ep)
69+
return "", "", fmt.Errorf("invalid endpoint: %v", ep)
7070
}

0 commit comments

Comments
 (0)