mirror of
https://github.com/go-gitea/gitea.git
synced 2025-12-18 21:52:48 +01:00
Bump golangci-lint to 2.7.2, enable modernize stringsbuilder (#36180)
Fixes were done automatically by `make lint-go-fix`. These modernize fixes are very readable. Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
parent
ebf9b4dc6b
commit
1e22bd712f
@ -111,9 +111,6 @@ linters:
|
||||
- require-error
|
||||
usetesting:
|
||||
os-temp-dir: true
|
||||
modernize:
|
||||
disable:
|
||||
- stringsbuilder
|
||||
perfsprint:
|
||||
concat-loop: false
|
||||
govet:
|
||||
|
||||
2
Makefile
2
Makefile
@ -32,7 +32,7 @@ XGO_VERSION := go-1.25.x
|
||||
AIR_PACKAGE ?= github.com/air-verse/air@v1
|
||||
EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/v3/cmd/editorconfig-checker@v3
|
||||
GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@v0.9.2
|
||||
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.7.0
|
||||
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.7.2
|
||||
GXZ_PACKAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.15
|
||||
MISSPELL_PACKAGE ?= github.com/golangci/misspell/cmd/misspell@v0.7.0
|
||||
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@v0.33.1
|
||||
|
||||
@ -8,6 +8,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
actions_model "code.gitea.io/gitea/models/actions"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
@ -169,7 +170,8 @@ func (p *Permission) ReadableUnitTypes() []unit.Type {
|
||||
}
|
||||
|
||||
func (p *Permission) LogString() string {
|
||||
format := "<Permission AccessMode=%s, %d Units, %d UnitsMode(s): ["
|
||||
var format strings.Builder
|
||||
format.WriteString("<Permission AccessMode=%s, %d Units, %d UnitsMode(s): [")
|
||||
args := []any{p.AccessMode.ToString(), len(p.units), len(p.unitsMode)}
|
||||
|
||||
for i, u := range p.units {
|
||||
@ -181,19 +183,19 @@ func (p *Permission) LogString() string {
|
||||
config = err.Error()
|
||||
}
|
||||
}
|
||||
format += "\n\tunits[%d]: ID=%d RepoID=%d Type=%s Config=%s"
|
||||
format.WriteString("\n\tunits[%d]: ID=%d RepoID=%d Type=%s Config=%s")
|
||||
args = append(args, i, u.ID, u.RepoID, u.Type.LogString(), config)
|
||||
}
|
||||
for key, value := range p.unitsMode {
|
||||
format += "\n\tunitsMode[%-v]: %-v"
|
||||
format.WriteString("\n\tunitsMode[%-v]: %-v")
|
||||
args = append(args, key.LogString(), value.LogString())
|
||||
}
|
||||
format += "\n\tanonymousAccessMode: %-v"
|
||||
format.WriteString("\n\tanonymousAccessMode: %-v")
|
||||
args = append(args, p.anonymousAccessMode)
|
||||
format += "\n\teveryoneAccessMode: %-v"
|
||||
format.WriteString("\n\teveryoneAccessMode: %-v")
|
||||
args = append(args, p.everyoneAccessMode)
|
||||
format += "\n\t]>"
|
||||
return fmt.Sprintf(format, args...)
|
||||
format.WriteString("\n\t]>")
|
||||
return fmt.Sprintf(format.String(), args...)
|
||||
}
|
||||
|
||||
func applyPublicAccessPermission(unitType unit.Type, accessMode perm_model.AccessMode, modeMap *map[unit.Type]perm_model.AccessMode) {
|
||||
|
||||
@ -75,9 +75,9 @@ func (f Format) Parser(r io.Reader) *Parser {
|
||||
// hexEscaped produces hex-escpaed characters from a string. For example, "\n\0"
|
||||
// would turn into "%0a%00".
|
||||
func (f Format) hexEscaped(delim []byte) string {
|
||||
escaped := ""
|
||||
var escaped strings.Builder
|
||||
for i := range delim {
|
||||
escaped += "%" + hex.EncodeToString([]byte{delim[i]})
|
||||
escaped.WriteString("%" + hex.EncodeToString([]byte{delim[i]}))
|
||||
}
|
||||
return escaped
|
||||
return escaped.String()
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
package setting
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
@ -23,11 +24,11 @@ type OpenWithEditorApp struct {
|
||||
type OpenWithEditorAppsType []OpenWithEditorApp
|
||||
|
||||
func (t OpenWithEditorAppsType) ToTextareaString() string {
|
||||
ret := ""
|
||||
var ret strings.Builder
|
||||
for _, app := range t {
|
||||
ret += app.DisplayName + " = " + app.OpenURL + "\n"
|
||||
ret.WriteString(app.DisplayName + " = " + app.OpenURL + "\n")
|
||||
}
|
||||
return ret
|
||||
return ret.String()
|
||||
}
|
||||
|
||||
func DefaultOpenWithEditorApps() OpenWithEditorAppsType {
|
||||
|
||||
@ -249,17 +249,18 @@ func (ut *RenderUtils) MarkdownToHtml(input string) template.HTML { //nolint:rev
|
||||
func (ut *RenderUtils) RenderLabels(labels []*issues_model.Label, repoLink string, issue *issues_model.Issue) template.HTML {
|
||||
isPullRequest := issue != nil && issue.IsPull
|
||||
baseLink := fmt.Sprintf("%s/%s", repoLink, util.Iif(isPullRequest, "pulls", "issues"))
|
||||
htmlCode := `<span class="labels-list">`
|
||||
var htmlCode strings.Builder
|
||||
htmlCode.WriteString(`<span class="labels-list">`)
|
||||
for _, label := range labels {
|
||||
// Protect against nil value in labels - shouldn't happen but would cause a panic if so
|
||||
if label == nil {
|
||||
continue
|
||||
}
|
||||
link := fmt.Sprintf("%s?labels=%d", baseLink, label.ID)
|
||||
htmlCode += string(ut.RenderLabelWithLink(label, template.URL(link)))
|
||||
htmlCode.WriteString(string(ut.RenderLabelWithLink(label, template.URL(link))))
|
||||
}
|
||||
htmlCode += "</span>"
|
||||
return template.HTML(htmlCode)
|
||||
htmlCode.WriteString("</span>")
|
||||
return template.HTML(htmlCode.String())
|
||||
}
|
||||
|
||||
func (ut *RenderUtils) RenderThemeItem(info *webtheme.ThemeMetaInfo, iconSize int) template.HTML {
|
||||
|
||||
@ -433,15 +433,16 @@ func makePackageVersionDependency(ctx *context.Context, version *packages_model.
|
||||
}
|
||||
|
||||
func makePackageInfo(ctx *context.Context, versions []*packages_model.PackageVersion, c *cache.EphemeralCache) (string, error) {
|
||||
ret := "---\n"
|
||||
var ret strings.Builder
|
||||
ret.WriteString("---\n")
|
||||
for _, v := range versions {
|
||||
dep, err := makePackageVersionDependency(ctx, v, c)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
ret += dep + "\n"
|
||||
ret.WriteString(dep + "\n")
|
||||
}
|
||||
return ret, nil
|
||||
return ret.String(), nil
|
||||
}
|
||||
|
||||
func makeGemFullFileName(gemName, version, platform string) string {
|
||||
|
||||
@ -179,11 +179,11 @@ func AuthorizeOAuth(ctx *context.Context) {
|
||||
errs := binding.Errors{}
|
||||
errs = form.Validate(ctx.Req, errs)
|
||||
if len(errs) > 0 {
|
||||
errstring := ""
|
||||
var errstring strings.Builder
|
||||
for _, e := range errs {
|
||||
errstring += e.Error() + "\n"
|
||||
errstring.WriteString(e.Error() + "\n")
|
||||
}
|
||||
ctx.ServerError("AuthorizeOAuth: Validate: ", fmt.Errorf("errors occurred during validation: %s", errstring))
|
||||
ctx.ServerError("AuthorizeOAuth: Validate: ", fmt.Errorf("errors occurred during validation: %s", errstring.String()))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@ -72,22 +72,22 @@ func (dc dingtalkConvertor) Push(p *api.PushPayload) (DingtalkPayload, error) {
|
||||
|
||||
title := fmt.Sprintf("[%s:%s] %s", p.Repo.FullName, branchName, commitDesc)
|
||||
|
||||
var text string
|
||||
var text strings.Builder
|
||||
// for each commit, generate attachment text
|
||||
for i, commit := range p.Commits {
|
||||
var authorName string
|
||||
if commit.Author != nil {
|
||||
authorName = " - " + commit.Author.Name
|
||||
}
|
||||
text += fmt.Sprintf("[%s](%s) %s", commit.ID[:7], commit.URL,
|
||||
strings.TrimRight(commit.Message, "\r\n")) + authorName
|
||||
text.WriteString(fmt.Sprintf("[%s](%s) %s", commit.ID[:7], commit.URL,
|
||||
strings.TrimRight(commit.Message, "\r\n")) + authorName)
|
||||
// add linebreak to each commit but the last
|
||||
if i < len(p.Commits)-1 {
|
||||
text += "\r\n"
|
||||
text.WriteString("\r\n")
|
||||
}
|
||||
}
|
||||
|
||||
return createDingtalkPayload(title, text, linkText, titleLink), nil
|
||||
return createDingtalkPayload(title, text.String(), linkText, titleLink), nil
|
||||
}
|
||||
|
||||
// Issue implements PayloadConvertor Issue method
|
||||
|
||||
@ -159,7 +159,7 @@ func (d discordConvertor) Push(p *api.PushPayload) (DiscordPayload, error) {
|
||||
|
||||
title := fmt.Sprintf("[%s:%s] %s", p.Repo.FullName, branchName, commitDesc)
|
||||
|
||||
var text string
|
||||
var text strings.Builder
|
||||
// for each commit, generate attachment text
|
||||
for i, commit := range p.Commits {
|
||||
// limit the commit message display to just the summary, otherwise it would be hard to read
|
||||
@ -169,14 +169,14 @@ func (d discordConvertor) Push(p *api.PushPayload) (DiscordPayload, error) {
|
||||
if utf8.RuneCountInString(message) > 50 {
|
||||
message = fmt.Sprintf("%.47s...", message)
|
||||
}
|
||||
text += fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL, message, commit.Author.Name)
|
||||
text.WriteString(fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL, message, commit.Author.Name))
|
||||
// add linebreak to each commit but the last
|
||||
if i < len(p.Commits)-1 {
|
||||
text += "\n"
|
||||
text.WriteString("\n")
|
||||
}
|
||||
}
|
||||
|
||||
return d.createPayload(p.Sender, title, text, titleLink, greenColor), nil
|
||||
return d.createPayload(p.Sender, title, text.String(), titleLink, greenColor), nil
|
||||
}
|
||||
|
||||
// Issue implements PayloadConvertor Issue method
|
||||
|
||||
@ -76,22 +76,23 @@ func (fc feishuConvertor) Push(p *api.PushPayload) (FeishuPayload, error) {
|
||||
commitDesc string
|
||||
)
|
||||
|
||||
text := fmt.Sprintf("[%s:%s] %s\r\n", p.Repo.FullName, branchName, commitDesc)
|
||||
var text strings.Builder
|
||||
text.WriteString(fmt.Sprintf("[%s:%s] %s\r\n", p.Repo.FullName, branchName, commitDesc))
|
||||
// for each commit, generate attachment text
|
||||
for i, commit := range p.Commits {
|
||||
var authorName string
|
||||
if commit.Author != nil {
|
||||
authorName = " - " + commit.Author.Name
|
||||
}
|
||||
text += fmt.Sprintf("[%s](%s) %s", commit.ID[:7], commit.URL,
|
||||
strings.TrimRight(commit.Message, "\r\n")) + authorName
|
||||
text.WriteString(fmt.Sprintf("[%s](%s) %s", commit.ID[:7], commit.URL,
|
||||
strings.TrimRight(commit.Message, "\r\n")) + authorName)
|
||||
// add linebreak to each commit but the last
|
||||
if i < len(p.Commits)-1 {
|
||||
text += "\r\n"
|
||||
text.WriteString("\r\n")
|
||||
}
|
||||
}
|
||||
|
||||
return newFeishuTextPayload(text), nil
|
||||
return newFeishuTextPayload(text.String()), nil
|
||||
}
|
||||
|
||||
// Issue implements PayloadConvertor Issue method
|
||||
|
||||
@ -173,18 +173,19 @@ func (m matrixConvertor) Push(p *api.PushPayload) (MatrixPayload, error) {
|
||||
|
||||
repoLink := htmlLinkFormatter(p.Repo.HTMLURL, p.Repo.FullName)
|
||||
branchLink := MatrixLinkToRef(p.Repo.HTMLURL, p.Ref)
|
||||
text := fmt.Sprintf("[%s] %s pushed %s to %s:<br>", repoLink, p.Pusher.UserName, commitDesc, branchLink)
|
||||
var text strings.Builder
|
||||
text.WriteString(fmt.Sprintf("[%s] %s pushed %s to %s:<br>", repoLink, p.Pusher.UserName, commitDesc, branchLink))
|
||||
|
||||
// for each commit, generate a new line text
|
||||
for i, commit := range p.Commits {
|
||||
text += fmt.Sprintf("%s: %s - %s", htmlLinkFormatter(commit.URL, commit.ID[:7]), commit.Message, commit.Author.Name)
|
||||
text.WriteString(fmt.Sprintf("%s: %s - %s", htmlLinkFormatter(commit.URL, commit.ID[:7]), commit.Message, commit.Author.Name))
|
||||
// add linebreak to each commit but the last
|
||||
if i < len(p.Commits)-1 {
|
||||
text += "<br>"
|
||||
text.WriteString("<br>")
|
||||
}
|
||||
}
|
||||
|
||||
return m.newPayload(text, p.Commits...)
|
||||
return m.newPayload(text.String(), p.Commits...)
|
||||
}
|
||||
|
||||
// PullRequest implements payloadConvertor PullRequest method
|
||||
|
||||
@ -131,14 +131,14 @@ func (m msteamsConvertor) Push(p *api.PushPayload) (MSTeamsPayload, error) {
|
||||
|
||||
title := fmt.Sprintf("[%s:%s] %s", p.Repo.FullName, branchName, commitDesc)
|
||||
|
||||
var text string
|
||||
var text strings.Builder
|
||||
// for each commit, generate attachment text
|
||||
for i, commit := range p.Commits {
|
||||
text += fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL,
|
||||
strings.TrimRight(commit.Message, "\r\n"), commit.Author.Name)
|
||||
text.WriteString(fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL,
|
||||
strings.TrimRight(commit.Message, "\r\n"), commit.Author.Name))
|
||||
// add linebreak to each commit but the last
|
||||
if i < len(p.Commits)-1 {
|
||||
text += "\n\n"
|
||||
text.WriteString("\n\n")
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,7 +146,7 @@ func (m msteamsConvertor) Push(p *api.PushPayload) (MSTeamsPayload, error) {
|
||||
p.Repo,
|
||||
p.Sender,
|
||||
title,
|
||||
text,
|
||||
text.String(),
|
||||
titleLink,
|
||||
greenColor,
|
||||
&MSTeamsFact{"Commit count:", strconv.Itoa(p.TotalCommits)},
|
||||
|
||||
@ -208,13 +208,13 @@ func (s slackConvertor) Push(p *api.PushPayload) (SlackPayload, error) {
|
||||
branchLink := SlackLinkToRef(p.Repo.HTMLURL, p.Ref)
|
||||
text := fmt.Sprintf("[%s:%s] %s pushed by %s", repoLink, branchLink, commitString, p.Pusher.UserName)
|
||||
|
||||
var attachmentText string
|
||||
var attachmentText strings.Builder
|
||||
// for each commit, generate attachment text
|
||||
for i, commit := range p.Commits {
|
||||
attachmentText += fmt.Sprintf("%s: %s - %s", SlackLinkFormatter(commit.URL, commit.ID[:7]), SlackShortTextFormatter(commit.Message), SlackTextFormatter(commit.Author.Name))
|
||||
attachmentText.WriteString(fmt.Sprintf("%s: %s - %s", SlackLinkFormatter(commit.URL, commit.ID[:7]), SlackShortTextFormatter(commit.Message), SlackTextFormatter(commit.Author.Name)))
|
||||
// add linebreak to each commit but the last
|
||||
if i < len(p.Commits)-1 {
|
||||
attachmentText += "\n"
|
||||
attachmentText.WriteString("\n")
|
||||
}
|
||||
}
|
||||
|
||||
@ -222,7 +222,7 @@ func (s slackConvertor) Push(p *api.PushPayload) (SlackPayload, error) {
|
||||
Color: s.Color,
|
||||
Title: p.Repo.HTMLURL,
|
||||
TitleLink: p.Repo.HTMLURL,
|
||||
Text: attachmentText,
|
||||
Text: attachmentText.String(),
|
||||
}}), nil
|
||||
}
|
||||
|
||||
|
||||
@ -94,14 +94,14 @@ func (t telegramConvertor) Push(p *api.PushPayload) (TelegramPayload, error) {
|
||||
}
|
||||
title := fmt.Sprintf(`[%s:%s] %s`, htmlLinkFormatter(p.Repo.HTMLURL, p.Repo.FullName), htmlLinkFormatter(titleLink, branchName), html.EscapeString(commitDesc))
|
||||
|
||||
var htmlCommits string
|
||||
var htmlCommits strings.Builder
|
||||
for _, commit := range p.Commits {
|
||||
htmlCommits += fmt.Sprintf("\n[%s] %s", htmlLinkFormatter(commit.URL, commit.ID[:7]), html.EscapeString(strings.TrimRight(commit.Message, "\r\n")))
|
||||
htmlCommits.WriteString(fmt.Sprintf("\n[%s] %s", htmlLinkFormatter(commit.URL, commit.ID[:7]), html.EscapeString(strings.TrimRight(commit.Message, "\r\n"))))
|
||||
if commit.Author != nil {
|
||||
htmlCommits += " - " + html.EscapeString(commit.Author.Name)
|
||||
htmlCommits.WriteString(" - " + html.EscapeString(commit.Author.Name))
|
||||
}
|
||||
}
|
||||
return createTelegramPayloadHTML(title + htmlCommits), nil
|
||||
return createTelegramPayloadHTML(title + htmlCommits.String()), nil
|
||||
}
|
||||
|
||||
// Issue implements PayloadConvertor Issue method
|
||||
|
||||
@ -77,7 +77,7 @@ func (wc wechatworkConvertor) Push(p *api.PushPayload) (WechatworkPayload, error
|
||||
|
||||
title := fmt.Sprintf("# %s:%s <font color=\"warning\"> %s </font>", p.Repo.FullName, branchName, commitDesc)
|
||||
|
||||
var text string
|
||||
var text strings.Builder
|
||||
// for each commit, generate attachment text
|
||||
for i, commit := range p.Commits {
|
||||
var authorName string
|
||||
@ -86,15 +86,15 @@ func (wc wechatworkConvertor) Push(p *api.PushPayload) (WechatworkPayload, error
|
||||
}
|
||||
|
||||
message := strings.ReplaceAll(commit.Message, "\n\n", "\r\n")
|
||||
text += fmt.Sprintf(" > [%s](%s) \r\n ><font color=\"info\">%s</font> \n ><font color=\"warning\">%s</font>", commit.ID[:7], commit.URL,
|
||||
message, authorName)
|
||||
text.WriteString(fmt.Sprintf(" > [%s](%s) \r\n ><font color=\"info\">%s</font> \n ><font color=\"warning\">%s</font>", commit.ID[:7], commit.URL,
|
||||
message, authorName))
|
||||
|
||||
// add linebreak to each commit but the last
|
||||
if i < len(p.Commits)-1 {
|
||||
text += "\n"
|
||||
text.WriteString("\n")
|
||||
}
|
||||
}
|
||||
return newWechatworkMarkdownPayload(title + "\r\n\r\n" + text), nil
|
||||
return newWechatworkMarkdownPayload(title + "\r\n\r\n" + text.String()), nil
|
||||
}
|
||||
|
||||
// Issue implements PayloadConvertor Issue method
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user