Skip to content

Commit 5bbdffb

Browse files
authored
update golangci-lint 2.8 (#4194)
1 parent 8d0c4c7 commit 5bbdffb

5 files changed

Lines changed: 18 additions & 24 deletions

File tree

.github/workflows/go-tests-windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ jobs:
5858
- name: golangci-lint
5959
uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0
6060
with:
61-
version: v2.7
61+
version: v2.8
6262
args: --issues-exit-code=1 --timeout 10m
6363
only-new-issues: false

.github/workflows/go-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,6 @@ jobs:
214214
- name: golangci-lint
215215
uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0
216216
with:
217-
version: v2.7
217+
version: v2.8
218218
args: --issues-exit-code=1 --timeout 10m
219219
only-new-issues: false

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ linters:
3131
- errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`.
3232
- unparam # Reports unused function parameters
3333
- errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and reports occasions, where the check for the returned error can be omitted.
34+
- unqueryvet # Detects SELECT * in SQL queries and SQL builders, preventing performance issues and encouraging explicit column selection.
3435

3536
# we allow named returns (to improve readability, in the function signatures)
3637
# but disallow implicit (or "naked") returns, to improve readability in the actual code.

pkg/apiclient/client_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"net/http"
77
"net/http/httptest"
88
"net/url"
9-
"path"
9+
"path/filepath"
1010
"runtime"
1111
"strings"
1212
"testing"
@@ -44,14 +44,14 @@ func setupWithPrefix(urlPrefix string) (*http.ServeMux, string, func()) {
4444
// toUNCPath converts a Windows file path to a UNC path.
4545
// This is necessary because the Go http package does not support Windows file paths.
4646
func toUNCPath(path string) (string, error) {
47-
colonIdx := strings.Index(path, ":")
48-
if colonIdx == -1 {
47+
drive, rest, ok := strings.Cut(path, ":")
48+
if !ok {
4949
return "", fmt.Errorf("invalid path format, missing drive letter: %s", path)
5050
}
5151

5252
// URL parsing does not like backslashes
53-
remaining := strings.ReplaceAll(path[colonIdx+1:], "\\", "/")
54-
uncPath := "//localhost/" + path[:colonIdx] + "$" + remaining
53+
rest = strings.ReplaceAll(rest, `\`, "/")
54+
uncPath := "//localhost/" + drive + "$" + rest
5555

5656
return uncPath, nil
5757
}
@@ -110,7 +110,7 @@ func TestNewClientOk(t *testing.T) {
110110
})
111111

112112
mux.HandleFunc("/alerts", func(w http.ResponseWriter, r *http.Request) {
113-
testMethod(t, r, "GET")
113+
testMethod(t, r, http.MethodGet)
114114
w.WriteHeader(http.StatusOK)
115115
})
116116

@@ -147,7 +147,7 @@ func TestNewClientOk_UnixSocket(t *testing.T) {
147147
})
148148

149149
mux.HandleFunc("/alerts", func(w http.ResponseWriter, r *http.Request) {
150-
testMethod(t, r, "GET")
150+
testMethod(t, r, http.MethodGet)
151151
w.WriteHeader(http.StatusOK)
152152
})
153153

@@ -157,7 +157,7 @@ func TestNewClientOk_UnixSocket(t *testing.T) {
157157
}
158158

159159
if resp.Response.StatusCode != http.StatusOK {
160-
t.Fatalf("Alerts.List returned status: %d, want %d", resp.Response.StatusCode, http.StatusCreated)
160+
t.Fatalf("Alerts.List returned status: %d, want %d", resp.Response.StatusCode, http.StatusOK)
161161
}
162162
}
163163

@@ -185,7 +185,7 @@ func TestNewClientKo(t *testing.T) {
185185
})
186186

187187
mux.HandleFunc("/alerts", func(w http.ResponseWriter, r *http.Request) {
188-
testMethod(t, r, "GET")
188+
testMethod(t, r, http.MethodGet)
189189
w.WriteHeader(http.StatusOK)
190190
})
191191

@@ -278,7 +278,7 @@ func TestNewClientRegisterOK(t *testing.T) {
278278

279279
/*mock login*/
280280
mux.HandleFunc("/watchers", func(w http.ResponseWriter, r *http.Request) {
281-
testMethod(t, r, "POST")
281+
testMethod(t, r, http.MethodPost)
282282
w.WriteHeader(http.StatusOK)
283283
_, err := w.Write([]byte(`{"code": 200, "expire": "2030-01-02T15:04:05Z", "token": "oklol"}`))
284284
assert.NoError(t, err)
@@ -303,14 +303,14 @@ func TestNewClientRegisterOK_UnixSocket(t *testing.T) {
303303
log.SetLevel(log.TraceLevel)
304304

305305
tmpDir := t.TempDir()
306-
socket := path.Join(tmpDir, "socket")
306+
socket := filepath.Join(tmpDir, "socket")
307307

308308
mux, urlx, teardown := setupUnixSocketWithPrefix(t, socket, "v1")
309309
defer teardown()
310310

311311
/*mock login*/
312312
mux.HandleFunc("/watchers", func(w http.ResponseWriter, r *http.Request) {
313-
testMethod(t, r, "POST")
313+
testMethod(t, r, http.MethodPost)
314314
w.WriteHeader(http.StatusOK)
315315
_, err := w.Write([]byte(`{"code": 200, "expire": "2030-01-02T15:04:05Z", "token": "oklol"}`))
316316
assert.NoError(t, err)
@@ -343,7 +343,7 @@ func TestNewClientBadAnswer(t *testing.T) {
343343

344344
/*mock login*/
345345
mux.HandleFunc("/watchers", func(w http.ResponseWriter, r *http.Request) {
346-
testMethod(t, r, "POST")
346+
testMethod(t, r, http.MethodPost)
347347
w.WriteHeader(http.StatusUnauthorized)
348348
_, err := w.Write([]byte(`bad`))
349349
assert.NoError(t, err)

pkg/exprhelpers/waf.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,15 @@ func ExprWrapExtractQueryParam(params ...any) (any, error) {
100100
// ExtractQueryParam extracts values for a given query parameter from a raw URI string.
101101
func ExtractQueryParam(uri, param string) []string {
102102
// Find the first occurrence of "?"
103-
idx := strings.Index(uri, "?")
104-
if idx == -1 {
103+
_, queryString, ok := strings.Cut(uri, "?")
104+
if !ok || queryString == "" {
105105
// No query string present
106106
return []string{}
107107
}
108108

109-
// Extract the query string part
110-
queryString := uri[idx+1:]
111-
112109
// Parse the query string using a function that supports both `&` and `;`
113110
values := ParseQuery(queryString)
114111

115-
if values == nil {
116-
// No query string present
117-
return []string{}
118-
}
119112
// Retrieve the values for the specified parameter
120113
if _, ok := values[param]; !ok {
121114
return []string{}

0 commit comments

Comments
 (0)