Skip to content

Commit 1cff2d4

Browse files
committed
Revert "re-enable stringsbuilder and run autofix"
This reverts commit f2347df.
1 parent f2347df commit 1cff2d4

File tree

15 files changed

+62
-66
lines changed

15 files changed

+62
-66
lines changed

.golangci.yml

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

models/perm/access/repo_permission.go

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

1312
actions_model "code.gitea.io/gitea/models/actions"
1413
"code.gitea.io/gitea/models/db"
@@ -169,8 +168,7 @@ func (p *Permission) ReadableUnitTypes() []unit.Type {
169168
}
170169

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

176174
for i, u := range p.units {
@@ -182,19 +180,19 @@ func (p *Permission) LogString() string {
182180
config = err.Error()
183181
}
184182
}
185-
format.WriteString("\n\tunits[%d]: ID=%d RepoID=%d Type=%s Config=%s")
183+
format += "\n\tunits[%d]: ID=%d RepoID=%d Type=%s Config=%s"
186184
args = append(args, i, u.ID, u.RepoID, u.Type.LogString(), config)
187185
}
188186
for key, value := range p.unitsMode {
189-
format.WriteString("\n\tunitsMode[%-v]: %-v")
187+
format += "\n\tunitsMode[%-v]: %-v"
190188
args = append(args, key.LogString(), value.LogString())
191189
}
192-
format.WriteString("\n\tanonymousAccessMode: %-v")
190+
format += "\n\tanonymousAccessMode: %-v"
193191
args = append(args, p.anonymousAccessMode)
194-
format.WriteString("\n\teveryoneAccessMode: %-v")
192+
format += "\n\teveryoneAccessMode: %-v"
195193
args = append(args, p.everyoneAccessMode)
196-
format.WriteString("\n\t]>")
197-
return fmt.Sprintf(format.String(), args...)
194+
format += "\n\t]>"
195+
return fmt.Sprintf(format, args...)
198196
}
199197

200198
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-
var escaped strings.Builder
78+
escaped := ""
7979
for i := range delim {
80-
escaped.WriteString("%" + hex.EncodeToString([]byte{delim[i]}))
80+
escaped += "%" + hex.EncodeToString([]byte{delim[i]})
8181
}
82-
return escaped.String()
82+
return escaped
8383
}

modules/setting/config.go

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

66
import (
7-
"strings"
87
"sync"
98

109
"code.gitea.io/gitea/modules/log"
@@ -24,11 +23,11 @@ type OpenWithEditorApp struct {
2423
type OpenWithEditorAppsType []OpenWithEditorApp
2524

2625
func (t OpenWithEditorAppsType) ToTextareaString() string {
27-
var ret strings.Builder
26+
ret := ""
2827
for _, app := range t {
29-
ret.WriteString(app.DisplayName + " = " + app.OpenURL + "\n")
28+
ret += app.DisplayName + " = " + app.OpenURL + "\n"
3029
}
31-
return ret.String()
30+
return ret
3231
}
3332

3433
func DefaultOpenWithEditorApps() OpenWithEditorAppsType {

modules/templates/util_render.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,18 +249,17 @@ 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-
var htmlCode strings.Builder
253-
htmlCode.WriteString(`<span class="labels-list">`)
252+
htmlCode := `<span class="labels-list">`
254253
for _, label := range labels {
255254
// Protect against nil value in labels - shouldn't happen but would cause a panic if so
256255
if label == nil {
257256
continue
258257
}
259258
link := fmt.Sprintf("%s?labels=%d", baseLink, label.ID)
260-
htmlCode.WriteString(string(ut.RenderLabelWithLink(label, template.URL(link))))
259+
htmlCode += string(ut.RenderLabelWithLink(label, template.URL(link)))
261260
}
262-
htmlCode.WriteString("</span>")
263-
return template.HTML(htmlCode.String())
261+
htmlCode += "</span>"
262+
return template.HTML(htmlCode)
264263
}
265264

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

routers/api/packages/rubygems/rubygems.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,16 +433,15 @@ 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-
var ret strings.Builder
437-
ret.WriteString("---\n")
436+
ret := "---\n"
438437
for _, v := range versions {
439438
dep, err := makePackageVersionDependency(ctx, v, c)
440439
if err != nil {
441440
return "", err
442441
}
443-
ret.WriteString(dep + "\n")
442+
ret += dep + "\n"
444443
}
445-
return ret.String(), nil
444+
return ret, nil
446445
}
447446

448447
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-
var errstring strings.Builder
182+
errstring := ""
183183
for _, e := range errs {
184-
errstring.WriteString(e.Error() + "\n")
184+
errstring += e.Error() + "\n"
185185
}
186-
ctx.ServerError("AuthorizeOAuth: Validate: ", fmt.Errorf("errors occurred during validation: %s", errstring.String()))
186+
ctx.ServerError("AuthorizeOAuth: Validate: ", fmt.Errorf("errors occurred during validation: %s", errstring))
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 strings.Builder
75+
var text string
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.WriteString(fmt.Sprintf("[%s](%s) %s", commit.ID[:7], commit.URL,
83-
strings.TrimRight(commit.Message, "\r\n")) + authorName)
82+
text += 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.WriteString("\r\n")
86+
text += "\r\n"
8787
}
8888
}
8989

90-
return createDingtalkPayload(title, text.String(), linkText, titleLink), nil
90+
return createDingtalkPayload(title, text, 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 strings.Builder
162+
var text string
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.WriteString(fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL, message, commit.Author.Name))
172+
text += 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.WriteString("\n")
175+
text += "\n"
176176
}
177177
}
178178

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

182182
// Issue implements PayloadConvertor Issue method

services/webhook/feishu.go

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

79-
var text strings.Builder
80-
text.WriteString(fmt.Sprintf("[%s:%s] %s\r\n", p.Repo.FullName, branchName, commitDesc))
79+
text := fmt.Sprintf("[%s:%s] %s\r\n", p.Repo.FullName, branchName, commitDesc)
8180
// for each commit, generate attachment text
8281
for i, commit := range p.Commits {
8382
var authorName string
8483
if commit.Author != nil {
8584
authorName = " - " + commit.Author.Name
8685
}
87-
text.WriteString(fmt.Sprintf("[%s](%s) %s", commit.ID[:7], commit.URL,
88-
strings.TrimRight(commit.Message, "\r\n")) + authorName)
86+
text += fmt.Sprintf("[%s](%s) %s", commit.ID[:7], commit.URL,
87+
strings.TrimRight(commit.Message, "\r\n")) + authorName
8988
// add linebreak to each commit but the last
9089
if i < len(p.Commits)-1 {
91-
text.WriteString("\r\n")
90+
text += "\r\n"
9291
}
9392
}
9493

95-
return newFeishuTextPayload(text.String()), nil
94+
return newFeishuTextPayload(text), nil
9695
}
9796

9897
// Issue implements PayloadConvertor Issue method

0 commit comments

Comments
 (0)