Skip to content

Commit 5e30dc8

Browse files
authored
Merge pull request #1917 from umputun/paskal/golangci_lint_v2
Automatic fix of errors reported by golangci-lint v2
2 parents c32e5ef + edfc5b9 commit 5e30dc8

File tree

15 files changed

+30
-37
lines changed

15 files changed

+30
-37
lines changed

backend/app/cmd/cleanup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (cc *CleanupCommand) procSpam(comments []store.Comment) int {
7777
log.Printf("[WARN] can't remove comment, %v", err)
7878
}
7979
}
80-
comment.Text = strings.Replace(comment.Text, "\n", " ", -1)
80+
comment.Text = strings.ReplaceAll(comment.Text, "\n", " ")
8181
log.Printf("[SPAM] %+v [%.0f%%]", comment, score)
8282
}
8383
}

backend/app/cmd/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,7 @@ func newAuthRefreshCache() *authRefreshCache {
13571357

13581358
// Get implements cache getter with key converted to string
13591359
func (c *authRefreshCache) Get(key string) (token.Claims, bool) {
1360-
return c.LoadingCache.Peek(key)
1360+
return c.Peek(key)
13611361
}
13621362

13631363
// Set implements cache setter with key converted to string

backend/app/migrator/disqus.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func (d *Disqus) convert(r io.Reader, siteID string) (ch chan store.Comment) {
175175

176176
func (*Disqus) cleanText(text string) string {
177177
text = strings.TrimSpace(text)
178-
text = strings.Replace(text, "\n", "", -1)
179-
text = strings.Replace(text, "\t", "", -1)
178+
text = strings.ReplaceAll(text, "\n", "")
179+
text = strings.ReplaceAll(text, "\t", "")
180180
return text
181181
}

backend/app/notify/email_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestEmailNew(t *testing.T) {
3434
assert.NotNil(t, email, "email returned")
3535

3636
assert.NotNil(t, email.msgTmpl, "e.template is set")
37-
assert.Equal(t, emailParams.From, email.EmailParams.From, "emailParams.From unchanged after creation")
37+
assert.Equal(t, emailParams.From, email.From, "emailParams.From unchanged after creation")
3838
if smtpParams.TimeOut == 0 {
3939
assert.Equal(t, defaultEmailTimeout, email.TimeOut, "empty emailParams.TimeOut changed to default")
4040
} else {

backend/app/rest/api/admin_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ func TestAdmin_DeleteMeRequestFailed(t *testing.T) {
835835

836836
// try with wrong audience
837837
badClaimsMultipleAudience := claims
838-
badClaimsMultipleAudience.RegisteredClaims.Audience = jwt.ClaimStrings{"remark42", "something else"}
838+
badClaimsMultipleAudience.Audience = jwt.ClaimStrings{"remark42", "something else"}
839839
tkn, err = srv.Authenticator.TokenService().Token(badClaimsMultipleAudience)
840840
assert.NoError(t, err)
841841
req, err = http.NewRequest(http.MethodGet, fmt.Sprintf("%s/api/v1/admin/deleteme?token=%s", ts.URL, tkn), http.NoBody)
@@ -848,7 +848,7 @@ func TestAdmin_DeleteMeRequestFailed(t *testing.T) {
848848
assert.NoError(t, err)
849849
assert.NoError(t, resp.Body.Close())
850850
assert.Contains(t, string(b), "can't process token, claims.Audience expected to be a single element but it's not")
851-
badClaimsMultipleAudience.RegisteredClaims.Audience = jwt.ClaimStrings{"remark42"}
851+
badClaimsMultipleAudience.Audience = jwt.ClaimStrings{"remark42"}
852852
}
853853

854854
func TestAdmin_GetUserInfo(t *testing.T) {

backend/app/rest/api/migrator.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,8 @@ func (m *Migrator) waitCtrl(w http.ResponseWriter, r *http.Request) {
110110

111111
ctx, cancel := context.WithTimeout(context.Background(), timeOut)
112112
defer cancel()
113-
for {
114-
if !m.isBusy(siteID) {
115-
break
116-
}
113+
for m.isBusy(siteID) {
114+
117115
select {
118116
case <-ctx.Done():
119117
render.Status(r, http.StatusGatewayTimeout)

backend/app/rest/api/migrator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func TestMigrator_ImportFromWP(t *testing.T) {
123123
ts, _, teardown := startupT(t)
124124
defer teardown()
125125

126-
r := strings.NewReader(strings.Replace(xmlTestWP, "'", "`", -1))
126+
r := strings.NewReader(strings.ReplaceAll(xmlTestWP, "'", "`"))
127127

128128
client := &http.Client{Timeout: 1 * time.Second}
129129
defer client.CloseIdleConnections()

backend/app/rest/api/rest_public.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ func (s *public) findCommentsCtrl(w http.ResponseWriter, r *http.Request) {
129129
switch format {
130130
case "tree":
131131
withInfo := treeWithInfo{Tree: service.MakeTree(comments, sort, limit, offsetID), Info: commentsInfo}
132-
withInfo.Info.CountLeft = withInfo.Tree.CountLeft()
133-
withInfo.Info.LastComment = withInfo.Tree.LastComment()
132+
withInfo.Info.CountLeft = withInfo.CountLeft()
133+
withInfo.Info.LastComment = withInfo.LastComment()
134134
if withInfo.Nodes == nil { // eliminate json nil serialization
135135
withInfo.Nodes = []*service.Node{}
136136
}

backend/app/rest/api/rest_public_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ srv, ts := prep(t)
141141
}
142142
BKT
143143
`
144-
text = strings.Replace(text, "BKT", "```", -1)
144+
text = strings.ReplaceAll(text, "BKT", "```")
145145
j := fmt.Sprintf(`{"text": %q, "locator":{"url": "https://radio-t.com/blah1", "site": "radio-t"}}`, text)
146-
j = strings.Replace(j, "\n", "\\n", -1)
146+
j = strings.ReplaceAll(j, "\n", "\\n")
147147

148148
resp, err := post(t, ts.URL+"/api/v1/preview", j)
149149
assert.NoError(t, err)
@@ -169,9 +169,9 @@ func TestRest_PreviewCode(t *testing.T) {
169169
func main(aa string) int {return 0}
170170
BKT
171171
`
172-
text = strings.Replace(text, "BKT", "```", -1)
172+
text = strings.ReplaceAll(text, "BKT", "```")
173173
j := fmt.Sprintf(`{"text": %q, "locator":{"url": "https://radio-t.com/blah1", "site": "radio-t"}}`, text)
174-
j = strings.Replace(j, "\n", "\\n", -1)
174+
j = strings.ReplaceAll(j, "\n", "\\n")
175175

176176
resp, err := post(t, ts.URL+"/api/v1/preview", j)
177177
assert.NoError(t, err)

backend/app/rest/api/rss_test.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,7 @@ func TestServer_RssReplies(t *testing.T) {
271271
}
272272

273273
func waitOnSecChange() {
274-
for {
275-
if time.Now().Nanosecond() < 100000000 {
276-
break
277-
}
274+
for time.Now().Nanosecond() >= 100000000 {
278275
time.Sleep(10 * time.Nanosecond)
279276
}
280277
}
@@ -283,11 +280,11 @@ func waitOnSecChange() {
283280
func cleanRssFormatting(expected, actual string) (cleanExp, cleanAct string) {
284281
reSpaces := regexp.MustCompile(`[\s\p{Zs}]{2,}`)
285282

286-
expected = strings.Replace(expected, "\n", " ", -1)
287-
expected = strings.Replace(expected, "\t", " ", -1)
283+
expected = strings.ReplaceAll(expected, "\n", " ")
284+
expected = strings.ReplaceAll(expected, "\t", " ")
288285
expected = reSpaces.ReplaceAllString(expected, " ")
289286

290-
actual = strings.Replace(actual, "\n", " ", -1)
287+
actual = strings.ReplaceAll(actual, "\n", " ")
291288
actual = reSpaces.ReplaceAllString(actual, " ")
292289
return expected, actual
293290
}

0 commit comments

Comments
 (0)