Skip to content

Commit 532573f

Browse files
paskalumputun
authored andcommitted
fix problems reported by golangci-lint
1 parent e1173bb commit 532573f

20 files changed

+62
-72
lines changed

backend/_example/memory_store/accessor/data_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -547,12 +547,12 @@ func TestMemData_FlagListBlocked(t *testing.T) {
547547
assert.NoError(t, err)
548548

549549
blockedList := toBlocked(vv)
550-
var blockedIds = make([]string, len(blockedList))
550+
var blockedIDs = make([]string, len(blockedList))
551551
for i, x := range blockedList {
552-
blockedIds[i] = x.ID
552+
blockedIDs[i] = x.ID
553553
}
554554
require.Equal(t, 2, len(blockedList), b.metaUsers)
555-
assert.ElementsMatch(t, []string{"user1", "user2"}, blockedIds)
555+
assert.ElementsMatch(t, []string{"user1", "user2"}, blockedIDs)
556556
t.Logf("%+v", blockedList)
557557

558558
// check block expiration

backend/app/cmd/cleanup_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,15 @@ func cleanupRoutes(t *testing.T, r *chi.Mux, c *cleanedComments) {
195195
require.NoError(t, json.NewEncoder(w).Encode(commentsWithInfo))
196196
})
197197

198-
r.HandleFunc("/api/v1/admin/comment/{id}", func(w http.ResponseWriter, r *http.Request) {
198+
r.HandleFunc("/api/v1/admin/comment/{id}", func(_ http.ResponseWriter, r *http.Request) {
199199
require.Equal(t, "DELETE", r.Method)
200200
t.Log("delete ", r.URL.Path)
201201
c.lock.Lock()
202202
c.ids = append(c.ids, r.URL.Path)
203203
c.lock.Unlock()
204204
})
205205

206-
r.HandleFunc("/api/v1/admin/title/{id}", func(w http.ResponseWriter, r *http.Request) {
206+
r.HandleFunc("/api/v1/admin/title/{id}", func(_ http.ResponseWriter, r *http.Request) {
207207
require.Equal(t, "PUT", r.Method)
208208
t.Log("title for ", r.URL.Path)
209209
c.lock.Lock()

backend/app/cmd/server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ func (s *ServerCommand) getAuthenticator(ds *service.DataStore, avas avatar.Stor
12241224
return c
12251225
}),
12261226
AdminPasswd: s.AdminPasswd,
1227-
Validator: token.ValidatorFunc(func(token string, claims token.Claims) bool { // check on each auth call (in middleware)
1227+
Validator: token.ValidatorFunc(func(_ string, claims token.Claims) bool { // check on each auth call (in middleware)
12281228
if claims.User == nil {
12291229
return false
12301230
}

backend/app/cmd/server_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ func TestServerApp_WithSSL(t *testing.T) {
250250

251251
client := http.Client{
252252
// prevent http redirect
253-
CheckRedirect: func(req *http.Request, via []*http.Request) error {
253+
CheckRedirect: func(*http.Request, []*http.Request) error {
254254
return http.ErrUseLastResponse
255255
},
256256

backend/app/main_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func TestMain_WithWebhook(t *testing.T) {
6464
defer os.RemoveAll(dir)
6565

6666
var webhookSent int32
67-
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
67+
ts := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
6868
atomic.StoreInt32(&webhookSent, 1)
6969
assert.Equal(t, "application/json", r.Header.Get("Content-Type"))
7070

backend/app/rest/api/rest_private.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ func (s *private) userInfoCtrl(w http.ResponseWriter, r *http.Request) {
246246
if err != nil {
247247
log.Printf("[WARN] can't read email for %s, %v", user.ID, err)
248248
}
249-
if len(email) > 0 {
249+
if email != "" {
250250
user.EmailSubscription = true
251251
}
252252
}

backend/app/rest/api/rest_private_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func TestRest_CreateAndPreviewWithImage(t *testing.T) {
102102

103103
var pngRead bool
104104
// server with the test PNG image
105-
pngServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
105+
pngServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
106106
_, e := io.Copy(w, gopherPNG())
107107
assert.NoError(t, e)
108108
pngRead = true

backend/app/rest/api/rest_public_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ func TestRest_FindUserComments_CWE_918(t *testing.T) {
503503
defer teardown()
504504

505505
backendRequestedArbitraryServer := false
506-
arbitraryServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
506+
arbitraryServer := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
507507
t.Logf("request received: %+v", r)
508508
backendRequestedArbitraryServer = true
509509
}))

backend/app/rest/api/rest_test.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func TestRest_RunStaticSSLMode(t *testing.T) {
128128

129129
client := http.Client{
130130
// prevent http redirect
131-
CheckRedirect: func(req *http.Request, via []*http.Request) error {
131+
CheckRedirect: func(*http.Request, []*http.Request) error {
132132
return http.ErrUseLastResponse
133133
},
134134

@@ -178,7 +178,7 @@ func TestRest_RunAutocertModeHTTPOnly(t *testing.T) {
178178

179179
client := http.Client{
180180
// prevent http redirect
181-
CheckRedirect: func(req *http.Request, via []*http.Request) error {
181+
CheckRedirect: func(*http.Request, []*http.Request) error {
182182
return http.ErrUseLastResponse
183183
},
184184
}
@@ -194,7 +194,7 @@ func TestRest_RunAutocertModeHTTPOnly(t *testing.T) {
194194
}
195195

196196
func TestRest_rejectAnonUser(t *testing.T) {
197-
ts := httptest.NewServer(fakeAuth(rejectAnonUser(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
197+
ts := httptest.NewServer(fakeAuth(rejectAnonUser(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
198198
fmt.Fprintln(w, "Hello")
199199
}))))
200200
defer ts.Close()
@@ -307,7 +307,7 @@ func TestRest_cacheControl(t *testing.T) {
307307
req := httptest.NewRequest("GET", tt.url, http.NoBody)
308308
w := httptest.NewRecorder()
309309

310-
h := cacheControl(tt.exp, tt.version)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
310+
h := cacheControl(tt.exp, tt.version)(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}))
311311
h.ServeHTTP(w, req)
312312
resp := w.Result()
313313
assert.Equal(t, http.StatusOK, resp.StatusCode)
@@ -335,7 +335,7 @@ func TestRest_frameAncestors(t *testing.T) {
335335
req := httptest.NewRequest("GET", "http://example.com", http.NoBody)
336336
w := httptest.NewRecorder()
337337

338-
h := frameAncestors(tt.hosts)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
338+
h := frameAncestors(tt.hosts)(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}))
339339
h.ServeHTTP(w, req)
340340
resp := w.Result()
341341
assert.Equal(t, http.StatusOK, resp.StatusCode)
@@ -371,7 +371,7 @@ func TestRest_subscribersOnly(t *testing.T) {
371371
req = token.SetUserInfo(req, tt.user)
372372
}
373373
w := httptest.NewRecorder()
374-
h := subscribersOnly(tt.subsOnly)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
374+
h := subscribersOnly(tt.subsOnly)(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}))
375375
h.ServeHTTP(w, req)
376376
resp := w.Result()
377377
assert.Equal(t, tt.status, resp.StatusCode)
@@ -403,7 +403,7 @@ func Test_validEmailAuth(t *testing.T) {
403403
t.Run(strconv.Itoa(i), func(t *testing.T) {
404404
req := httptest.NewRequest("GET", "http://example.com"+tt.req, http.NoBody)
405405
w := httptest.NewRecorder()
406-
h := validEmailAuth()(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
406+
h := validEmailAuth()(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}))
407407
h.ServeHTTP(w, req)
408408
resp := w.Result()
409409
assert.Equal(t, tt.status, resp.StatusCode)
@@ -458,7 +458,7 @@ func startupT(t *testing.T, srvHook ...func(srv *Rest)) (ts *httptest.Server, sr
458458
DataService: dataStore,
459459
Authenticator: auth.NewService(auth.Opts{
460460
AdminPasswd: "password",
461-
SecretReader: token.SecretFunc(func(aud string) (string, error) { return "secret", nil }),
461+
SecretReader: token.SecretFunc(func(string) (string, error) { return "secret", nil }),
462462
AvatarStore: avatar.NewLocalFS(tmp + "/ava-remark42"),
463463
}),
464464
Cache: memCache,
@@ -495,7 +495,7 @@ func startupT(t *testing.T, srvHook ...func(srv *Rest)) (ts *httptest.Server, sr
495495
// add some providers. Needed because we don't allow users with unlisted providers to authenticate
496496
providers := []string{"provider1", "anonymous", "github", "email"}
497497
for _, p := range providers {
498-
srv.Authenticator.AddDirectProvider(p, provider.CredCheckerFunc(func(user, password string) (ok bool, err error) {
498+
srv.Authenticator.AddDirectProvider(p, provider.CredCheckerFunc(func(_, _ string) (ok bool, err error) {
499499
return true, nil
500500
}))
501501
}

backend/app/rest/api/ssl_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestSSL_Redirect(t *testing.T) {
2121

2222
client := http.Client{
2323
// prevent http redirect
24-
CheckRedirect: func(req *http.Request, via []*http.Request) error {
24+
CheckRedirect: func(*http.Request, []*http.Request) error {
2525
return http.ErrUseLastResponse
2626
},
2727

@@ -56,7 +56,7 @@ func TestSSL_ACME_HTTPChallengeRouter(t *testing.T) {
5656

5757
client := http.Client{
5858
// prevent http redirect
59-
CheckRedirect: func(req *http.Request, via []*http.Request) error {
59+
CheckRedirect: func(*http.Request, []*http.Request) error {
6060
return http.ErrUseLastResponse
6161
},
6262
}

backend/app/rest/proxy/image.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (p Image) extract(commentHTML string, imgSrcPred func(string) bool) ([]stri
5757
return nil, fmt.Errorf("can't create document: %w", err)
5858
}
5959
result := []string{}
60-
doc.Find("img").Each(func(i int, s *goquery.Selection) {
60+
doc.Find("img").Each(func(_ int, s *goquery.Selection) {
6161
if im, ok := s.Attr("src"); ok {
6262
if imgSrcPred(im) {
6363
result = append(result, im)

backend/app/rest/proxy/image_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func TestImage_Replace(t *testing.T) {
9595

9696
func TestImage_Routes(t *testing.T) {
9797
// no image supposed to be cached
98-
imageStore := image.StoreMock{LoadFunc: func(id string) ([]byte, error) { return nil, nil }}
98+
imageStore := image.StoreMock{LoadFunc: func(string) ([]byte, error) { return nil, nil }}
9999
img := Image{
100100
HTTP2HTTPS: true,
101101
RemarkURL: "https://demo.remark42.com",
@@ -132,7 +132,7 @@ func TestImage_Routes(t *testing.T) {
132132
}
133133

134134
func TestImage_DisabledCachingAndHTTP2HTTPS(t *testing.T) {
135-
imageStore := image.StoreMock{LoadFunc: func(id string) ([]byte, error) { return nil, nil }}
135+
imageStore := image.StoreMock{LoadFunc: func(string) ([]byte, error) { return nil, nil }}
136136
img := Image{
137137
RemarkURL: "https://demo.remark42.com",
138138
RoutePath: "/api/v1/proxy",
@@ -158,10 +158,10 @@ func TestImage_DisabledCachingAndHTTP2HTTPS(t *testing.T) {
158158

159159
func TestImage_RoutesCachingImage(t *testing.T) {
160160
imageStore := image.StoreMock{
161-
LoadFunc: func(id string) ([]byte, error) {
161+
LoadFunc: func(string) ([]byte, error) {
162162
return nil, nil
163163
},
164-
SaveFunc: func(id string, img []byte) error {
164+
SaveFunc: func(string, []byte) error {
165165
return nil
166166
},
167167
}
@@ -196,7 +196,7 @@ func TestImage_RoutesCachingImage(t *testing.T) {
196196
func TestImage_RoutesUsingCachedImage(t *testing.T) {
197197
// In order to validate that cached data used cache "will return" some other data from what http server would
198198
testImage := []byte(fmt.Sprintf("%256s", "X"))
199-
imageStore := image.StoreMock{LoadFunc: func(id string) ([]byte, error) {
199+
imageStore := image.StoreMock{LoadFunc: func(string) ([]byte, error) {
200200
return testImage, nil
201201
}}
202202
img := Image{
@@ -226,7 +226,7 @@ func TestImage_RoutesUsingCachedImage(t *testing.T) {
226226

227227
func TestImage_RoutesTimedOut(t *testing.T) {
228228
// no image supposed to be cached
229-
imageStore := image.StoreMock{LoadFunc: func(id string) ([]byte, error) { return nil, nil }}
229+
imageStore := image.StoreMock{LoadFunc: func(string) ([]byte, error) { return nil, nil }}
230230
img := Image{
231231
HTTP2HTTPS: true,
232232
RemarkURL: "https://demo.remark42.com",

backend/app/store/engine/bolt.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func (b *BoltDB) Find(req FindRequest) (comments []store.Comment, err error) {
170170
return e
171171
}
172172

173-
return bucket.ForEach(func(k, v []byte) error {
173+
return bucket.ForEach(func(_, v []byte) error {
174174
comment := store.Comment{}
175175
if e = json.Unmarshal(v, &comment); e != nil {
176176
return fmt.Errorf("failed to unmarshal: %w", e)
@@ -724,7 +724,7 @@ func (b *BoltDB) listDetails(loc store.Locator) (result []UserDetailEntry, err e
724724
err = bdb.View(func(tx *bolt.Tx) error {
725725
var entry UserDetailEntry
726726
bucket := tx.Bucket([]byte(userDetailsBucketName))
727-
return bucket.ForEach(func(userID, value []byte) error {
727+
return bucket.ForEach(func(_, value []byte) error {
728728
if err = json.Unmarshal(value, &entry); err != nil {
729729
return fmt.Errorf("failed to unmarshal entry: %w", e)
730730
}
@@ -869,7 +869,7 @@ func (b *BoltDB) deleteUser(bdb *bolt.DB, siteID, userID string, mode store.Dele
869869
err = bdb.View(func(tx *bolt.Tx) error {
870870
postsBkt := tx.Bucket([]byte(postsBucketName))
871871
postBkt := postsBkt.Bucket([]byte(postInfo.URL))
872-
err = postBkt.ForEach(func(postURL []byte, commentVal []byte) error {
872+
err = postBkt.ForEach(func(_ []byte, commentVal []byte) error {
873873
comment := store.Comment{}
874874
if err = json.Unmarshal(commentVal, &comment); err != nil {
875875
return fmt.Errorf("failed to unmarshal: %w", err)

backend/app/store/formatter.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (f *CommentFormatter) shortenAutoLinks(commentHTML string, max int) (resHTM
6262
if err != nil {
6363
return commentHTML
6464
}
65-
doc.Find("a").Each(func(i int, s *goquery.Selection) {
65+
doc.Find("a").Each(func(_ int, s *goquery.Selection) {
6666
if href, ok := s.Attr("href"); ok {
6767
if href != s.Text() || len(href) < max+3 || max < 3 {
6868
return
@@ -110,7 +110,7 @@ func (f *CommentFormatter) lazyImage(commentHTML string) (resHTML string) {
110110
if err != nil {
111111
return commentHTML
112112
}
113-
doc.Find("img").Each(func(i int, s *goquery.Selection) {
113+
doc.Find("img").Each(func(_ int, s *goquery.Selection) {
114114
s.SetAttr("loading", "lazy")
115115
})
116116
resHTML, err = doc.Find("body").Html()

backend/app/store/image/fs_store.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func (f *FileSystem) Info() (StoreInfo, error) {
166166
}
167167

168168
var ts time.Time
169-
err := filepath.Walk(f.Staging, func(fpath string, info os.FileInfo, err error) error {
169+
err := filepath.Walk(f.Staging, func(_ string, info os.FileInfo, err error) error {
170170
if err != nil {
171171
return err
172172
}

backend/app/store/image/image.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ func (s *Service) extractImageIDs(commentHTML string, includeProxied bool) (ids
250250
log.Printf("[ERROR] can't parse commentHTML to parse images: %q, error: %v", commentHTML, err)
251251
return nil
252252
}
253-
doc.Find("img").Each(func(i int, sl *goquery.Selection) {
253+
doc.Find("img").Each(func(_ int, sl *goquery.Selection) {
254254
if im, ok := sl.Attr("src"); ok {
255255
if strings.Contains(im, s.ImageAPI) {
256256
elems := strings.Split(im, "/")

backend/app/store/image/image_test.go

+9-19
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import (
1919

2020
func TestService_SaveAndLoad(t *testing.T) {
2121
store := StoreMock{
22-
SaveFunc: func(id string, img []byte) error {
22+
SaveFunc: func(string, []byte) error {
2323
return nil
2424
},
25-
LoadFunc: func(id string) ([]byte, error) {
25+
LoadFunc: func(string) ([]byte, error) {
2626
return nil, nil
2727
},
2828
}
@@ -126,7 +126,7 @@ func TestService_ExtractPictures(t *testing.T) {
126126

127127
func TestService_Cleanup(t *testing.T) {
128128
store := StoreMock{
129-
CleanupFunc: func(ctx context.Context, ttl time.Duration) error {
129+
CleanupFunc: func(context.Context, time.Duration) error {
130130
return nil
131131
},
132132
}
@@ -141,12 +141,8 @@ func TestService_Cleanup(t *testing.T) {
141141

142142
func TestService_Submit(t *testing.T) {
143143
store := StoreMock{
144-
CommitFunc: func(id string) error {
145-
return nil
146-
},
147-
ResetCleanupTimerFunc: func(id string) error {
148-
return nil
149-
},
144+
CommitFunc: func(string) error { return nil },
145+
ResetCleanupTimerFunc: func(string) error { return nil },
150146
}
151147
svc := NewService(&store, ServiceParams{ImageAPI: "/blah/", EditDuration: time.Millisecond * 100})
152148
svc.Submit(func() []string { return []string{"id1", "id2", "id3"} })
@@ -164,12 +160,8 @@ func TestService_Submit(t *testing.T) {
164160

165161
func TestService_Close(t *testing.T) {
166162
store := StoreMock{
167-
CommitFunc: func(id string) error {
168-
return nil
169-
},
170-
ResetCleanupTimerFunc: func(id string) error {
171-
return nil
172-
},
163+
CommitFunc: func(string) error { return nil },
164+
ResetCleanupTimerFunc: func(string) error { return nil },
173165
}
174166
svc := Service{store: &store, ServiceParams: ServiceParams{ImageAPI: "/blah/", EditDuration: time.Hour * 24}}
175167
svc.Submit(func() []string { return []string{"id1", "id2", "id3"} })
@@ -182,10 +174,8 @@ func TestService_Close(t *testing.T) {
182174

183175
func TestService_SubmitDelay(t *testing.T) {
184176
store := StoreMock{
185-
CommitFunc: func(id string) error {
186-
return nil
187-
},
188-
ResetCleanupTimerFunc: func(id string) error {
177+
CommitFunc: func(string) error { return nil },
178+
ResetCleanupTimerFunc: func(string) error {
189179
return nil
190180
},
191181
}

backend/app/store/service/service.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ func (s *DataStore) ValidateComment(c *store.Comment) error {
657657
mdExt, rend := store.GetMdExtensionsAndRenderer(false)
658658
parser := bf.New(bf.WithRenderer(rend), bf.WithExtensions(bf.CommonExtensions), bf.WithExtensions(mdExt))
659659
var wrongLinkError error
660-
parser.Parse([]byte(c.Orig)).Walk(func(node *bf.Node, entering bool) bf.WalkStatus {
660+
parser.Parse([]byte(c.Orig)).Walk(func(node *bf.Node, _ bool) bf.WalkStatus {
661661
if len(node.LinkData.Destination) != 0 &&
662662
!(strings.HasPrefix(string(node.LinkData.Destination), "http://") ||
663663
strings.HasPrefix(string(node.LinkData.Destination), "https://") ||

0 commit comments

Comments
 (0)