Skip to content

Commit f2347df

Browse files
committed
re-enable stringsbuilder and run autofix
1 parent b128978 commit f2347df

File tree

15 files changed

+66
-62
lines changed

15 files changed

+66
-62
lines changed

.golangci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,6 @@ linters:
109109
- require-error
110110
usetesting:
111111
os-temp-dir: true
112-
modernize:
113-
disable:
114-
- stringsbuilder
115112
perfsprint:
116113
concat-loop: false
117114
exclusions:

models/perm/access/repo_permission.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"errors"
99
"fmt"
1010
"slices"
11+
"strings"
1112

1213
actions_model "code.gitea.io/gitea/models/actions"
1314
"code.gitea.io/gitea/models/db"
@@ -168,7 +169,8 @@ func (p *Permission) ReadableUnitTypes() []unit.Type {
168169
}
169170

170171
func (p *Permission) LogString() string {
171-
format := "<Permission AccessMode=%s, %d Units, %d UnitsMode(s): ["
172+
var format strings.Builder
173+
format.WriteString("<Permission AccessMode=%s, %d Units, %d UnitsMode(s): [")
172174
args := []any{p.AccessMode.ToString(), len(p.units), len(p.unitsMode)}
173175

174176
for i, u := range p.units {
@@ -180,19 +182,19 @@ func (p *Permission) LogString() string {
180182
config = err.Error()
181183
}
182184
}
183-
format += "\n\tunits[%d]: ID=%d RepoID=%d Type=%s Config=%s"
185+
format.WriteString("\n\tunits[%d]: ID=%d RepoID=%d Type=%s Config=%s")
184186
args = append(args, i, u.ID, u.RepoID, u.Type.LogString(), config)
185187
}
186188
for key, value := range p.unitsMode {
187-
format += "\n\tunitsMode[%-v]: %-v"
189+
format.WriteString("\n\tunitsMode[%-v]: %-v")
188190
args = append(args, key.LogString(), value.LogString())
189191
}
190-
format += "\n\tanonymousAccessMode: %-v"
192+
format.WriteString("\n\tanonymousAccessMode: %-v")
191193
args = append(args, p.anonymousAccessMode)
192-
format += "\n\teveryoneAccessMode: %-v"
194+
format.WriteString("\n\teveryoneAccessMode: %-v")
193195
args = append(args, p.everyoneAccessMode)
194-
format += "\n\t]>"
195-
return fmt.Sprintf(format, args...)
196+
format.WriteString("\n\t]>")
197+
return fmt.Sprintf(format.String(), args...)
196198
}
197199

198200
func applyPublicAccessPermission(unitType unit.Type, accessMode perm_model.AccessMode, modeMap *map[unit.Type]perm_model.AccessMode) {

modules/git/foreachref/format.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ func (f Format) Parser(r io.Reader) *Parser {
7575
// hexEscaped produces hex-escpaed characters from a string. For example, "\n\0"
7676
// would turn into "%0a%00".
7777
func (f Format) hexEscaped(delim []byte) string {
78-
escaped := ""
78+
var escaped strings.Builder
7979
for i := range delim {
80-
escaped += "%" + hex.EncodeToString([]byte{delim[i]})
80+
escaped.WriteString("%" + hex.EncodeToString([]byte{delim[i]}))
8181
}
82-
return escaped
82+
return escaped.String()
8383
}

modules/setting/config.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package setting
55

66
import (
7+
"strings"
78
"sync"
89

910
"code.gitea.io/gitea/modules/log"
@@ -23,11 +24,11 @@ type OpenWithEditorApp struct {
2324
type OpenWithEditorAppsType []OpenWithEditorApp
2425

2526
func (t OpenWithEditorAppsType) ToTextareaString() string {
26-
ret := ""
27+
var ret strings.Builder
2728
for _, app := range t {
28-
ret += app.DisplayName + " = " + app.OpenURL + "\n"
29+
ret.WriteString(app.DisplayName + " = " + app.OpenURL + "\n")
2930
}
30-
return ret
31+
return ret.String()
3132
}
3233

3334
func DefaultOpenWithEditorApps() OpenWithEditorAppsType {

modules/templates/util_render.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,18 @@ func (ut *RenderUtils) MarkdownToHtml(input string) template.HTML { //nolint:rev
249249
func (ut *RenderUtils) RenderLabels(labels []*issues_model.Label, repoLink string, issue *issues_model.Issue) template.HTML {
250250
isPullRequest := issue != nil && issue.IsPull
251251
baseLink := fmt.Sprintf("%s/%s", repoLink, util.Iif(isPullRequest, "pulls", "issues"))
252-
htmlCode := `<span class="labels-list">`
252+
var htmlCode strings.Builder
253+
htmlCode.WriteString(`<span class="labels-list">`)
253254
for _, label := range labels {
254255
// Protect against nil value in labels - shouldn't happen but would cause a panic if so
255256
if label == nil {
256257
continue
257258
}
258259
link := fmt.Sprintf("%s?labels=%d", baseLink, label.ID)
259-
htmlCode += string(ut.RenderLabelWithLink(label, template.URL(link)))
260+
htmlCode.WriteString(string(ut.RenderLabelWithLink(label, template.URL(link))))
260261
}
261-
htmlCode += "</span>"
262-
return template.HTML(htmlCode)
262+
htmlCode.WriteString("</span>")
263+
return template.HTML(htmlCode.String())
263264
}
264265

265266
func (ut *RenderUtils) RenderThemeItem(info *webtheme.ThemeMetaInfo, iconSize int) template.HTML {

routers/api/packages/rubygems/rubygems.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,15 +433,16 @@ func makePackageVersionDependency(ctx *context.Context, version *packages_model.
433433
}
434434

435435
func makePackageInfo(ctx *context.Context, versions []*packages_model.PackageVersion, c *cache.EphemeralCache) (string, error) {
436-
ret := "---\n"
436+
var ret strings.Builder
437+
ret.WriteString("---\n")
437438
for _, v := range versions {
438439
dep, err := makePackageVersionDependency(ctx, v, c)
439440
if err != nil {
440441
return "", err
441442
}
442-
ret += dep + "\n"
443+
ret.WriteString(dep + "\n")
443444
}
444-
return ret, nil
445+
return ret.String(), nil
445446
}
446447

447448
func makeGemFullFileName(gemName, version, platform string) string {

routers/web/auth/oauth2_provider.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,11 @@ func AuthorizeOAuth(ctx *context.Context) {
179179
errs := binding.Errors{}
180180
errs = form.Validate(ctx.Req, errs)
181181
if len(errs) > 0 {
182-
errstring := ""
182+
var errstring strings.Builder
183183
for _, e := range errs {
184-
errstring += e.Error() + "\n"
184+
errstring.WriteString(e.Error() + "\n")
185185
}
186-
ctx.ServerError("AuthorizeOAuth: Validate: ", fmt.Errorf("errors occurred during validation: %s", errstring))
186+
ctx.ServerError("AuthorizeOAuth: Validate: ", fmt.Errorf("errors occurred during validation: %s", errstring.String()))
187187
return
188188
}
189189

services/webhook/dingtalk.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,22 @@ func (dc dingtalkConvertor) Push(p *api.PushPayload) (DingtalkPayload, error) {
7272

7373
title := fmt.Sprintf("[%s:%s] %s", p.Repo.FullName, branchName, commitDesc)
7474

75-
var text string
75+
var text strings.Builder
7676
// for each commit, generate attachment text
7777
for i, commit := range p.Commits {
7878
var authorName string
7979
if commit.Author != nil {
8080
authorName = " - " + commit.Author.Name
8181
}
82-
text += fmt.Sprintf("[%s](%s) %s", commit.ID[:7], commit.URL,
83-
strings.TrimRight(commit.Message, "\r\n")) + authorName
82+
text.WriteString(fmt.Sprintf("[%s](%s) %s", commit.ID[:7], commit.URL,
83+
strings.TrimRight(commit.Message, "\r\n")) + authorName)
8484
// add linebreak to each commit but the last
8585
if i < len(p.Commits)-1 {
86-
text += "\r\n"
86+
text.WriteString("\r\n")
8787
}
8888
}
8989

90-
return createDingtalkPayload(title, text, linkText, titleLink), nil
90+
return createDingtalkPayload(title, text.String(), linkText, titleLink), nil
9191
}
9292

9393
// Issue implements PayloadConvertor Issue method

services/webhook/discord.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (d discordConvertor) Push(p *api.PushPayload) (DiscordPayload, error) {
159159

160160
title := fmt.Sprintf("[%s:%s] %s", p.Repo.FullName, branchName, commitDesc)
161161

162-
var text string
162+
var text strings.Builder
163163
// for each commit, generate attachment text
164164
for i, commit := range p.Commits {
165165
// 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) {
169169
if utf8.RuneCountInString(message) > 50 {
170170
message = fmt.Sprintf("%.47s...", message)
171171
}
172-
text += fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL, message, commit.Author.Name)
172+
text.WriteString(fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL, message, commit.Author.Name))
173173
// add linebreak to each commit but the last
174174
if i < len(p.Commits)-1 {
175-
text += "\n"
175+
text.WriteString("\n")
176176
}
177177
}
178178

179-
return d.createPayload(p.Sender, title, text, titleLink, greenColor), nil
179+
return d.createPayload(p.Sender, title, text.String(), titleLink, greenColor), nil
180180
}
181181

182182
// Issue implements PayloadConvertor Issue method

services/webhook/feishu.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,23 @@ func (fc feishuConvertor) Push(p *api.PushPayload) (FeishuPayload, error) {
7676
commitDesc string
7777
)
7878

79-
text := fmt.Sprintf("[%s:%s] %s\r\n", p.Repo.FullName, branchName, commitDesc)
79+
var text strings.Builder
80+
text.WriteString(fmt.Sprintf("[%s:%s] %s\r\n", p.Repo.FullName, branchName, commitDesc))
8081
// for each commit, generate attachment text
8182
for i, commit := range p.Commits {
8283
var authorName string
8384
if commit.Author != nil {
8485
authorName = " - " + commit.Author.Name
8586
}
86-
text += fmt.Sprintf("[%s](%s) %s", commit.ID[:7], commit.URL,
87-
strings.TrimRight(commit.Message, "\r\n")) + authorName
87+
text.WriteString(fmt.Sprintf("[%s](%s) %s", commit.ID[:7], commit.URL,
88+
strings.TrimRight(commit.Message, "\r\n")) + authorName)
8889
// add linebreak to each commit but the last
8990
if i < len(p.Commits)-1 {
90-
text += "\r\n"
91+
text.WriteString("\r\n")
9192
}
9293
}
9394

94-
return newFeishuTextPayload(text), nil
95+
return newFeishuTextPayload(text.String()), nil
9596
}
9697

9798
// Issue implements PayloadConvertor Issue method

0 commit comments

Comments
 (0)