Skip to content

Commit 69ea96a

Browse files
committed
disable stringsbuilder and concat-loop
1 parent d787a09 commit 69ea96a

File tree

22 files changed

+84
-101
lines changed

22 files changed

+84
-101
lines changed

.golangci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ linters:
109109
- require-error
110110
usetesting:
111111
os-temp-dir: true
112+
modernize:
113+
disable:
114+
- stringsbuilder
115+
perfsprint:
116+
concat-loop: false
112117
exclusions:
113118
generated: lax
114119
presets:

models/asymkey/ssh_key_parse.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ func parseKeyString(content string) (string, error) {
6666
lines := strings.Split(content, "\n")
6767
continuationLine := false
6868

69-
var keyContentSb strings.Builder
7069
for _, line := range lines {
7170
// Skip lines that:
7271
// 1) are a continuation of the previous line,
@@ -75,10 +74,9 @@ func parseKeyString(content string) (string, error) {
7574
if continuationLine || strings.ContainsAny(line, ":-") {
7675
continuationLine = strings.HasSuffix(line, "\\")
7776
} else {
78-
keyContentSb.WriteString(line)
77+
keyContent += line
7978
}
8079
}
81-
keyContent += keyContentSb.String()
8280

8381
t, err := extractTypeFromBase64Key(keyContent)
8482
if err != nil {

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 formatSb strings.Builder
173-
formatSb.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-
formatSb.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-
formatSb.WriteString("\n\tunitsMode[%-v]: %-v")
187+
format += "\n\tunitsMode[%-v]: %-v"
190188
args = append(args, key.LogString(), value.LogString())
191189
}
192-
formatSb.WriteString("\n\tanonymousAccessMode: %-v")
190+
format += "\n\tanonymousAccessMode: %-v"
193191
args = append(args, p.anonymousAccessMode)
194-
formatSb.WriteString("\n\teveryoneAccessMode: %-v")
192+
format += "\n\teveryoneAccessMode: %-v"
195193
args = append(args, p.everyoneAccessMode)
196-
formatSb.WriteString("\n\t]>")
197-
return fmt.Sprintf(formatSb.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/auth/password/password.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,21 @@ func NewComplexity() {
6161
}
6262

6363
func setupComplexity(values []string) {
64-
var validCharsSb strings.Builder
6564
if len(values) != 1 || values[0] != "off" {
6665
for _, val := range values {
6766
if complexity, ok := charComplexities[val]; ok {
68-
validCharsSb.WriteString(complexity.ValidChars)
67+
validChars += complexity.ValidChars
6968
requiredList = append(requiredList, complexity)
7069
}
7170
}
7271
if len(requiredList) == 0 {
7372
// No valid character classes found; use all classes as default
7473
for _, complexity := range charComplexities {
75-
validCharsSb.WriteString(complexity.ValidChars)
74+
validChars += complexity.ValidChars
7675
requiredList = append(requiredList, complexity)
7776
}
7877
}
7978
}
80-
validChars = validCharsSb.String()
8179
if validChars == "" {
8280
// No complexities to check; provide a sensible default for password generation
8381
validChars = charComplexities["lower"].ValidChars + charComplexities["upper"].ValidChars + charComplexities["digit"].ValidChars

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

modules/git/notes_nogogit.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,22 @@ func GetNote(ctx context.Context, repo *Repository, commitID string, note *Note)
2626
return err
2727
}
2828

29+
path := ""
30+
2931
tree := &notes.Tree
3032
log.Trace("Found tree with ID %q while searching for git note corresponding to the commit %q", tree.ID, commitID)
3133

3234
var entry *TreeEntry
3335
originalCommitID := commitID
34-
var pathSb strings.Builder
3536
for len(commitID) > 2 {
3637
entry, err = tree.GetTreeEntryByPath(commitID)
3738
if err == nil {
38-
pathSb.WriteString(commitID)
39+
path += commitID
3940
break
4041
}
4142
if IsErrNotExist(err) {
4243
tree, err = tree.SubTree(commitID[0:2])
43-
pathSb.WriteString(commitID[0:2] + "/")
44+
path += commitID[0:2] + "/"
4445
commitID = commitID[2:]
4546
}
4647
if err != nil {
@@ -51,7 +52,6 @@ func GetNote(ctx context.Context, repo *Repository, commitID string, note *Note)
5152
return err
5253
}
5354
}
54-
path := pathSb.String()
5555

5656
blob := entry.Blob()
5757
dataRc, err := blob.DataAsync()

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 retSb strings.Builder
26+
ret := ""
2827
for _, app := range t {
29-
retSb.WriteString(app.DisplayName + " = " + app.OpenURL + "\n")
28+
ret += app.DisplayName + " = " + app.OpenURL + "\n"
3029
}
31-
return retSb.String()
30+
return ret
3231
}
3332

3433
func DefaultOpenWithEditorApps() OpenWithEditorAppsType {

modules/setting/config_env.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,18 @@ func decodeEnvSectionKey(encoded string) (ok bool, section, key string) {
4848
inKey := false
4949
last := 0
5050
escapeStringIndices := escapeRegex.FindAllStringIndex(encoded, -1)
51-
var keySb strings.Builder
52-
var sectionSb strings.Builder
5351
for _, unescapeIdx := range escapeStringIndices {
5452
preceding := encoded[last:unescapeIdx[0]]
5553
if !inKey {
5654
if splitter := strings.Index(preceding, "__"); splitter > -1 {
57-
sectionSb.WriteString(preceding[:splitter])
55+
section += preceding[:splitter]
5856
inKey = true
59-
keySb.WriteString(preceding[splitter+2:])
57+
key += preceding[splitter+2:]
6058
} else {
61-
sectionSb.WriteString(preceding)
59+
section += preceding
6260
}
6361
} else {
64-
keySb.WriteString(preceding)
62+
key += preceding
6563
}
6664
toDecode := encoded[unescapeIdx[0]+3 : unescapeIdx[1]-1]
6765
decodedBytes := make([]byte, len(toDecode)/2)
@@ -71,14 +69,12 @@ func decodeEnvSectionKey(encoded string) (ok bool, section, key string) {
7169
decodedBytes[i] = byte(byteInt)
7270
}
7371
if inKey {
74-
keySb.Write(decodedBytes)
72+
key += string(decodedBytes)
7573
} else {
76-
sectionSb.Write(decodedBytes)
74+
section += string(decodedBytes)
7775
}
7876
last = unescapeIdx[1]
7977
}
80-
key = keySb.String()
81-
section = sectionSb.String()
8278
remaining := encoded[last:]
8379
if !inKey {
8480
if splitter := strings.Index(remaining, "__"); splitter > -1 {

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 htmlCodeSb strings.Builder
253-
htmlCodeSb.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-
htmlCodeSb.WriteString(string(ut.RenderLabelWithLink(label, template.URL(link))))
259+
htmlCode += string(ut.RenderLabelWithLink(label, template.URL(link)))
261260
}
262-
htmlCodeSb.WriteString("</span>")
263-
return template.HTML(htmlCodeSb.String())
261+
htmlCode += "</span>"
262+
return template.HTML(htmlCode)
264263
}
265264

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

modules/timeutil/since.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,14 @@ func timeSincePro(then, now time.Time, lang translation.Locale) string {
9595
return lang.TrString("tool.now")
9696
}
9797

98-
var diffStr string
99-
var timeStrSb strings.Builder
98+
var timeStr, diffStr string
10099
for {
101100
if diff == 0 {
102101
break
103102
}
104103

105104
diff, diffStr = computeTimeDiffFloor(diff, lang)
106-
timeStrSb.WriteString(", " + diffStr)
105+
timeStr += ", " + diffStr
107106
}
108-
return strings.TrimPrefix(timeStrSb.String(), ", ")
107+
return strings.TrimPrefix(timeStr, ", ")
109108
}

0 commit comments

Comments
 (0)