Skip to content

Commit bff2a64

Browse files
author
Andrew Kerr
authored
Add golangci-lint github action workflow file
Enable and conform to gofumpt
1 parent 966349f commit bff2a64

File tree

453 files changed

+870
-3090
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

453 files changed

+870
-3090
lines changed

.github/workflows/golangci-lint.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: golangci-lint
2+
on:
3+
pull_request:
4+
branches:
5+
- master
6+
- stable/**
7+
permissions:
8+
contents: read
9+
# Optional: allow read access to pull request. Use with `only-new-issues` option.
10+
# pull-requests: read
11+
jobs:
12+
golangci:
13+
name: lint
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/setup-go@v3
17+
with:
18+
go-version: 1.17
19+
- uses: actions/checkout@v3
20+
- name: golangci-lint
21+
uses: golangci/golangci-lint-action@v3
22+
with:
23+
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
24+
version: v1.45.2
25+
26+
# Optional: working directory, useful for monorepos
27+
# working-directory: somedir
28+
29+
# Optional: golangci-lint command line arguments.
30+
# args: --issues-exit-code=0
31+
32+
# Optional: show only new issues if it's a pull request. The default value is `false`.
33+
# only-new-issues: true
34+
35+
# Optional: if set to true then the all caching functionality will be complete disabled,
36+
# takes precedence over all other caching options.
37+
# skip-cache: true
38+
39+
# Optional: if set to true then the action don't cache or restore ~/go/pkg.
40+
# skip-pkg-cache: true
41+
42+
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
43+
# skip-build-cache: true

.golangci.yml

+48
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,51 @@ run:
55

66
linters:
77
disable-all: true
8+
# Enable specific linter
9+
# https://golangci-lint.run/usage/linters/#enabled-by-default-linters
10+
enable:
11+
- gofumpt
12+
# - goimports
13+
# - lll
14+
15+
issues:
16+
exclude-rules:
17+
# Exclude some linters from running on tests files.
18+
- path: _test\.go
19+
linters:
20+
- gocyclo
21+
- errcheck
22+
- dupl
23+
- gosec
24+
# Exclude `lll` issues for long lines with `go:generate`.
25+
- linters:
26+
- lll
27+
source: "^//go:generate "
28+
29+
linters-settings:
30+
gofumpt:
31+
# Select the Go version to target.
32+
# Default: 1.15
33+
lang-version: "1.17"
34+
35+
# Choose whether to use the extra rules.
36+
# Default: false
37+
extra-rules: true
38+
39+
# Module path which contains the source code being formatted.
40+
# Default: empty string
41+
module-path: github.com/netapp/trident
42+
43+
goimports:
44+
# Put imports beginning with prefix after 3rd-party packages.
45+
# It's a comma-separated list of prefixes.
46+
local-prefixes: github.com/netapp/trident
47+
48+
lll:
49+
# Max line length, lines longer will be reported.
50+
# '\t' is counted as 1 character by default, and can be changed with the tab-width option.
51+
# Default: 120.
52+
line-length: 120
53+
# Tab width in spaces.
54+
# Default: 1
55+
tab-width: 4

cli/api/rest.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import (
1313

1414
const HTTPClientTimeout = time.Second * 300
1515

16-
func InvokeRESTAPI(method string, url string, requestBody []byte, debug bool) (*http.Response, []byte, error) {
17-
16+
func InvokeRESTAPI(method, url string, requestBody []byte, debug bool) (*http.Response, []byte, error) {
1817
var request *http.Request
1918
var err error
2019

@@ -35,7 +34,6 @@ func InvokeRESTAPI(method string, url string, requestBody []byte, debug bool) (*
3534

3635
client := &http.Client{Timeout: HTTPClientTimeout}
3736
response, err := client.Do(request)
38-
3937
if err != nil {
4038
err = fmt.Errorf("error communicating with Trident REST API; %v", err)
4139
return nil, nil, err

cli/cmd/create_backend.go

-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ var createBackendCmd = &cobra.Command{
3838
Short: "Add a backend to Trident",
3939
Aliases: []string{"b"},
4040
RunE: func(cmd *cobra.Command, args []string) error {
41-
4241
jsonData, err := getBackendData(createFilename, createBase64Data)
4342
if err != nil {
4443
return err
@@ -55,7 +54,6 @@ var createBackendCmd = &cobra.Command{
5554
}
5655

5756
func getBackendData(filename, b64Data string) ([]byte, error) {
58-
5957
var err error
6058
var rawData []byte
6159

@@ -85,7 +83,6 @@ func getBackendData(filename, b64Data string) ([]byte, error) {
8583
}
8684

8785
func backendCreate(postData []byte) error {
88-
8986
// Send the file to Trident
9087
url := BaseURL() + "/backend"
9188

cli/cmd/delete_backend.go

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ var deleteBackendCmd = &cobra.Command{
3737
}
3838

3939
func backendDelete(backendNames []string) error {
40-
4140
var err error
4241

4342
if allBackends {

cli/cmd/delete_node.go

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ var deleteNodeCmd = &cobra.Command{
3838
}
3939

4040
func nodeDelete(nodeNames []string) error {
41-
4241
var err error
4342

4443
if allNodes {

cli/cmd/delete_snapshot.go

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ var deleteSnapshotCmd = &cobra.Command{
4747
}
4848

4949
func snapshotDelete(snapshotIDs []string) error {
50-
5150
var err error
5251

5352
if allSnapshotsInVolume != "" {

cli/cmd/delete_storageclass.go

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ var deleteStorageClassCmd = &cobra.Command{
3737
}
3838

3939
func storageClassDelete(storageClassNames []string) error {
40-
4140
var err error
4241

4342
if allStorageClasses {

cli/cmd/delete_volume.go

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ var deleteVolumeCmd = &cobra.Command{
3737
}
3838

3939
func volumeDelete(volumeNames []string) error {
40-
4140
var err error
4241

4342
if allVolumes {

cli/cmd/get.go

-2
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@ var getCmd = &cobra.Command{
2424
}
2525

2626
func WriteJSON(out interface{}) {
27-
2827
jsonBytes, _ := json.MarshalIndent(out, "", " ")
2928
fmt.Println(string(jsonBytes))
3029
}
3130

3231
func WriteYAML(out interface{}) {
33-
3432
jsonBytes, _ := json.Marshal(out)
3533
yamlBytes, _ := yaml.JSONToYAML(jsonBytes)
3634
fmt.Println(string(yamlBytes))

cli/cmd/get_backend.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ var getBackendCmd = &cobra.Command{
4040
}
4141

4242
func backendList(backendNames []string) error {
43-
4443
var err error
4544

4645
// If no backends were specified, we'll get all of them
@@ -74,7 +73,6 @@ func backendList(backendNames []string) error {
7473
}
7574

7675
func GetBackends() ([]string, error) {
77-
7876
url := BaseURL() + "/backend"
7977

8078
response, responseBody, err := api.InvokeRESTAPI("GET", url, nil, Debug)
@@ -95,7 +93,6 @@ func GetBackends() ([]string, error) {
9593
}
9694

9795
func GetBackend(backendName string) (storage.BackendExternal, error) {
98-
9996
url := BaseURL() + "/backend/" + backendName
10097

10198
response, responseBody, err := api.InvokeRESTAPI("GET", url, nil, Debug)
@@ -122,7 +119,6 @@ func GetBackend(backendName string) (storage.BackendExternal, error) {
122119
}
123120

124121
func GetBackendByBackendUUID(backendUUID string) (storage.BackendExternal, error) {
125-
126122
url := BaseURL() + "/backend/" + backendUUID
127123

128124
response, responseBody, err := api.InvokeRESTAPI("GET", url, nil, Debug)
@@ -184,7 +180,8 @@ func getOntapStorageDriverConfig(configAsMap map[string]interface{}) (*drivers.O
184180
}
185181

186182
func getSolidfireStorageDriverConfig(configAsMap map[string]interface{}) (*drivers.SolidfireStorageDriverConfig,
187-
error) {
183+
error,
184+
) {
188185
jsonBytes, marshalError := json.MarshalIndent(configAsMap, "", " ")
189186
if marshalError != nil {
190187
return nil, marshalError
@@ -199,7 +196,6 @@ func getSolidfireStorageDriverConfig(configAsMap map[string]interface{}) (*drive
199196
}
200197

201198
func writeBackendTable(backends []storage.BackendExternal) {
202-
203199
table := tablewriter.NewWriter(os.Stdout)
204200
table.SetHeader([]string{"Name", "Storage Driver", "UUID", "State", "Volumes"})
205201

@@ -224,7 +220,6 @@ func writeBackendTable(backends []storage.BackendExternal) {
224220
}
225221

226222
func writeBackendNames(backends []storage.BackendExternal) {
227-
228223
for _, b := range backends {
229224
fmt.Println(b.Name)
230225
}

cli/cmd/get_node.go

-6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ var getNodeCmd = &cobra.Command{
3939
}
4040

4141
func nodeList(nodeNames []string) error {
42-
4342
var err error
4443

4544
// If no nodes were specified, we'll get all of them
@@ -73,7 +72,6 @@ func nodeList(nodeNames []string) error {
7372
}
7473

7574
func GetNodes() ([]string, error) {
76-
7775
url := BaseURL() + "/node"
7876

7977
response, responseBody, err := api.InvokeRESTAPI("GET", url, nil, Debug)
@@ -94,7 +92,6 @@ func GetNodes() ([]string, error) {
9492
}
9593

9694
func GetNode(nodeName string) (*utils.Node, error) {
97-
9895
url := BaseURL() + "/node/" + nodeName
9996

10097
response, responseBody, err := api.InvokeRESTAPI("GET", url, nil, Debug)
@@ -136,7 +133,6 @@ func WriteNodes(nodes []utils.Node) {
136133
}
137134

138135
func writeNodeTable(nodes []utils.Node) {
139-
140136
table := tablewriter.NewWriter(os.Stdout)
141137
table.SetHeader([]string{"Name"})
142138

@@ -150,7 +146,6 @@ func writeNodeTable(nodes []utils.Node) {
150146
}
151147

152148
func writeWideNodeTable(nodes []utils.Node) {
153-
154149
table := tablewriter.NewWriter(os.Stdout)
155150

156151
header := []string{
@@ -186,7 +181,6 @@ func writeWideNodeTable(nodes []utils.Node) {
186181
}
187182

188183
func writeNodeNames(nodes []utils.Node) {
189-
190184
for _, n := range nodes {
191185
fmt.Println(n.Name)
192186
}

cli/cmd/get_snapshot.go

-7
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ var getSnapshotCmd = &cobra.Command{
4848
}
4949

5050
func snapshotList(snapshotIDs []string) error {
51-
5251
var err error
5352

5453
// If no snapshots were specified, we'll get all of them
@@ -82,7 +81,6 @@ func snapshotList(snapshotIDs []string) error {
8281
}
8382

8483
func GetSnapshots(volume string) ([]string, error) {
85-
8684
var url string
8785
if volume == "" {
8886
url = BaseURL() + "/snapshot"
@@ -107,7 +105,6 @@ func GetSnapshots(volume string) ([]string, error) {
107105
}
108106

109107
func GetSnapshot(snapshotID string) (storage.SnapshotExternal, error) {
110-
111108
if !strings.ContainsRune(snapshotID, '/') {
112109
return storage.SnapshotExternal{}, utils.InvalidInputError(fmt.Sprintf("invalid snapshot ID: %s; "+
113110
"Please use the format <volume name>/<snapshot name>", snapshotID))
@@ -157,12 +154,10 @@ func WriteSnapshots(snapshots []storage.SnapshotExternal) {
157154
}
158155

159156
func writeSnapshotTable(snapshots []storage.SnapshotExternal) {
160-
161157
table := tablewriter.NewWriter(os.Stdout)
162158
table.SetHeader([]string{"Name", "Volume"})
163159

164160
for _, snapshot := range snapshots {
165-
166161
table.Append([]string{
167162
snapshot.Config.Name,
168163
snapshot.Config.VolumeName,
@@ -173,7 +168,6 @@ func writeSnapshotTable(snapshots []storage.SnapshotExternal) {
173168
}
174169

175170
func writeWideSnapshotTable(snapshots []storage.SnapshotExternal) {
176-
177171
table := tablewriter.NewWriter(os.Stdout)
178172
header := []string{
179173
"Name",
@@ -185,7 +179,6 @@ func writeWideSnapshotTable(snapshots []storage.SnapshotExternal) {
185179
table.SetHeader(header)
186180

187181
for _, snapshot := range snapshots {
188-
189182
table.Append([]string{
190183
snapshot.Config.Name,
191184
snapshot.Config.VolumeName,

cli/cmd/get_storageclass.go

-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ var getStorageClassCmd = &cobra.Command{
3737
}
3838

3939
func storageClassList(storageClassNames []string) error {
40-
4140
var err error
4241

4342
// If no storage classes were specified, we'll get all of them
@@ -71,7 +70,6 @@ func storageClassList(storageClassNames []string) error {
7170
}
7271

7372
func GetStorageClasses() ([]string, error) {
74-
7573
url := BaseURL() + "/storageclass"
7674

7775
response, responseBody, err := api.InvokeRESTAPI("GET", url, nil, Debug)
@@ -92,7 +90,6 @@ func GetStorageClasses() ([]string, error) {
9290
}
9391

9492
func GetStorageClass(storageClassName string) (api.StorageClass, error) {
95-
9693
url := BaseURL() + "/storageclass/" + storageClassName
9794

9895
response, responseBody, err := api.InvokeRESTAPI("GET", url, nil, Debug)
@@ -132,7 +129,6 @@ func WriteStorageClasses(storageClasses []api.StorageClass) {
132129
}
133130

134131
func writeStorageClassTable(storageClasses []api.StorageClass) {
135-
136132
table := tablewriter.NewWriter(os.Stdout)
137133
table.SetHeader([]string{"Name"})
138134

@@ -146,7 +142,6 @@ func writeStorageClassTable(storageClasses []api.StorageClass) {
146142
}
147143

148144
func writeStorageClassNames(storageClasses []api.StorageClass) {
149-
150145
for _, sc := range storageClasses {
151146
fmt.Println(sc.Config.Name)
152147
}

0 commit comments

Comments
 (0)