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 <k@knt.li>
This commit is contained in:
kolaente 2020-10-11 22:27:20 +02:00 committed by GitHub
parent e35f7e81ae
commit 64133126cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 47 additions and 41 deletions

View file

@ -96,7 +96,7 @@ func (h *Hook) Update() error {
return err
}
err := ioutil.WriteFile(h.path, []byte(strings.Replace(h.Content, "\r", "", -1)), os.ModePerm)
err := ioutil.WriteFile(h.path, []byte(strings.ReplaceAll(h.Content, "\r", "")), os.ModePerm)
if err != nil {
return err
}

View file

@ -69,7 +69,7 @@ func functionName(programCounter uintptr) []byte {
name = name[period+1:]
}
// And we should just replace the interpunct with a dot
name = bytes.Replace(name, []byte("·"), []byte("."), -1)
name = bytes.ReplaceAll(name, []byte("·"), []byte("."))
return name
}

View file

@ -683,9 +683,9 @@ func shortLinkProcessorFull(ctx *postProcessCtx, node *html.Node, noLink bool) {
absoluteLink := isLinkStr(link)
if !absoluteLink {
if image {
link = strings.Replace(link, " ", "+", -1)
link = strings.ReplaceAll(link, " ", "+")
} else {
link = strings.Replace(link, " ", "-", -1)
link = strings.ReplaceAll(link, " ", "-")
}
if !strings.Contains(link, "/") {
link = url.PathEscape(link)
@ -902,7 +902,7 @@ func emojiShortCodeProcessor(ctx *postProcessCtx, node *html.Node) {
}
alias := node.Data[m[0]:m[1]]
alias = strings.Replace(alias, ":", "", -1)
alias = strings.ReplaceAll(alias, ":", "")
converted := emoji.FromAlias(alias)
if converted == nil {
// check if this is a custom reaction

View file

@ -35,7 +35,7 @@ func TestRender_Commits(t *testing.T) {
var sha = "65f1bf27bc3bf70f64657658635e66094edbcb4d"
var commit = util.URLJoin(AppSubURL, "commit", sha)
var subtree = util.URLJoin(commit, "src")
var tree = strings.Replace(subtree, "/commit/", "/tree/", -1)
var tree = strings.ReplaceAll(subtree, "/commit/", "/tree/")
test(sha, `<p><a href="`+commit+`" rel="nofollow"><code>65f1bf27bc</code></a></p>`)
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) {
setting.StaticURLPrefix = AppURL
test := func(input, expected string) {
expected = strings.Replace(expected, "&", "&amp;", -1)
expected = strings.ReplaceAll(expected, "&", "&amp;")
buffer := RenderString("a.md", input, setting.AppSubURL, nil)
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
}

View file

@ -120,7 +120,7 @@ func gatherMissingRepoRecords(ctx context.Context) ([]*models.Repository, error)
return nil
},
); err != nil {
if strings.HasPrefix("Aborted gathering missing repo", err.Error()) {
if strings.HasPrefix(err.Error(), "Aborted gathering missing repo") {
return nil, err
}
if err2 := models.CreateRepositoryNotice("gatherMissingRepoRecords: %v", err); err2 != nil {

View file

@ -253,7 +253,7 @@ func newRepository() {
if err != nil {
log.Fatal("Failed to get home directory: %v", err)
}
homeDir = strings.Replace(homeDir, "\\", "/", -1)
homeDir = strings.ReplaceAll(homeDir, "\\", "/")
// Determine and create root git repository path.
sec := Cfg.Section("repository")

View file

@ -405,7 +405,7 @@ func getAppPath() (string, error) {
}
// Note: we don't use path.Dir here because it does not handle case
// which path starts with two "/" in Windows: "//psf/Home/..."
return strings.Replace(appPath, "\\", "/", -1), err
return strings.ReplaceAll(appPath, "\\", "/"), err
}
func getWorkPath(appPath string) string {
@ -422,7 +422,7 @@ func getWorkPath(appPath string) string {
workPath = appPath[:i]
}
}
return strings.Replace(workPath, "\\", "/", -1)
return strings.ReplaceAll(workPath, "\\", "/")
}
func init() {
@ -524,7 +524,7 @@ func NewContext() {
if err != nil {
log.Fatal("Failed to get home directory: %v", err)
}
homeDir = strings.Replace(homeDir, "\\", "/", -1)
homeDir = strings.ReplaceAll(homeDir, "\\", "/")
LogLevel = getLogLevel(Cfg.Section("log"), "LEVEL", "Info")
StacktraceLogLevel = getStacktraceLogLevel(Cfg.Section("log"), "STACKTRACE_LEVEL", "None")

View file

@ -338,7 +338,7 @@ func ParsePushHook(raw []byte) (*PushPayload, error) {
// Branch returns branch name from a payload
func (p *PushPayload) Branch() string {
return strings.Replace(p.Ref, "refs/heads/", "", -1)
return strings.ReplaceAll(p.Ref, "refs/heads/", "")
}
// .___

View file

@ -76,7 +76,7 @@ func AddUploadContext(ctx *context.Context, uploadType string) {
ctx.Data["UploadUrl"] = ctx.Repo.RepoLink + "/releases/attachments"
ctx.Data["UploadRemoveUrl"] = ctx.Repo.RepoLink + "/releases/attachments/remove"
ctx.Data["UploadLinkUrl"] = ctx.Repo.RepoLink + "/releases/attachments"
ctx.Data["UploadAccepts"] = strings.Replace(setting.Repository.Release.AllowedTypes, "|", ",", -1)
ctx.Data["UploadAccepts"] = strings.ReplaceAll(setting.Repository.Release.AllowedTypes, "|", ",")
ctx.Data["UploadMaxFiles"] = setting.Attachment.MaxFiles
ctx.Data["UploadMaxSize"] = setting.Attachment.MaxSize
} else if uploadType == "comment" {
@ -87,14 +87,14 @@ func AddUploadContext(ctx *context.Context, uploadType string) {
} else {
ctx.Data["UploadLinkUrl"] = ctx.Repo.RepoLink + "/issues/attachments"
}
ctx.Data["UploadAccepts"] = strings.Replace(setting.Attachment.AllowedTypes, "|", ",", -1)
ctx.Data["UploadAccepts"] = strings.ReplaceAll(setting.Attachment.AllowedTypes, "|", ",")
ctx.Data["UploadMaxFiles"] = setting.Attachment.MaxFiles
ctx.Data["UploadMaxSize"] = setting.Attachment.MaxSize
} else if uploadType == "repo" {
ctx.Data["UploadUrl"] = ctx.Repo.RepoLink + "/upload-file"
ctx.Data["UploadRemoveUrl"] = ctx.Repo.RepoLink + "/upload-remove"
ctx.Data["UploadLinkUrl"] = ctx.Repo.RepoLink + "/upload-file"
ctx.Data["UploadAccepts"] = strings.Replace(setting.Repository.Upload.AllowedTypes, "|", ",", -1)
ctx.Data["UploadAccepts"] = strings.ReplaceAll(setting.Repository.Upload.AllowedTypes, "|", ",")
ctx.Data["UploadMaxFiles"] = setting.Repository.Upload.MaxFiles
ctx.Data["UploadMaxSize"] = setting.Repository.Upload.FileMaxSize
}

View file

@ -28,7 +28,7 @@ func URLSanitizedError(err error, unsanitizedURL string) error {
// SanitizeMessage sanitizes a message which may contains a sensitive URL
func SanitizeMessage(message, unsanitizedURL string) string {
sanitizedURL := SanitizeURLCredentials(unsanitizedURL, true)
return strings.Replace(message, unsanitizedURL, sanitizedURL, -1)
return strings.ReplaceAll(message, unsanitizedURL, sanitizedURL)
}
// SanitizeURLCredentials sanitizes a url, either removing user credentials

View file

@ -71,9 +71,9 @@ func (s *SlackPayload) JSONPayload() ([]byte, error) {
// see: https://api.slack.com/docs/formatting
func SlackTextFormatter(s string) string {
// replace & < >
s = strings.Replace(s, "&", "&amp;", -1)
s = strings.Replace(s, "<", "&lt;", -1)
s = strings.Replace(s, ">", "&gt;", -1)
s = strings.ReplaceAll(s, "&", "&amp;")
s = strings.ReplaceAll(s, "<", "&lt;")
s = strings.ReplaceAll(s, ">", "&gt;")
return s
}
@ -81,9 +81,9 @@ func SlackTextFormatter(s string) string {
func SlackShortTextFormatter(s string) string {
s = strings.Split(s, "\n")[0]
// replace & < >
s = strings.Replace(s, "&", "&amp;", -1)
s = strings.Replace(s, "<", "&lt;", -1)
s = strings.Replace(s, ">", "&gt;", -1)
s = strings.ReplaceAll(s, "&", "&amp;")
s = strings.ReplaceAll(s, "<", "&lt;")
s = strings.ReplaceAll(s, ">", "&gt;")
return s
}