Skip to content

Commit 1225d61

Browse files
authored
chore(lint): fix staticcheck issues (oauth2-proxy#3061)
* chores: fix staticcheck QF1012 Fix use of fmt.Sprintf when writing to a writer. https://staticcheck.dev/docs/checks/#QF1012 oauth2-proxy#3060 * chores: fix staticcheck QF1003 Use switch instead of multiple if/else. https://staticcheck.dev/docs/checks/#QF1003 oauth2-proxy#3060 * chores: exclude staticcheck QF1008 for now We aim to migrate golangci-lint to v2 Let's disable QF1008 (Omit embedded fields from selector expression) for now. https://staticcheck.dev/docs/checks/#QF1008 * chores: fix golangci config: run.deadline -> timeout Rename config option to match v1 documentation: deadline -> timeout. https://golangci.github.io/legacy-v1-doc/usage/configuration/#run-configuration This error has been spotted by golangci-lint v2 migration tool. * chores: fix staticcheck QF1012
1 parent 09f6252 commit 1225d61

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

.golangci.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
run:
2-
deadline: 120s
2+
timeout: 120s
33
linters:
44
enable:
55
- govet
@@ -24,6 +24,10 @@ linters:
2424
- revive
2525
disable-all: true
2626
issues:
27+
exclude:
28+
# To ease migration to golangci-lint v2.1
29+
# https://staticcheck.dev/docs/checks/#QF1008
30+
- QF1008
2731
exclude-rules:
2832
- path: _test\.go
2933
linters:

pkg/app/pagewriter/pagewriter_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ var _ = Describe("Writer", func() {
167167
writer: &WriterFuncs{
168168
SignInPageFunc: func(rw http.ResponseWriter, req *http.Request, redirectURL string, statusCode int) {
169169
rw.WriteHeader(202)
170-
rw.Write([]byte(fmt.Sprintf("%s %s", req.URL.Path, redirectURL)))
170+
fmt.Fprintf(rw, "%s %s", req.URL.Path, redirectURL)
171171
},
172172
},
173173
expectedStatus: 202,
@@ -200,7 +200,7 @@ var _ = Describe("Writer", func() {
200200
writer: &WriterFuncs{
201201
ErrorPageFunc: func(rw http.ResponseWriter, opts ErrorPageOpts) {
202202
rw.WriteHeader(503)
203-
rw.Write([]byte(fmt.Sprintf("%s %s", opts.RequestID, opts.RedirectURL)))
203+
fmt.Fprintf(rw, "%s %s", opts.RequestID, opts.RedirectURL)
204204
},
205205
},
206206
expectedStatus: 503,
@@ -230,7 +230,7 @@ var _ = Describe("Writer", func() {
230230
writer: &WriterFuncs{
231231
ProxyErrorFunc: func(rw http.ResponseWriter, req *http.Request, proxyErr error) {
232232
rw.WriteHeader(503)
233-
rw.Write([]byte(fmt.Sprintf("%s %v", req.URL.Path, proxyErr)))
233+
fmt.Fprintf(rw, "%s %v", req.URL.Path, proxyErr)
234234
},
235235
},
236236
expectedStatus: 503,

providers/google_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,30 +237,31 @@ func TestGoogleProviderGetEmailAddressEmailMissing(t *testing.T) {
237237

238238
func TestGoogleProvider_userInGroup(t *testing.T) {
239239
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
240-
if r.URL.Path == "/admin/directory/v1/groups/[email protected]/hasMember/[email protected]" {
240+
switch r.URL.Path {
241+
case "/admin/directory/v1/groups/[email protected]/hasMember/[email protected]":
241242
fmt.Fprintln(w, `{"isMember":true}`)
242-
} else if r.URL.Path == "/admin/directory/v1/groups/[email protected]/hasMember/[email protected]" {
243+
case "/admin/directory/v1/groups/[email protected]/hasMember/[email protected]":
243244
fmt.Fprintln(w, `{"isMember":false}`)
244-
} else if r.URL.Path == "/admin/directory/v1/groups/[email protected]/hasMember/[email protected]" {
245+
case "/admin/directory/v1/groups/[email protected]/hasMember/[email protected]":
245246
http.Error(
246247
w,
247248
`{"error":{"errors":[{"domain":"global","reason":"invalid","message":"Invalid Input: memberKey"}],"code":400,"message":"Invalid Input: memberKey"}}`,
248249
http.StatusBadRequest,
249250
)
250-
} else if r.URL.Path == "/admin/directory/v1/groups/[email protected]/hasMember/[email protected]" {
251+
case "/admin/directory/v1/groups/[email protected]/hasMember/[email protected]":
251252
http.Error(
252253
w,
253254
`{"error":{"errors":[{"domain":"global","reason":"invalid","message":"Invalid Input: memberKey"}],"code":400,"message":"Invalid Input: memberKey"}}`,
254255
http.StatusBadRequest,
255256
)
256-
} else if r.URL.Path == "/admin/directory/v1/groups/[email protected]/members/[email protected]" {
257+
case "/admin/directory/v1/groups/[email protected]/members/[email protected]":
257258
// note that the client currently doesn't care what this response text or code is - any error here results in failure to match the group
258259
http.Error(
259260
w,
260261
`{"kind":"admin#directory#member","etag":"12345","id":"1234567890","email":"[email protected]","role":"MEMBER","type":"USER","status":"ACTIVE","delivery_settings":"ALL_MAIL"}`,
261262
http.StatusNotFound,
262263
)
263-
} else if r.URL.Path == "/admin/directory/v1/groups/[email protected]/members/[email protected]" {
264+
case "/admin/directory/v1/groups/[email protected]/members/[email protected]":
264265
fmt.Fprintln(w,
265266
`{"kind":"admin#directory#member","etag":"12345","id":"1234567890","email":"[email protected]","role":"MEMBER","type":"USER","status":"ACTIVE","delivery_settings":"ALL_MAIL"}`,
266267
)

providers/ms_entra_id_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func mockGraphAPI(noGroupMemberPermissions bool) *httptest.Server {
149149

150150
} else if r.URL.Path == groupsPath && r.Method == http.MethodGet {
151151
// First page (pagination)
152-
w.Write([]byte(fmt.Sprintf(`{
152+
fmt.Fprintf(w, `{
153153
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#directoryObjects(id)",
154154
"@odata.nextLink": "http://%s/v1.0/me/transitiveMemberOf?$select=id&$top=2&$skiptoken=TEST_TOKEN",
155155
"value": [
@@ -162,7 +162,7 @@ func mockGraphAPI(noGroupMemberPermissions bool) *httptest.Server {
162162
"id": "916f0604-8a3b-4a69-bda9-06db11a8f0cd"
163163
}
164164
]
165-
}`, r.Host)))
165+
}`, r.Host)
166166
}
167167
},
168168
))

0 commit comments

Comments
 (0)