aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHana Kim <hyangah@gmail.com>2026-03-05 22:48:28 -0500
committerHyang-Ah Hana Kim <hyangah@gmail.com>2026-03-26 14:11:53 -0700
commit81ffb8b9704ea4f04dfc06ccb3300d236e8aeef2 (patch)
tree96dd18e795d7faa1a9b28ac23eaadfab3e86c5a2
parent98258ff769bbca6f3d004ce80fabf5bff8f1136c (diff)
downloadgo-x-pkgsite-81ffb8b9704ea4f04dfc06ccb3300d236e8aeef2.tar.xz
all: run go fix -stringsbuilder
Change-Id: I839e47c2b39ee592909f7ecb03603d4fb1d1954b Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/753430 Reviewed-by: Jonathan Amsterdam <jba@google.com> kokoro-CI: kokoro <noreply+kokoro@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
-rw-r--r--devtools/cmd/css/main.go12
-rw-r--r--internal/middleware/accept_requests_test.go9
-rw-r--r--internal/symbol/goapi.go7
-rw-r--r--internal/testing/htmlcheck/query.go11
4 files changed, 21 insertions, 18 deletions
diff --git a/devtools/cmd/css/main.go b/devtools/cmd/css/main.go
index 187ebe42..bcea960a 100644
--- a/devtools/cmd/css/main.go
+++ b/devtools/cmd/css/main.go
@@ -179,7 +179,7 @@ func pxToRem(value string) string {
// replaceValueWithRems replaces the px values in a line of css with rems.
// e.g: padding: 25px 10px => padding:
func replaceValueWithRems(line string) string {
- var cssLine string
+ var cssLine strings.Builder
valueRegex := regexp.MustCompile(`([-+]?[0-9]*\.?[0-9]+)px`)
matches := valueRegex.FindAllStringSubmatchIndex(line, -1)
for idx, m := range matches {
@@ -188,15 +188,15 @@ func replaceValueWithRems(line string) string {
// The value here is the full string "25px" and num is just "25".
valueStartIdx, valueEndIdx, numStartIdx, numEndIdx := m[0], m[1], m[2], m[3]
if idx == 0 {
- cssLine += line[0:valueStartIdx]
+ cssLine.WriteString(line[0:valueStartIdx])
}
- cssLine += pxToRem(line[numStartIdx:numEndIdx])
+ cssLine.WriteString(pxToRem(line[numStartIdx:numEndIdx]))
if idx == len(matches)-1 {
- cssLine += line[valueEndIdx:]
+ cssLine.WriteString(line[valueEndIdx:])
} else {
// If there are more matches for "px", add up until the start of the next match.
- cssLine += line[valueEndIdx:matches[idx+1][0]]
+ cssLine.WriteString(line[valueEndIdx:matches[idx+1][0]])
}
}
- return cssLine
+ return cssLine.String()
}
diff --git a/internal/middleware/accept_requests_test.go b/internal/middleware/accept_requests_test.go
index 24f5fa19..e1971bac 100644
--- a/internal/middleware/accept_requests_test.go
+++ b/internal/middleware/accept_requests_test.go
@@ -7,6 +7,7 @@ package middleware
import (
"net/http"
"net/http/httptest"
+ "strings"
"testing"
)
@@ -62,20 +63,20 @@ func TestAcceptRequests_URILength(t *testing.T) {
defer ts.Close()
c := ts.Client()
- var longURL string
+ var longURL strings.Builder
// Create a URL with 990 characters.
numParts := maxURILength/2 - 5
for range numParts {
- longURL += "/a"
+ longURL.WriteString("/a")
}
// Without this query param, the length of longURL will be < maxURILength.
- longURL += "?q=randomstring"
+ longURL.WriteString("?q=randomstring")
for _, test := range []struct {
name, urlPath string
want bool
}{
{"short URL", "/shorturlpath", true},
- {"long URL", longURL, false},
+ {"long URL", longURL.String(), false},
} {
called = false
req, err := http.NewRequest(http.MethodGet, ts.URL+test.urlPath, nil)
diff --git a/internal/symbol/goapi.go b/internal/symbol/goapi.go
index fd4cc840..5dbea638 100644
--- a/internal/symbol/goapi.go
+++ b/internal/symbol/goapi.go
@@ -83,7 +83,8 @@ func tagKey(dir string, context *build.Context, tags []string) string {
ctags[tag] = true
}
// TODO: ReleaseTags (need to load default)
- key := dir
+ var key strings.Builder
+ key.WriteString(dir)
// explicit on GOOS and GOARCH as global cache will use "all" cached packages for
// an indirect imported package. See https://github.com/golang/go/issues/21181
// for more detail.
@@ -91,11 +92,11 @@ func tagKey(dir string, context *build.Context, tags []string) string {
sort.Strings(tags)
for _, tag := range tags {
if ctags[tag] {
- key += "," + tag
+ key.WriteString("," + tag)
ctags[tag] = false
}
}
- return key
+ return key.String()
}
var listCache sync.Map // map[string]listImports, keyed by contextName
diff --git a/internal/testing/htmlcheck/query.go b/internal/testing/htmlcheck/query.go
index fe594150..ea082270 100644
--- a/internal/testing/htmlcheck/query.go
+++ b/internal/testing/htmlcheck/query.go
@@ -29,15 +29,16 @@ func (s *selector) String() string {
if s == nil {
return "nil"
}
- str := "["
+ var str strings.Builder
+ str.WriteString("[")
for i, atom := range s.atoms {
- str += fmt.Sprintf("%#v", atom)
+ str.WriteString(fmt.Sprintf("%#v", atom))
if i != len(s.atoms)-1 {
- str += ","
+ str.WriteString(",")
}
}
- str += "]->" + s.next.String()
- return str
+ str.WriteString("]->" + s.next.String())
+ return str.String()
}
// selectorAtom represents a part of a selector that individually