Skip to content

Commit 0600522

Browse files
committed
Updated linting config and fixed a bunch of issues.
1 parent ccc0080 commit 0600522

File tree

9 files changed

+71
-18
lines changed

9 files changed

+71
-18
lines changed

.golangci.yml

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,57 @@ linters:
22
disable-all: true
33
enable:
44
- govet
5+
- deadcode
56
- vet
67
- staticcheck
78
- revive
89
- errcheck
910
- ineffassign
1011
- misspell
11-
#
12-
#issues:
13-
# exclude-rules:
14-
# - path: _test\.go
15-
# linters:
16-
# - goerr113
17-
# - gochecknoglobals
18-
# - wsl
19-
# - lll
20-
# - funlen
12+
- nlreturn
13+
- gosec
2114

2215
run:
2316
timeout: 5m
17+
18+
issues:
19+
exclude-rules:
20+
- path: _test\.go
21+
linters:
22+
- funlen
23+
- bodyclose
24+
- gosec
25+
- revive
26+
- path: example/
27+
text: "avoid magic numbers"
28+
29+
linters-settings:
30+
revive:
31+
enable-all-rules: true
32+
rules:
33+
- name: cognitive-complexity
34+
disabled: true
35+
- name: line-length-limit
36+
arguments: [120]
37+
- name: function-length
38+
arguments: [50, 0]
39+
- name: argument-limit
40+
disabled: true
41+
- name: banned-characters
42+
disabled: true
43+
- name: cyclomatic
44+
arguments: [15]
45+
- name: function-result-limit
46+
arguments: [3]
47+
- name: max-public-structs
48+
arguments: [3]
49+
- name: file-header
50+
disabled: true
51+
- name: add-constant
52+
arguments:
53+
- allowStrs: '""'
54+
allowInts: "0,1,2"
55+
- name: unhandled-error
56+
arguments:
57+
- "fmt.Printf"
58+
- "fmt.Println"

driver/connector_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type testDriver struct {
3939
func (d *testDriver) Open(dsn string) (driver.Conn, error) {
4040
d.Called++
4141
d.ConnStr = dsn
42+
4243
return d.Conn, d.ConnErr
4344
}
4445

@@ -56,6 +57,7 @@ func (fd *testFailingDriver) Open(dsn string) (driver.Conn, error) {
5657
if fd.Called == 1 {
5758
return nil, fd.ConnErr
5859
}
60+
5961
return nil, nil
6062
}
6163

@@ -384,6 +386,7 @@ func TestConnectorFailsToRefreshOnConnectionFailure(t *testing.T) {
384386
},
385387
Refresher: func(ctx context.Context) (Credentials, error) {
386388
refreshCalled++
389+
387390
return nil, errors.New("failed to refresh creds")
388391
},
389392
}, "driver", &cfg)
@@ -449,6 +452,7 @@ func TestConnectorRetriesUntilSuccess(t *testing.T) {
449452
Password: password,
450453
}, nil
451454
}
455+
452456
return nil, errors.New("failed to refresh creds")
453457
},
454458
}, "driver", &cfg)
@@ -514,6 +518,7 @@ func TestConnectorRetriesUntilMax(t *testing.T) {
514518
},
515519
Refresher: func(ctx context.Context) (Credentials, error) {
516520
refreshCalled++
521+
517522
return &testCredential{
518523
Username: username,
519524
Password: password,
@@ -583,6 +588,7 @@ func TestConnectorRetriesUntilNonAuthError(t *testing.T) {
583588
},
584589
Refresher: func(ctx context.Context) (Credentials, error) {
585590
refreshCalled++
591+
586592
return &testCredential{
587593
Username: username,
588594
Password: password,

driver/formatter_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func TestFormatters(t *testing.T) {
8989
if dsn != testCase.expectedDsn {
9090
t.Fatalf("expected %s but got %s", testCase.expectedDsn, dsn)
9191
}
92+
9293
return
9394
}
9495
// Because url.Values is a map[string][]string we get randomized ordering before encoding so we

store/awsrds/store_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
func TestStoreValidation(t *testing.T) {
1818
if _, err := NewStore(nil); err == nil {
1919
t.Error("expected an error but didn't get one")
20-
} else if err != errMissingConfig {
20+
} else if !errors.Is(err, errMissingConfig) {
2121
t.Errorf("expected '%T' but got '%T' instead", errMissingConfig, err)
2222
}
2323

@@ -103,12 +103,14 @@ func TestStoreValidation(t *testing.T) {
103103
_, err = NewStore(&conf)
104104
if err == nil {
105105
t.Error("expected an error but didn't get one")
106+
106107
return
107108
}
108109

109110
// If we have a pointer to an error we need to compare error strings
110111
if reflect.ValueOf(testCase.expectedErr).Kind() == reflect.Ptr && err.Error() != testCase.expectedErr.Error() {
111112
t.Errorf("expected '%v' but got '%v' instead", testCase.expectedErr, err)
113+
112114
return
113115
}
114116

@@ -209,6 +211,7 @@ func TestStoreCachesCredentials(t *testing.T) {
209211
patch = monkey.Patch(time.Now, func() time.Time {
210212
patch.Unpatch()
211213
defer patch.Restore()
214+
212215
return time.Now().Add(20 * time.Minute)
213216
})
214217
defer patch.Unpatch()

store/vault/auth/kubernetes_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,21 @@ qQYZl8EZf4Jznaes/XFP0Yb+IhGXBoR9Ib+I
5252
func tokenReviewHandler(w http.ResponseWriter, r *http.Request) {
5353
if r.URL.Path != "/apis/authentication.k8s.io/v1/tokenreviews" {
5454
w.WriteHeader(404)
55+
5556
return
5657
}
5758
body, err := ioutil.ReadAll(r.Body)
5859
if err != nil {
5960
w.WriteHeader(500)
61+
6062
return
6163
}
62-
defer r.Body.Close()
64+
defer r.Body.Close() //nolint:errcheck
6365

6466
var tr authv1.TokenReview
6567
if err := json.Unmarshal(body, &tr); err != nil {
6668
w.WriteHeader(500)
69+
6770
return
6871
}
6972

@@ -84,7 +87,7 @@ func TestKubernetesAuth(t *testing.T) {
8487
defer srv.Close()
8588

8689
ln, client := vaulttest.CreateTestVault(t, nil)
87-
defer ln.Close()
90+
defer ln.Close() //nolint:errcheck
8891

8992
ctx := context.Background()
9093

@@ -115,7 +118,7 @@ func TestKubernetesAuth(t *testing.T) {
115118
if err != nil {
116119
t.Error(err)
117120
}
118-
defer os.Remove(tmpfile.Name())
121+
defer os.Remove(tmpfile.Name()) //nolint:errcheck
119122

120123
if _, err = tmpfile.Write([]byte(jwtData)); err != nil {
121124
t.Error(err)
@@ -182,9 +185,9 @@ func TestKubernetesAuthFileError(t *testing.T) {
182185
}
183186

184187
func TestKubernetesAuthVaultError(t *testing.T) {
185-
srv := httptest.NewServer(http.HandlerFunc((func(w http.ResponseWriter, r *http.Request) {
188+
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
186189
w.WriteHeader(404)
187-
})))
190+
}))
188191
defer srv.Close()
189192

190193
client, err := api.NewClient(nil)
@@ -200,7 +203,7 @@ func TestKubernetesAuthVaultError(t *testing.T) {
200203
if err != nil {
201204
t.Error(err)
202205
}
203-
defer os.Remove(tmpfile.Name())
206+
defer os.Remove(tmpfile.Name()) //nolint:errcheck
204207

205208
if _, err = tmpfile.Write([]byte(jwtData)); err != nil {
206209
t.Error(err)

store/vault/credentials/agent_database_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var testMapper Mapper = func(s string) (*store.Credential, error) {
2525
Password: creds[1],
2626
}, nil
2727
}
28+
2829
return nil, errors.New("mapping function failed")
2930
}
3031

store/vault/credentials/kv.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ func (kv *KvCredentials) GetCredentials(ctx context.Context, client *api.Client)
2626
}
2727

2828
// Map implements the CredentialLocation interface.
29-
func (kv *KvCredentials) Map(s string) (*store.Credential, error) {
29+
func (*KvCredentials) Map(s string) (*store.Credential, error) {
3030
return DefaultMapper(s)
3131
}

store/vault/example/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func Run() error {
9898
err = db.Ping(ctx, database)
9999
if err != nil {
100100
fmt.Println(err)
101+
101102
break
102103
}
103104

@@ -110,6 +111,7 @@ func Run() error {
110111
})
111112
if err != nil {
112113
fmt.Println(err)
114+
113115
break
114116
}
115117

store/vault/store_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ func TestNewStoreWithClientThatAlreadyHasToken(t *testing.T) {
216216
if c.Token() != client.Token() {
217217
t.Fatalf("expected token to be '%s' but got '%s' instead", client.Token(), c.Token())
218218
}
219+
219220
return fmt.Sprintf(`{"username": "%s", "password": "%s"}`, username, password), nil
220221
},
221222
Mapper: vaultcredentials.DefaultMapper,
@@ -285,6 +286,7 @@ func TestStoreWithCachedCredentials(t *testing.T) {
285286
},
286287
Mapper: func(s string) (*store.Credential, error) {
287288
mapCallCount++
289+
288290
return vaultcredentials.DefaultMapper(s)
289291
},
290292
},

0 commit comments

Comments
 (0)