Skip to content

Commit 6413312

Browse files
authored
Update golangci-lint to version 1.31.0 (#13102)
This PR updates golangci-lint to the latest version 1.31.0. The upgrade introduced a new check for which I've fixed or disabled most cases. Signed-off-by: kolaente <[email protected]>
1 parent e35f7e8 commit 6413312

File tree

23 files changed

+47
-41
lines changed

23 files changed

+47
-41
lines changed

.golangci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,9 @@ issues:
101101
- path: cmd/dump.go
102102
linters:
103103
- dupl
104+
- text: "commentFormatting: put a space between `//` and comment text"
105+
linters:
106+
- gocritic
107+
- text: "exitAfterDefer:"
108+
linters:
109+
- gocritic

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ pr\#%: clean-all
697697
golangci-lint:
698698
@hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
699699
export BINARY="golangci-lint"; \
700-
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.30.0; \
700+
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.31.0; \
701701
fi
702702
golangci-lint run --timeout 5m
703703

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,5 +189,5 @@ func formatBuiltWith() string {
189189
return " built with " + version
190190
}
191191

192-
return " built with " + version + " : " + strings.Replace(Tags, " ", ", ", -1)
192+
return " built with " + version + " : " + strings.ReplaceAll(Tags, " ", ", ")
193193
}

models/migrations/migrations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ func dropTableColumns(sess *xorm.Session, tableName string, columnNames ...strin
680680
cols += "`" + strings.ToLower(col) + "`"
681681
}
682682
sql := fmt.Sprintf("SELECT Name FROM SYS.DEFAULT_CONSTRAINTS WHERE PARENT_OBJECT_ID = OBJECT_ID('%[1]s') AND PARENT_COLUMN_ID IN (SELECT column_id FROM sys.columns WHERE lower(NAME) IN (%[2]s) AND object_id = OBJECT_ID('%[1]s'))",
683-
tableName, strings.Replace(cols, "`", "'", -1))
683+
tableName, strings.ReplaceAll(cols, "`", "'"))
684684
constraints := make([]string, 0)
685685
if err := sess.SQL(sql).Find(&constraints); err != nil {
686686
return fmt.Errorf("Find constraints: %v", err)

modules/git/hook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (h *Hook) Update() error {
9696
return err
9797
}
9898

99-
err := ioutil.WriteFile(h.path, []byte(strings.Replace(h.Content, "\r", "", -1)), os.ModePerm)
99+
err := ioutil.WriteFile(h.path, []byte(strings.ReplaceAll(h.Content, "\r", "")), os.ModePerm)
100100
if err != nil {
101101
return err
102102
}

modules/log/stack.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func functionName(programCounter uintptr) []byte {
6969
name = name[period+1:]
7070
}
7171
// And we should just replace the interpunct with a dot
72-
name = bytes.Replace(name, []byte("·"), []byte("."), -1)
72+
name = bytes.ReplaceAll(name, []byte("·"), []byte("."))
7373
return name
7474
}
7575

modules/markup/html.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -683,9 +683,9 @@ func shortLinkProcessorFull(ctx *postProcessCtx, node *html.Node, noLink bool) {
683683
absoluteLink := isLinkStr(link)
684684
if !absoluteLink {
685685
if image {
686-
link = strings.Replace(link, " ", "+", -1)
686+
link = strings.ReplaceAll(link, " ", "+")
687687
} else {
688-
link = strings.Replace(link, " ", "-", -1)
688+
link = strings.ReplaceAll(link, " ", "-")
689689
}
690690
if !strings.Contains(link, "/") {
691691
link = url.PathEscape(link)
@@ -902,7 +902,7 @@ func emojiShortCodeProcessor(ctx *postProcessCtx, node *html.Node) {
902902
}
903903

904904
alias := node.Data[m[0]:m[1]]
905-
alias = strings.Replace(alias, ":", "", -1)
905+
alias = strings.ReplaceAll(alias, ":", "")
906906
converted := emoji.FromAlias(alias)
907907
if converted == nil {
908908
// check if this is a custom reaction

modules/markup/html_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestRender_Commits(t *testing.T) {
3535
var sha = "65f1bf27bc3bf70f64657658635e66094edbcb4d"
3636
var commit = util.URLJoin(AppSubURL, "commit", sha)
3737
var subtree = util.URLJoin(commit, "src")
38-
var tree = strings.Replace(subtree, "/commit/", "/tree/", -1)
38+
var tree = strings.ReplaceAll(subtree, "/commit/", "/tree/")
3939

4040
test(sha, `<p><a href="`+commit+`" rel="nofollow"><code>65f1bf27bc</code></a></p>`)
4141
test(sha[:7], `<p><a href="`+commit[:len(commit)-(40-7)]+`" rel="nofollow"><code>65f1bf2</code></a></p>`)
@@ -235,7 +235,7 @@ func TestRender_emoji(t *testing.T) {
235235
setting.StaticURLPrefix = AppURL
236236

237237
test := func(input, expected string) {
238-
expected = strings.Replace(expected, "&", "&amp;", -1)
238+
expected = strings.ReplaceAll(expected, "&", "&amp;")
239239
buffer := RenderString("a.md", input, setting.AppSubURL, nil)
240240
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
241241
}

modules/repository/check.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func gatherMissingRepoRecords(ctx context.Context) ([]*models.Repository, error)
120120
return nil
121121
},
122122
); err != nil {
123-
if strings.HasPrefix("Aborted gathering missing repo", err.Error()) {
123+
if strings.HasPrefix(err.Error(), "Aborted gathering missing repo") {
124124
return nil, err
125125
}
126126
if err2 := models.CreateRepositoryNotice("gatherMissingRepoRecords: %v", err); err2 != nil {

modules/setting/repository.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ func newRepository() {
253253
if err != nil {
254254
log.Fatal("Failed to get home directory: %v", err)
255255
}
256-
homeDir = strings.Replace(homeDir, "\\", "/", -1)
256+
homeDir = strings.ReplaceAll(homeDir, "\\", "/")
257257

258258
// Determine and create root git repository path.
259259
sec := Cfg.Section("repository")

modules/setting/setting.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ func getAppPath() (string, error) {
405405
}
406406
// Note: we don't use path.Dir here because it does not handle case
407407
// which path starts with two "/" in Windows: "//psf/Home/..."
408-
return strings.Replace(appPath, "\\", "/", -1), err
408+
return strings.ReplaceAll(appPath, "\\", "/"), err
409409
}
410410

411411
func getWorkPath(appPath string) string {
@@ -422,7 +422,7 @@ func getWorkPath(appPath string) string {
422422
workPath = appPath[:i]
423423
}
424424
}
425-
return strings.Replace(workPath, "\\", "/", -1)
425+
return strings.ReplaceAll(workPath, "\\", "/")
426426
}
427427

428428
func init() {
@@ -524,7 +524,7 @@ func NewContext() {
524524
if err != nil {
525525
log.Fatal("Failed to get home directory: %v", err)
526526
}
527-
homeDir = strings.Replace(homeDir, "\\", "/", -1)
527+
homeDir = strings.ReplaceAll(homeDir, "\\", "/")
528528

529529
LogLevel = getLogLevel(Cfg.Section("log"), "LEVEL", "Info")
530530
StacktraceLogLevel = getStacktraceLogLevel(Cfg.Section("log"), "STACKTRACE_LEVEL", "None")

modules/structs/hook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ func ParsePushHook(raw []byte) (*PushPayload, error) {
338338

339339
// Branch returns branch name from a payload
340340
func (p *PushPayload) Branch() string {
341-
return strings.Replace(p.Ref, "refs/heads/", "", -1)
341+
return strings.ReplaceAll(p.Ref, "refs/heads/", "")
342342
}
343343

344344
// .___

modules/upload/upload.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func AddUploadContext(ctx *context.Context, uploadType string) {
7676
ctx.Data["UploadUrl"] = ctx.Repo.RepoLink + "/releases/attachments"
7777
ctx.Data["UploadRemoveUrl"] = ctx.Repo.RepoLink + "/releases/attachments/remove"
7878
ctx.Data["UploadLinkUrl"] = ctx.Repo.RepoLink + "/releases/attachments"
79-
ctx.Data["UploadAccepts"] = strings.Replace(setting.Repository.Release.AllowedTypes, "|", ",", -1)
79+
ctx.Data["UploadAccepts"] = strings.ReplaceAll(setting.Repository.Release.AllowedTypes, "|", ",")
8080
ctx.Data["UploadMaxFiles"] = setting.Attachment.MaxFiles
8181
ctx.Data["UploadMaxSize"] = setting.Attachment.MaxSize
8282
} else if uploadType == "comment" {
@@ -87,14 +87,14 @@ func AddUploadContext(ctx *context.Context, uploadType string) {
8787
} else {
8888
ctx.Data["UploadLinkUrl"] = ctx.Repo.RepoLink + "/issues/attachments"
8989
}
90-
ctx.Data["UploadAccepts"] = strings.Replace(setting.Attachment.AllowedTypes, "|", ",", -1)
90+
ctx.Data["UploadAccepts"] = strings.ReplaceAll(setting.Attachment.AllowedTypes, "|", ",")
9191
ctx.Data["UploadMaxFiles"] = setting.Attachment.MaxFiles
9292
ctx.Data["UploadMaxSize"] = setting.Attachment.MaxSize
9393
} else if uploadType == "repo" {
9494
ctx.Data["UploadUrl"] = ctx.Repo.RepoLink + "/upload-file"
9595
ctx.Data["UploadRemoveUrl"] = ctx.Repo.RepoLink + "/upload-remove"
9696
ctx.Data["UploadLinkUrl"] = ctx.Repo.RepoLink + "/upload-file"
97-
ctx.Data["UploadAccepts"] = strings.Replace(setting.Repository.Upload.AllowedTypes, "|", ",", -1)
97+
ctx.Data["UploadAccepts"] = strings.ReplaceAll(setting.Repository.Upload.AllowedTypes, "|", ",")
9898
ctx.Data["UploadMaxFiles"] = setting.Repository.Upload.MaxFiles
9999
ctx.Data["UploadMaxSize"] = setting.Repository.Upload.FileMaxSize
100100
}

modules/util/sanitize.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func URLSanitizedError(err error, unsanitizedURL string) error {
2828
// SanitizeMessage sanitizes a message which may contains a sensitive URL
2929
func SanitizeMessage(message, unsanitizedURL string) string {
3030
sanitizedURL := SanitizeURLCredentials(unsanitizedURL, true)
31-
return strings.Replace(message, unsanitizedURL, sanitizedURL, -1)
31+
return strings.ReplaceAll(message, unsanitizedURL, sanitizedURL)
3232
}
3333

3434
// SanitizeURLCredentials sanitizes a url, either removing user credentials

modules/webhook/slack.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,19 @@ func (s *SlackPayload) JSONPayload() ([]byte, error) {
7171
// see: https://api.slack.com/docs/formatting
7272
func SlackTextFormatter(s string) string {
7373
// replace & < >
74-
s = strings.Replace(s, "&", "&amp;", -1)
75-
s = strings.Replace(s, "<", "&lt;", -1)
76-
s = strings.Replace(s, ">", "&gt;", -1)
74+
s = strings.ReplaceAll(s, "&", "&amp;")
75+
s = strings.ReplaceAll(s, "<", "&lt;")
76+
s = strings.ReplaceAll(s, ">", "&gt;")
7777
return s
7878
}
7979

8080
// SlackShortTextFormatter replaces &, <, > with HTML characters
8181
func SlackShortTextFormatter(s string) string {
8282
s = strings.Split(s, "\n")[0]
8383
// replace & < >
84-
s = strings.Replace(s, "&", "&amp;", -1)
85-
s = strings.Replace(s, "<", "&lt;", -1)
86-
s = strings.Replace(s, ">", "&gt;", -1)
84+
s = strings.ReplaceAll(s, "&", "&amp;")
85+
s = strings.ReplaceAll(s, "<", "&lt;")
86+
s = strings.ReplaceAll(s, ">", "&gt;")
8787
return s
8888
}
8989

routers/install.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
172172
}
173173

174174
// Test repository root path.
175-
form.RepoRootPath = strings.Replace(form.RepoRootPath, "\\", "/", -1)
175+
form.RepoRootPath = strings.ReplaceAll(form.RepoRootPath, "\\", "/")
176176
if err = os.MkdirAll(form.RepoRootPath, os.ModePerm); err != nil {
177177
ctx.Data["Err_RepoRootPath"] = true
178178
ctx.RenderWithErr(ctx.Tr("install.invalid_repo_path", err), tplInstall, &form)
@@ -181,7 +181,7 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
181181

182182
// Test LFS root path if not empty, empty meaning disable LFS
183183
if form.LFSRootPath != "" {
184-
form.LFSRootPath = strings.Replace(form.LFSRootPath, "\\", "/", -1)
184+
form.LFSRootPath = strings.ReplaceAll(form.LFSRootPath, "\\", "/")
185185
if err := os.MkdirAll(form.LFSRootPath, os.ModePerm); err != nil {
186186
ctx.Data["Err_LFSRootPath"] = true
187187
ctx.RenderWithErr(ctx.Tr("install.invalid_lfs_path", err), tplInstall, &form)
@@ -190,7 +190,7 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
190190
}
191191

192192
// Test log root path.
193-
form.LogRootPath = strings.Replace(form.LogRootPath, "\\", "/", -1)
193+
form.LogRootPath = strings.ReplaceAll(form.LogRootPath, "\\", "/")
194194
if err = os.MkdirAll(form.LogRootPath, os.ModePerm); err != nil {
195195
ctx.Data["Err_LogRootPath"] = true
196196
ctx.RenderWithErr(ctx.Tr("install.invalid_log_root_path", err), tplInstall, &form)

routers/repo/download.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func ServeData(ctx *context.Context, name string, reader io.Reader) error {
3434
name = path.Base(name)
3535

3636
// Google Chrome dislike commas in filenames, so let's change it to a space
37-
name = strings.Replace(name, ",", " ", -1)
37+
name = strings.ReplaceAll(name, ",", " ")
3838

3939
if base.IsTextFile(buf) || ctx.QueryBool("render") {
4040
cs, err := charset.DetectEncoding(buf)

routers/repo/editor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
238238
FromTreePath: ctx.Repo.TreePath,
239239
TreePath: form.TreePath,
240240
Message: message,
241-
Content: strings.Replace(form.Content, "\r", "", -1),
241+
Content: strings.ReplaceAll(form.Content, "\r", ""),
242242
IsNewFile: isNewFile,
243243
}); err != nil {
244244
// This is where we handle all the errors thrown by repofiles.CreateOrUpdateRepoFile

routers/repo/http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ func getGitConfig(option, dir string) string {
497497
}
498498

499499
func getConfigSetting(service, dir string) bool {
500-
service = strings.Replace(service, "-", "", -1)
500+
service = strings.ReplaceAll(service, "-", "")
501501
setting := getGitConfig("http."+service, dir)
502502

503503
if service == "uploadpack" {

routers/repo/view.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,8 @@ func renderDirectory(ctx *context.Context, treeLink string) {
332332
ctx.Data["FileContent"] = string(markup.Render(readmeFile.name, buf, readmeTreelink, ctx.Repo.Repository.ComposeDocumentMetas()))
333333
} else {
334334
ctx.Data["IsRenderedHTML"] = true
335-
ctx.Data["FileContent"] = strings.Replace(
336-
gotemplate.HTMLEscapeString(string(buf)), "\n", `<br>`, -1,
335+
ctx.Data["FileContent"] = strings.ReplaceAll(
336+
gotemplate.HTMLEscapeString(string(buf)), "\n", `<br>`,
337337
)
338338
}
339339
}
@@ -471,8 +471,8 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
471471
ctx.Data["FileContent"] = string(markup.Render(blob.Name(), buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeDocumentMetas()))
472472
} else if readmeExist {
473473
ctx.Data["IsRenderedHTML"] = true
474-
ctx.Data["FileContent"] = strings.Replace(
475-
gotemplate.HTMLEscapeString(string(buf)), "\n", `<br>`, -1,
474+
ctx.Data["FileContent"] = strings.ReplaceAll(
475+
gotemplate.HTMLEscapeString(string(buf)), "\n", `<br>`,
476476
)
477477
} else {
478478
buf = charset.ToUTF8WithFallback(buf)

routers/user/setting/security_twofa.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func twofaGenerateSecretAndQr(ctx *context.Context) bool {
9393
}
9494
}
9595
// Filter unsafe character ':' in issuer
96-
issuer := strings.Replace(setting.AppName+" ("+setting.Domain+")", ":", "", -1)
96+
issuer := strings.ReplaceAll(setting.AppName+" ("+setting.Domain+")", ":", "")
9797
if otpKey == nil {
9898
otpKey, err = totp.Generate(totp.GenerateOpts{
9999
SecretSize: 40,

routers/utils/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func SanitizeFlashErrorString(x string) string {
4747
x = "..." + string(runes[len(runes)-512:])
4848
}
4949

50-
return strings.Replace(html.EscapeString(x), "\n", "<br>", -1)
50+
return strings.ReplaceAll(html.EscapeString(x), "\n", "<br>")
5151
}
5252

5353
// IsExternalURL checks if rawURL points to an external URL like http://example.com

services/wiki/wiki.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ func nameAllowed(name string) error {
3737

3838
// NameToSubURL converts a wiki name to its corresponding sub-URL.
3939
func NameToSubURL(name string) string {
40-
return url.QueryEscape(strings.Replace(name, " ", "-", -1))
40+
return url.QueryEscape(strings.ReplaceAll(name, " ", "-"))
4141
}
4242

4343
// NormalizeWikiName normalizes a wiki name
4444
func NormalizeWikiName(name string) string {
45-
return strings.Replace(name, "-", " ", -1)
45+
return strings.ReplaceAll(name, "-", " ")
4646
}
4747

4848
// NameToFilename converts a wiki name to its corresponding filename.
4949
func NameToFilename(name string) string {
50-
name = strings.Replace(name, " ", "-", -1)
50+
name = strings.ReplaceAll(name, " ", "-")
5151
return url.QueryEscape(name) + ".md"
5252
}
5353

0 commit comments

Comments
 (0)