]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
all: Run go fix ./...
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 7 Mar 2026 15:37:47 +0000 (16:37 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 7 Mar 2026 17:30:42 +0000 (18:30 +0100)
44 files changed:
codegen/methods.go
codegen/methods_test.go
common/hashing/hashing_test.go
common/herrors/file_error_test.go
common/hreflect/convert.go
common/hreflect/helpers.go
common/types/evictingqueue_test.go
common/types/types.go
config/security/securityConfig.go
helpers/path.go
helpers/path_test.go
htesting/hqt/checkers.go
hugolib/cascade_test.go
hugolib/doctree/simpletree_test.go
hugolib/hugo_sites_build_errors_test.go
hugolib/hugo_sites_build_test.go
hugolib/hugo_smoke_test.go
hugolib/language_test.go
hugolib/page_test.go
hugolib/pages_test.go
hugolib/paginator_test.go
hugolib/rebuild_test.go
hugolib/resource_chain_test.go
hugolib/shortcode.go
hugolib/site_stats_test.go
hugolib/sitesmatrix/sitematrix_integration_test.go
hugolib/taxonomy_test.go
internal/warpc/webp.go
markup/goldmark/goldmark_integration_test.go
navigation/menu_cache_test.go
related/inverted_index_test.go
related/related_integration_test.go
resources/images/color.go
resources/page/page_generate/generate_page_wrappers.go
resources/page/pages_cache_test.go
resources/page/path_integration_test.go
tpl/collections/apply.go
tpl/collections/collections.go
tpl/collections/collections_integration_test.go
tpl/collections/index.go
tpl/collections/reflect_helpers.go
tpl/partials/partials_integration_test.go
tpl/strings/truncate.go
tpl/tplimpl/template_funcs.go

index 08ac97b0036d4ffea6ffdce814d56da4d49912be..d705914bcff29e51cfa7464fff9af6e0e4261f40 100644 (file)
@@ -73,7 +73,7 @@ func (c *Inspector) MethodsFromTypes(include []reflect.Type, exclude []reflect.T
        nameAndPackage := func(t reflect.Type) (string, string) {
                var name, pkg string
 
-               isPointer := t.Kind() == reflect.Ptr
+               isPointer := t.Kind() == reflect.Pointer
 
                if isPointer {
                        t = t.Elem()
index 0aff43d0eb9e1d873360836e24ece253edb17e97..bce80ec03f2b859acafa732c56e8485aab2becf9 100644 (file)
@@ -26,9 +26,9 @@ import (
 
 func TestMethods(t *testing.T) {
        var (
-               zeroIE     = reflect.TypeOf((*IEmbed)(nil)).Elem()
-               zeroIEOnly = reflect.TypeOf((*IEOnly)(nil)).Elem()
-               zeroI      = reflect.TypeOf((*I)(nil)).Elem()
+               zeroIE     = reflect.TypeFor[IEmbed]()
+               zeroIEOnly = reflect.TypeFor[IEOnly]()
+               zeroI      = reflect.TypeFor[I]()
        )
 
        dir, _ := os.Getwd()
index 8a165786a8e65eee0e576b95bc8353ae806914f3..de2fed8f0e96bc25f7a299124783a321e9e0b2e4 100644 (file)
@@ -38,9 +38,7 @@ func TestXxHashFromReaderPara(t *testing.T) {
 
        var wg sync.WaitGroup
        for i := range 10 {
-               wg.Add(1)
-               go func() {
-                       defer wg.Done()
+               wg.Go(func() {
                        for j := range 100 {
                                s := strings.Repeat("Hello ", i+j+1*42)
                                r := strings.NewReader(s)
@@ -50,7 +48,7 @@ func TestXxHashFromReaderPara(t *testing.T) {
                                expect, _ := XXHashFromString(s)
                                c.Assert(got, qt.Equals, expect)
                        }
-               }()
+               })
        }
 
        wg.Wait()
index 7aca08405434338746552d9f8c80159b664e2755..e7e66ca8f9b49200679eb37c0e4d6e6d598b0fbc 100644 (file)
@@ -32,15 +32,15 @@ func TestNewFileError(t *testing.T) {
        fe := NewFileErrorFromName(errors.New("bar"), "foo.html")
        c.Assert(fe.Error(), qt.Equals, `"foo.html:1:1": bar`)
 
-       lines := ""
+       var lines strings.Builder
        for i := 1; i <= 100; i++ {
-               lines += fmt.Sprintf("line %d\n", i)
+               lines.WriteString(fmt.Sprintf("line %d\n", i))
        }
 
        fe.UpdatePosition(text.Position{LineNumber: 32, ColumnNumber: 2})
        c.Assert(fe.Error(), qt.Equals, `"foo.html:32:2": bar`)
        fe.UpdatePosition(text.Position{LineNumber: 0, ColumnNumber: 0, Offset: 212})
-       fe.UpdateContent(strings.NewReader(lines), nil)
+       fe.UpdateContent(strings.NewReader(lines.String()), nil)
        c.Assert(fe.Error(), qt.Equals, `"foo.html:32:0": bar`)
        errorContext := fe.ErrorContext()
        c.Assert(errorContext, qt.IsNotNil)
index cb523348218552f73c1ee72940886127b4fff03e..e317d4aedb69cfe101a221295349fc008e13da1a 100644 (file)
@@ -96,7 +96,7 @@ func errConvert(v reflect.Value, s string) error {
 // See Issue 14079.
 func ConvertIfPossible(val reflect.Value, typ reflect.Type) (reflect.Value, bool) {
        switch val.Kind() {
-       case reflect.Ptr, reflect.Interface:
+       case reflect.Pointer, reflect.Interface:
                if val.IsNil() {
                        // Return typ's zero value.
                        return reflect.Zero(typ), true
index 0a9200007f19dd3814c8ba6add193799f23db4ca..fe11d2b9fbfdb5bef90cbedbc002941e36208969 100644 (file)
@@ -27,7 +27,7 @@ import (
 
 // IsInterfaceOrPointer returns whether the given kind is an interface or a pointer.
 func IsInterfaceOrPointer(kind reflect.Kind) bool {
-       return kind == reflect.Interface || kind == reflect.Ptr
+       return kind == reflect.Interface || kind == reflect.Pointer
 }
 
 // TODO(bep) replace the private versions in /tpl with these.
@@ -92,7 +92,7 @@ func IsSlice(v any) bool {
        return reflect.ValueOf(v).Kind() == reflect.Slice
 }
 
-var zeroType = reflect.TypeOf((*types.Zeroer)(nil)).Elem()
+var zeroType = reflect.TypeFor[types.Zeroer]()
 
 var isZeroCache sync.Map
 
@@ -136,7 +136,7 @@ func IsTruthfulValue(val reflect.Value) (truth bool) {
                truth = val.Bool()
        case reflect.Complex64, reflect.Complex128:
                truth = val.Complex() != 0
-       case reflect.Chan, reflect.Func, reflect.Ptr, reflect.Interface:
+       case reflect.Chan, reflect.Func, reflect.Pointer, reflect.Interface:
                truth = !val.IsNil()
        case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
                truth = val.Int() != 0
@@ -216,8 +216,8 @@ func GetMethodIndexByName(tp reflect.Type, name string) int {
 }
 
 var (
-       timeType           = reflect.TypeOf((*time.Time)(nil)).Elem()
-       asTimeProviderType = reflect.TypeOf((*htime.AsTimeProvider)(nil)).Elem()
+       timeType           = reflect.TypeFor[time.Time]()
+       asTimeProviderType = reflect.TypeFor[htime.AsTimeProvider]()
 )
 
 // IsTime returns whether tp is a time.Time type or if it can be converted into one
@@ -240,7 +240,7 @@ func IsValid(v reflect.Value) bool {
        }
 
        switch v.Kind() {
-       case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice:
+       case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Pointer, reflect.Slice:
                return !v.IsNil()
        }
 
@@ -347,13 +347,13 @@ func IsNil(v reflect.Value) bool {
                return true
        }
        switch v.Kind() {
-       case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice:
+       case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Pointer, reflect.Slice:
                return v.IsNil()
        }
        return false
 }
 
-var contextInterface = reflect.TypeOf((*context.Context)(nil)).Elem()
+var contextInterface = reflect.TypeFor[context.Context]()
 
 var isContextCache = hmaps.NewCache[reflect.Type, bool]()
 
index b93243f3ce718ed0b425e0770e545e69010b7849..a2fcc8e6f4b592071536d5beb72868f3b51a9fe4 100644 (file)
@@ -56,9 +56,7 @@ func TestEvictingStringQueueConcurrent(t *testing.T) {
        queue := NewEvictingQueue[string](3)
 
        for range 100 {
-               wg.Add(1)
-               go func() {
-                       defer wg.Done()
+               wg.Go(func() {
                        queue.Add(val)
                        v := queue.Peek()
                        if v != val {
@@ -68,7 +66,7 @@ func TestEvictingStringQueueConcurrent(t *testing.T) {
                        if len(vals) != 1 || vals[0] != val {
                                t.Error("wrong val")
                        }
-               }()
+               })
        }
        wg.Wait()
 }
index 3c9c3b60d6e4e573da80a9fb7b6971b0dcd58c90..733a10946a559a8d9de2a1faf89ecdcaf628fdec 100644 (file)
@@ -89,7 +89,7 @@ func IsNil(v any) bool {
 
        value := reflect.ValueOf(v)
        switch value.Kind() {
-       case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice:
+       case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Pointer, reflect.Slice:
                return value.IsNil()
        }
 
index 333cf4cc2bb3b99a2bef8aca56a7cd5586667501..d47492c0e608c414407cd2598ef7526f78d70f87 100644 (file)
@@ -202,7 +202,7 @@ func stringSliceToWhitelistHook() mapstructure.DecodeHookFuncType {
                t reflect.Type,
                data any,
        ) (any, error) {
-               if t != reflect.TypeOf(Whitelist{}) {
+               if t != reflect.TypeFor[Whitelist]() {
                        return data, nil
                }
 
index 7e7ec025267e548b5cb3c7bd19af5cfa59cc1a7d..87577f4b311aff2bf33dec393ca53ff2574eab99 100644 (file)
@@ -109,13 +109,13 @@ func GetDottedRelativePath(inPath string) string {
                return "./"
        }
 
-       var dottedPath string
+       var dottedPath strings.Builder
 
        for i := 1; i < sectionCount; i++ {
-               dottedPath += "../"
+               dottedPath.WriteString("../")
        }
 
-       return dottedPath
+       return dottedPath.String()
 }
 
 type NamedSlice struct {
index a1928b2b5e269e503a8816455d39b0ebb4ced8eb..697f420af463db013a83e46dea79f069df9e2d03 100644 (file)
@@ -364,7 +364,7 @@ func TestExtractAndGroupRootPaths(t *testing.T) {
        t.Run("Limits number of root groups", func(t *testing.T) {
                in := []string{}
                // Create 15 different root paths to exceed maxRootGroups (10)
-               for i := 0; i < 15; i++ {
+               for i := range 15 {
                        in = append(in, filepath.FromSlash(fmt.Sprintf("/path%d/subdir", i)))
                }
 
@@ -377,8 +377,8 @@ func TestExtractAndGroupRootPaths(t *testing.T) {
 
 func BenchmarkExtractAndGroupRootPaths(b *testing.B) {
        in := []string{}
-       for i := 0; i < 10; i++ {
-               for j := 0; j < 1000; j++ {
+       for i := range 10 {
+               for j := range 1000 {
                        in = append(in, fmt.Sprintf("/a/b/c/s%d/p%d", i, j))
                }
        }
index f58382fb55c827e53b0fddf65e26498f97ce5a60..a118967c118d12b6ba86c28341daeea7542b6883 100644 (file)
@@ -182,7 +182,7 @@ func structTypes(v reflect.Value, m map[reflect.Type]struct{}) {
                return
        }
        switch v.Kind() {
-       case reflect.Ptr:
+       case reflect.Pointer:
                if !v.IsNil() {
                        structTypes(v.Elem(), m)
                }
index 8eaa369b64d6bfcc97e75da9f2cb3112175629aa..21d8e20c498bc3884efffab1e1be4b582593c61a 100644 (file)
@@ -15,6 +15,7 @@ package hugolib
 
 import (
        "fmt"
+       "strings"
        "testing"
 
        "github.com/gohugoio/hugo/hugolib/sitesmatrix"
@@ -23,27 +24,28 @@ import (
 )
 
 func BenchmarkCascadeTarget(b *testing.B) {
-       files := `
+       var files strings.Builder
+       files.WriteString(`
 -- content/_index.md --
 background = 'yosemite.jpg'
 [cascade._target]
 kind = '{section,term}'
 -- content/posts/_index.md --
 -- content/posts/funny/_index.md --
-`
+`)
 
        for i := 1; i < 100; i++ {
-               files += fmt.Sprintf("\n-- content/posts/p%d.md --\n", i+1)
+               files.WriteString(fmt.Sprintf("\n-- content/posts/p%d.md --\n", i+1))
        }
 
        for i := 1; i < 100; i++ {
-               files += fmt.Sprintf("\n-- content/posts/funny/pf%d.md --\n", i+1)
+               files.WriteString(fmt.Sprintf("\n-- content/posts/funny/pf%d.md --\n", i+1))
        }
 
        b.Run("Kind", func(b *testing.B) {
                cfg := IntegrationTestConfig{
                        T:           b,
-                       TxtarString: files,
+                       TxtarString: files.String(),
                }
                b.ResetTimer()
 
index fe4c0fa84a0281437eb4f5151678021e50d89de4..e99d348f0a39df0baa38b10652d861658c0d1f11 100644 (file)
@@ -21,7 +21,7 @@ import (
 func BenchmarkSimpleThreadSafeTree(b *testing.B) {
        newTestTree := func() TreeThreadSafe[int] {
                t := NewSimpleThreadSafeTree[int]()
-               for i := 0; i < 1000; i++ {
+               for i := range 1000 {
                        t.Insert(fmt.Sprintf("key%d", i), i)
                }
                return t
index eecd86f8dcbca8b95a2cdbc5dbe73a7dcfdf41f0..3209f664d3f84947ade40c121e2b5081bb8759d4 100644 (file)
@@ -275,7 +275,6 @@ foo bar
        }
 
        for _, test := range tests {
-               test := test
                if test.name != "Base template parse failed" {
                        continue
                }
index d4456aebb2a137bd20a329f557ff64a51ffb04cc..8ea992aa09a6f54ca7bd9f5b63958ccb1fd2bf29 100644 (file)
@@ -154,7 +154,7 @@ RegularPagesRecursive: {{ range .RegularPagesRecursive }}{{ .RelPermalink }}|{{
                        return
                }
 
-               for i := 0; i < sectionsPerLevel; i++ {
+               for i := range sectionsPerLevel {
                        sectionCount++
                        sectionName := fmt.Sprintf("s%d", i)
                        sectionPath := sectionName
@@ -164,7 +164,7 @@ RegularPagesRecursive: {{ range .RegularPagesRecursive }}{{ .RelPermalink }}|{{
                        sb.WriteString(section(currentSection, i))
 
                        // Pages in this section
-                       for j := 0; j < pagesPerSection; j++ {
+                       for j := range pagesPerSection {
                                pageCount++
                                sb.WriteString(page(sectionPath, j))
                        }
index b32af4f448815aedbe7b51e1f776893638325c92..fb46cff1745ac5ed824df5d117da21a1301bded0 100644 (file)
@@ -781,7 +781,8 @@ func BenchmarkBaseline(b *testing.B) {
 func benchmarkBaselineFiles(leafBundles bool) string {
        rnd := rand.New(rand.NewSource(32))
 
-       files := `
+       var files strings.Builder
+       files.WriteString(`
 -- hugo.toml --
 baseURL = "https://example.com"
 defaultContentLanguage = 'en'
@@ -828,7 +829,7 @@ weight = 4
 {{ .Content }}
 -- layouts/_shortcodes/myshort.html --
 {{ .Inner }}
-`
+`)
 
        contentTemplate := `
 ---
@@ -855,11 +856,11 @@ Aliqua labore enim et sint anim amet excepteur ea dolore.
 `
 
        for _, lang := range []string{"en", "nn", "no", "sv"} {
-               files += fmt.Sprintf("\n-- content/%s/_index.md --\n"+contentTemplate, lang, 1, 1, 1)
+               files.WriteString(fmt.Sprintf("\n-- content/%s/_index.md --\n"+contentTemplate, lang, 1, 1, 1))
                for i, root := range []string{"", "foo", "bar", "baz"} {
                        for j, section := range []string{"posts", "posts/funny", "posts/science", "posts/politics", "posts/world", "posts/technology", "posts/world/news", "posts/world/news/europe"} {
                                n := i + j + 1
-                               files += fmt.Sprintf("\n-- content/%s/%s/%s/_index.md --\n"+contentTemplate, lang, root, section, n, n, n)
+                               files.WriteString(fmt.Sprintf("\n-- content/%s/%s/%s/_index.md --\n"+contentTemplate, lang, root, section, n, n, n))
                                for k := 1; k < rnd.Intn(30)+1; k++ {
                                        n := n + k
                                        ns := fmt.Sprintf("%d", n)
@@ -867,11 +868,11 @@ Aliqua labore enim et sint anim amet excepteur ea dolore.
                                                ns = fmt.Sprintf("%d/index", n)
                                        }
                                        file := fmt.Sprintf("\n-- content/%s/%s/%s/p%s.md --\n"+contentTemplate, lang, root, section, ns, n, n)
-                                       files += file
+                                       files.WriteString(file)
                                }
                        }
                }
        }
 
-       return files
+       return files.String()
 }
index eb7f218f8bc9a1a3878a2e00d529f006ab96ec62..e242fc90747e468ff4e3f5ea755c1016e9ad835f 100644 (file)
@@ -38,7 +38,6 @@ func TestI18n(t *testing.T) {
        }
 
        for _, tc := range testCases {
-               tc := tc
                c.Run(tc.name, func(c *qt.C) {
                        files := fmt.Sprintf(`
 -- hugo.toml --
index 6783bc1283abe669e983c575b43d46fb2b572a91..0d9c99505282fac495b984da84506e52b66ea4de 100644 (file)
@@ -320,15 +320,15 @@ func normalizeExpected(ext, str string) string {
                return strings.Trim(tpl.StripHTML(str), " ")
        case "ad":
                paragraphs := strings.Split(str, "</p>")
-               expected := ""
+               var expected strings.Builder
                for _, para := range paragraphs {
                        if para == "" {
                                continue
                        }
-                       expected += fmt.Sprintf("<div class=\"paragraph\">\n%s</p></div>\n", para)
+                       expected.WriteString(fmt.Sprintf("<div class=\"paragraph\">\n%s</p></div>\n", para))
                }
 
-               return expected
+               return expected.String()
        case "rst":
                if str == "" {
                        return "<div class=\"document\"></div>"
@@ -364,23 +364,24 @@ func testAllMarkdownEnginesForPages(t *testing.T,
                                panic("contentDir must be set to 'content' for this test")
                        }
 
-                       files := `
+                       var files strings.Builder
+                       files.WriteString(`
 -- hugo.toml --
 [security]
 [security.exec]
 allow = ['^python$', '^rst2html.*', '^asciidoctor$']
-`
+`)
 
                        for i, source := range pageSources {
-                               files += fmt.Sprintf("-- content/p%d.%s --\n%s\n", i, e.ext, source)
+                               files.WriteString(fmt.Sprintf("-- content/p%d.%s --\n%s\n", i, e.ext, source))
                        }
                        homePath := fmt.Sprintf("_index.%s", e.ext)
-                       files += fmt.Sprintf("-- content/%s --\n%s\n", homePath, homePage)
+                       files.WriteString(fmt.Sprintf("-- content/%s --\n%s\n", homePath, homePage))
 
                        b := NewIntegrationTestBuilder(
                                IntegrationTestConfig{
                                        T:           t,
-                                       TxtarString: files,
+                                       TxtarString: files.String(),
                                        NeedsOsFS:   true,
                                        BaseCfg:     cfg,
                                },
@@ -513,7 +514,8 @@ baseURL = "http://example.com/"
 func TestPageDatesSections(t *testing.T) {
        t.Parallel()
 
-       files := `
+       var files strings.Builder
+       files.WriteString(`
 -- hugo.toml --
 baseURL = "http://example.com/"
 -- content/no-index/page.md --
@@ -540,18 +542,18 @@ date: 2018-01-15
 title: Date
 date: 2018-01-15
 ---
-`
+`)
        for i := 1; i <= 20; i++ {
-               files += fmt.Sprintf(`
+               files.WriteString(fmt.Sprintf(`
 -- content/main-section/p%d.md --
 ---
 title: Date
 date: 2012-01-12
 ---
-`, i)
+`, i))
        }
 
-       b := Test(t, files)
+       b := Test(t, files.String())
 
        b.Assert(len(b.H.Sites), qt.Equals, 1)
        s := b.H.Sites[0]
@@ -1261,7 +1263,6 @@ post = ":year/:month/:day/:title/"
        }
 
        for i, test := range tests {
-               test := test
                t.Run(fmt.Sprintf("Test%d", i), func(t *testing.T) {
                        t.Parallel()
 
index bfa67ad9bc173825d1fc013501779958c68de1ca..35b82b386496512fb5b07d1a15f13b4ae71fcc69 100644 (file)
@@ -3,6 +3,7 @@ package hugolib
 import (
        "fmt"
        "math/rand"
+       "strings"
        "testing"
 
        "github.com/gohugoio/hugo/resources/page"
@@ -22,17 +23,18 @@ categories: %s
 ---
 
 `
-       files := `
+       var files strings.Builder
+       files.WriteString(`
 -- hugo.toml --
 baseURL = "http://example.com/"
 
-`
+`)
 
        for i := 1; i <= numPages; i++ {
-               files += fmt.Sprintf("-- content/page%d.md --%s\n", i, fmt.Sprintf(pageTemplate, i, rand.Intn(numPages), categoriesSlice))
+               files.WriteString(fmt.Sprintf("-- content/page%d.md --%s\n", i, fmt.Sprintf(pageTemplate, i, rand.Intn(numPages), categoriesSlice)))
        }
 
-       return Test(t, files, TestOptSkipRender())
+       return Test(t, files.String(), TestOptSkipRender())
 }
 
 func TestPagesPrevNext(t *testing.T) {
index 7c860c269f6b65c95bb5c1e57876ae5dfcc13de1..f049dddd435b8552719232d253664c6344f20315 100644 (file)
@@ -15,13 +15,15 @@ package hugolib
 
 import (
        "fmt"
+       "strings"
        "testing"
 
        qt "github.com/frankban/quicktest"
 )
 
 func TestPaginator(t *testing.T) {
-       files := `
+       var files strings.Builder
+       files.WriteString(`
 -- hugo.toml --
 baseURL = "https://example.com/foo/"
 
@@ -36,28 +38,28 @@ contentDir = "content/en"
 [languages.nn]
 weight = 2
 contentDir = "content/nn"
-`
+`)
        // Manually generate content files for the txtar string
-       for i := 0; i < 9; i++ {
-               files += fmt.Sprintf(`
+       for i := range 9 {
+               files.WriteString(fmt.Sprintf(`
 -- content/en/blog/page%d.md --
 ---
 title: Page %d
 ---
 
 Content.
-`, i, i)
-               files += fmt.Sprintf(`
+`, i, i))
+               files.WriteString(fmt.Sprintf(`
 -- content/nn/blog/page%d.md --
 ---
 title: Page %d
 ---
 
 Content.
-`, i, i)
+`, i, i))
        }
 
-       files += `
+       files.WriteString(`
 -- layouts/home.html --
 {{ $pag := $.Paginator }}
 Total: {{ $pag.TotalPages }}
@@ -80,9 +82,9 @@ URL: {{ $pag.URL }}
 {{ range $i, $e := $pag.Pagers }}
 {{ printf "%d: %d/%d  %t" $i $pag.PageNumber .PageNumber (eq . $pag) -}}
 {{ end }}
-`
+`)
 
-       b := Test(t, files)
+       b := Test(t, files.String())
 
        b.AssertFileContent("public/index.html",
                "Page Number: 1",
@@ -131,7 +133,8 @@ Paginate: {{ range (.Paginate (sort .Site.RegularPages ".File.Filename" "desc"))
 
 // https://github.com/gohugoio/hugo/issues/6797
 func TestPaginateOutputFormat(t *testing.T) {
-       files := `
+       var files strings.Builder
+       files.WriteString(`
 -- hugo.toml --
 baseURL = "http://example.com/"
 -- content/_index.md --
@@ -141,23 +144,23 @@ cascade:
   outputs:
     - JSON
 ---
-`
-       for i := 0; i < 22; i++ {
-               files += fmt.Sprintf(`
+`)
+       for i := range 22 {
+               files.WriteString(fmt.Sprintf(`
 -- content/p%d.md --
 ---
 title: "Page"
 weight: %d
 ---
-`, i+1, i+1)
+`, i+1, i+1))
        }
 
-       files += `
+       files.WriteString(`
 -- layouts/index.json --
 JSON: {{ .Paginator.TotalNumberOfElements }}: {{ range .Paginator.Pages }}|{{ .RelPermalink }}{{ end }}:DONE
-`
+`)
 
-       b := Test(t, files)
+       b := Test(t, files.String())
 
        b.AssertFileContent("public/index.json",
                `JSON: 22
index bf2c13a3cbb342754623e8d7882cde9e01ce5530..d376c162c3a3f2097a4dd6298f50b30f7ca95173 100644 (file)
@@ -1778,7 +1778,8 @@ Home.
 }
 
 func benchmarkFilesEdit(count int) string {
-       files := `
+       var files strings.Builder
+       files.WriteString(`
 -- hugo.toml --
 baseURL = "https://example.com"
 disableKinds = ["term", "taxonomy"]
@@ -1791,7 +1792,7 @@ List: {{ .Title }}|{{ .Content }}|
 ---
 title: "My Sect"
 ---
-       `
+       `)
 
        contentTemplate := `
 ---
@@ -1801,10 +1802,10 @@ P%d Content.
 `
 
        for i := range count {
-               files += fmt.Sprintf("-- content/mysect/p%d/index.md --\n%s", i, fmt.Sprintf(contentTemplate, i, i))
+               files.WriteString(fmt.Sprintf("-- content/mysect/p%d/index.md --\n%s", i, fmt.Sprintf(contentTemplate, i, i)))
        }
 
-       return files
+       return files.String()
 }
 
 func BenchmarkRebuildContentFileChange(b *testing.B) {
index 978fa3713766ee18e2011e24aba84b07eac27d1b..ba6f30d7691a155fffc851beb06c8c5dabb653b7 100644 (file)
@@ -1321,7 +1321,6 @@ Template test.
        }
 
        for _, test := range tests {
-               test := test
                t.Run(test.name, func(t *testing.T) {
                        if !test.shouldRun() {
                                t.Skip()
index 78edd8135a4025f0521866c30332df258606182c..c680620cfbe2b5ddcf43cb87db50402b2b844248 100644 (file)
@@ -446,11 +446,11 @@ func doRenderShortcode(
        }
 
        if len(sc.inner) > 0 {
-               var inner string
+               var inner strings.Builder
                for _, innerData := range sc.inner {
                        switch innerData := innerData.(type) {
                        case string:
-                               inner += innerData
+                               inner.WriteString(innerData)
                        case *shortcode:
                                s, err := prepareShortcode(level+1, innerData, data, po, isRenderString)
                                if err != nil {
@@ -461,7 +461,7 @@ func doRenderShortcode(
                                if err != nil {
                                        return zeroShortcode, err
                                }
-                               inner += ss
+                               inner.WriteString(ss)
                        default:
                                po.p.s.Log.Errorf("Illegal state on shortcode rendering of %q in page %q. Illegal type in inner data: %s ",
                                        sc.name, p.File().Path(), reflect.TypeOf(innerData))
@@ -473,7 +473,7 @@ func doRenderShortcode(
                // shortcode.
                if sc.doMarkup && (level > 0 || sc.configVersion() == 1) {
                        var err error
-                       b, err := p.pageOutput.contentRenderer.ParseAndRenderContent(ctx, []byte(inner), false)
+                       b, err := p.pageOutput.contentRenderer.ParseAndRenderContent(ctx, []byte(inner.String()), false)
                        if err != nil {
                                return zeroShortcode, err
                        }
@@ -492,7 +492,7 @@ func doRenderShortcode(
                        //     the newline.
                        switch p.m.pageConfigSource.Content.Markup {
                        case "", "markdown":
-                               if match, _ := regexp.MatchString(innerNewlineRegexp, inner); !match {
+                               if match, _ := regexp.MatchString(innerNewlineRegexp, inner.String()); !match {
                                        cleaner, err := regexp.Compile(innerCleanupRegexp)
 
                                        if err == nil {
@@ -504,7 +504,7 @@ func doRenderShortcode(
                        // TODO(bep) we may have plain text inner templates.
                        data.Inner = template.HTML(newInner)
                } else {
-                       data.Inner = template.HTML(inner)
+                       data.Inner = template.HTML(inner.String())
                }
 
        }
index 79dbfa59a9ee98ed790b5282bdac0655af3cfb6e..8f5ce6867303ad27c9c924af559e4f9f0cc20c76 100644 (file)
@@ -16,6 +16,7 @@ package hugolib
 import (
        "bytes"
        "fmt"
+       "strings"
        "testing"
 
        "github.com/gohugoio/hugo/helpers"
@@ -28,7 +29,8 @@ func TestSiteStats(t *testing.T) {
 
        c := qt.New(t)
 
-       files := `
+       var files strings.Builder
+       files.WriteString(`
 -- hugo.toml --
 baseURL = "http://example.com/blog"
 
@@ -56,7 +58,7 @@ List|{{ .Title }}|Pages: {{ .Paginator.TotalPages }}|{{ .Content }}
 -- layouts/terms.html --
 Terms List|{{ .Title }}|{{ .Content }}
 
-`
+`)
 
        pageTemplate := `---
 title: "T%d"
@@ -72,16 +74,16 @@ aliases: [/Ali%d]
        for i := range 2 {
                for j := range 2 {
                        pageID := i + j + 1
-                       files += fmt.Sprintf("\n-- content/p%d.md --\n", pageID)
-                       files += fmt.Sprintf(pageTemplate, pageID, fmt.Sprintf("- tag%d", j), fmt.Sprintf("- category%d", j), pageID)
+                       files.WriteString(fmt.Sprintf("\n-- content/p%d.md --\n", pageID))
+                       files.WriteString(fmt.Sprintf(pageTemplate, pageID, fmt.Sprintf("- tag%d", j), fmt.Sprintf("- category%d", j), pageID))
                }
        }
 
        for i := range 5 {
-               files += fmt.Sprintf("\n-- assets/myimage%d.png --\niVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==", i+1)
+               files.WriteString(fmt.Sprintf("\n-- assets/myimage%d.png --\niVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==", i+1))
        }
 
-       b := Test(t, files)
+       b := Test(t, files.String())
        h := b.H
 
        stats := []*helpers.ProcessingStats{
index 4e7bab8461a1db6ddc2b661b45b0d54db4d933d3..cf20088d514d809026c1dc2780a09c73dc058460 100644 (file)
@@ -1053,7 +1053,8 @@ All. {{ .Title }}|Lang: {{ .Site.Language.Name }}|Ver: {{ .Site.Version.Name }}|
 }
 
 func newSitesMatrixContentBenchmarkBuilder(t testing.TB, numPages int, skipRender, multipleDimensions bool) *hugolib.IntegrationTestBuilder {
-       files := `
+       var files strings.Builder
+       files.WriteString(`
 -- hugo.toml --
 disableKinds = ["rss", "sitemap", "section", "taxonomy", "term"]
 defaultContentLanguage = "en"
@@ -1069,10 +1070,10 @@ title = "Benchmark"
 weight = 1
 
 
-`
+`)
 
        if multipleDimensions {
-               files += `
+               files.WriteString(`
 [languages.nn]
 weight = 2
 [languages.sv]
@@ -1087,10 +1088,10 @@ weight = 3
 weight = 300
 [roles.member]
 weight = 200
-`
+`)
        }
 
-       files += `
+       files.WriteString(`
 
 [[module.mounts]]
 source = 'content'
@@ -1101,31 +1102,31 @@ versions  = ["**"]
 roles = ["**"]
 -- layouts/all.html --
 All. {{ .Title }}|
-`
+`)
        if multipleDimensions {
-               files += `
+               files.WriteString(`
 Rotate(language): {{ with .Rotate "language" }}{{ range . }}{{ template "printp" . }}|{{ end }}{{ end }}$
 Rotate(version): {{ with .Rotate "version" }}{{ range . }}{{ template "printp" . }}|{{ end }}{{ end }}$
 Rotate(role): {{ with .Rotate "role" }}{{ range . }}{{ template "printp" . }}|{{ end }}{{ end }}$
 {{ define "printp" }}{{ .RelPermalink }}:{{ with .Site }}{{ template "prints" . }}{{ end }}{{ end }}
 {{ define "prints" }}/l:{{ .Language.Name }}/v:{{ .Version.Name }}/r:{{ .Role.Name }}{{ end }}
 
-`
+`)
        }
 
        for i := range numPages {
-               files += fmt.Sprintf(`
+               files.WriteString(fmt.Sprintf(`
 -- content/p%d/index.md --
 ---
 title: "P%d"
 ---
-`, i+1, i+1)
+`, i+1, i+1))
        }
 
        b := hugolib.NewIntegrationTestBuilder(
                hugolib.IntegrationTestConfig{
                        T:           t,
-                       TxtarString: files,
+                       TxtarString: files.String(),
                        BuildCfg: hugolib.BuildCfg{
                                SkipRender: skipRender,
                        },
index 72beb587e2f3d9c610f8d03d15983c5d4a965bfa..c663096165703d36977f301caee731c5edb256a0 100644 (file)
@@ -15,6 +15,7 @@ package hugolib
 
 import (
        "fmt"
+       "strings"
        "testing"
 
        "github.com/gohugoio/hugo/resources/kinds"
@@ -144,7 +145,8 @@ categories: ["This is Cool", "And new" ]
 Content.
 `
 
-       files := `
+       var files strings.Builder
+       files.WriteString(`
 -- hugo.toml --
 baseURL = "http://example.com"
 -- layouts/home.html --
@@ -161,13 +163,13 @@ baseURL = "http://example.com"
             <li><a href="{{ .Page.Permalink }}">{{ .Page.Title }}</a> {{ .Count }}</li>
     {{ end }}
 </ul>
-`
+`)
 
        for i := range 10 {
-               files += fmt.Sprintf("\n-- content/page%d.md --\n%s", i+1, pageContent)
+               files.WriteString(fmt.Sprintf("\n-- content/page%d.md --\n%s", i+1, pageContent))
        }
 
-       b := Test(t, files)
+       b := Test(t, files.String())
 
        b.AssertFileContent("public/index.html", `<li><a href="http://example.com/tags/hugo-rocks/">Hugo Rocks!</a> 10</li>`)
        b.AssertFileContent("public/categories/index.html", `<li><a href="http://example.com/categories/this-is-cool/">This Is Cool</a> 10</li>`)
@@ -845,7 +847,8 @@ func BenchmarkTaxonomiesGetTerms(b *testing.B) {
        createBuilder := func(b *testing.B, numPages int) *IntegrationTestBuilder {
                b.StopTimer()
 
-               files := `
+               var files strings.Builder
+               files.WriteString(`
 -- hugo.toml --
 baseURL = "https://example.com"
 disableKinds = ["RSS", "sitemap", "section"]
@@ -856,7 +859,7 @@ List.
 -- layouts/single.html --
 GetTerms.tags: {{ range .GetTerms "tags" }}{{ .Title }}|{{ end }}
 -- content/_index.md --
-`
+`)
 
                tagsVariants := []string{
                        "tags: ['a']",
@@ -871,12 +874,12 @@ GetTerms.tags: {{ range .GetTerms "tags" }}{{ .Title }}|{{ end }}
 
                for i := 1; i < numPages; i++ {
                        tags := tagsVariants[i%len(tagsVariants)]
-                       files += fmt.Sprintf("\n-- content/posts/p%d.md --\n---\n%s\n---", i+1, tags)
+                       files.WriteString(fmt.Sprintf("\n-- content/posts/p%d.md --\n---\n%s\n---", i+1, tags))
                }
 
                cfg := IntegrationTestConfig{
                        T:           b,
-                       TxtarString: files,
+                       TxtarString: files.String(),
                }
 
                bb := NewIntegrationTestBuilder(cfg)
index a241324d57e246ff8a802aeb03425ab5876db29c..a3ca19762a5ade15583fd2229db684b2a2e3e1d1 100644 (file)
@@ -141,7 +141,7 @@ func (d *WebpCodec) Decode(r io.Reader) (image.Image, error) {
 
                frameSize := stride * h
                frames := make([]image.Image, len(destination.Bytes())/frameSize)
-               for i := 0; i < len(frames); i++ {
+               for i := range frames {
                        frameBytes := destination.Bytes()[i*frameSize : (i+1)*frameSize]
                        frameImg := &image.NRGBA{
                                Pix:    frameBytes,
@@ -166,10 +166,10 @@ func (d *WebpCodec) Decode(r io.Reader) (image.Image, error) {
                rgbData := destination.Bytes()
                nrgbaStride = w * 4
                pix = make([]byte, nrgbaStride*h)
-               for y := 0; y < h; y++ {
+               for y := range h {
                        srcIdx := y * stride
                        dstIdx := y * nrgbaStride
-                       for x := 0; x < w; x++ {
+                       for range w {
                                pix[dstIdx+0] = rgbData[srcIdx+0] // R
                                pix[dstIdx+1] = rgbData[srcIdx+1] // G
                                pix[dstIdx+2] = rgbData[srcIdx+2] // B
index a6fea53cff20b3bf6bcc933cea4d660f533a2853..b1c18203483c42ba50585c60b8544a5a4d4a1a0f 100644 (file)
@@ -232,7 +232,8 @@ LINE8
 }
 
 func BenchmarkRenderHooks(b *testing.B) {
-       files := `
+       var files strings.Builder
+       files.WriteString(`
 -- hugo.toml --
 -- layouts/_markup/render-heading.html --
 <h{{ .Level }} id="{{ .Anchor | safeURL }}">
@@ -243,7 +244,7 @@ func BenchmarkRenderHooks(b *testing.B) {
 <a href="{{ .Destination | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}>{{ .Text }}</a>
 -- layouts/single.html --
 {{ .Content }}
-`
+`)
 
        content := `
 
@@ -271,12 +272,12 @@ D.
 `
 
        for i := 1; i < 100; i++ {
-               files += fmt.Sprintf("\n-- content/posts/p%d.md --\n"+content, i+1)
+               files.WriteString(fmt.Sprintf("\n-- content/posts/p%d.md --\n"+content, i+1))
        }
 
        cfg := hugolib.IntegrationTestConfig{
                T:           b,
-               TxtarString: files,
+               TxtarString: files.String(),
        }
 
        for b.Loop() {
@@ -288,7 +289,8 @@ D.
 }
 
 func BenchmarkCodeblocks(b *testing.B) {
-       filesTemplate := `
+       var filesTemplate strings.Builder
+       filesTemplate.WriteString(`
 -- hugo.toml --
 [markup]
   [markup.highlight]
@@ -305,7 +307,7 @@ func BenchmarkCodeblocks(b *testing.B) {
     tabWidth = 4
 -- layouts/single.html --
 {{ .Content }}
-`
+`)
 
        content := `
 
@@ -325,7 +327,7 @@ FENCE
        content = strings.ReplaceAll(content, "FENCE", "```")
 
        for i := 1; i < 100; i++ {
-               filesTemplate += fmt.Sprintf("\n-- content/posts/p%d.md --\n"+content, i+1)
+               filesTemplate.WriteString(fmt.Sprintf("\n-- content/posts/p%d.md --\n"+content, i+1))
        }
 
        runBenchmark := func(files string, b *testing.B) {
@@ -343,11 +345,11 @@ FENCE
        }
 
        b.Run("Default", func(b *testing.B) {
-               runBenchmark(filesTemplate, b)
+               runBenchmark(filesTemplate.String(), b)
        })
 
        b.Run("Hook no higlight", func(b *testing.B) {
-               files := filesTemplate + `
+               files := filesTemplate.String() + `
 -- layouts/_markup/render-codeblock.html --
 {{ .Inner }}
 `
index a1f56b416205dd2bc40357e7dd8831ef84084e41..98e98c4425176d72ce0f077c040e2ec120c47065 100644 (file)
@@ -55,9 +55,7 @@ func TestMenuCache(t *testing.T) {
        }
 
        for range 100 {
-               wg.Add(1)
-               go func() {
-                       defer wg.Done()
+               wg.Go(func() {
                        for k, menu := range testMenuSets {
                                l1.Lock()
                                m, ca := c1.get("k1", nil, menu)
@@ -76,7 +74,7 @@ func TestMenuCache(t *testing.T) {
                                c.Assert(m3, qt.Not(qt.IsNil))
                                c.Assert("changed", qt.Equals, m3[0].Title)
                        }
-               }()
+               })
        }
        wg.Wait()
 }
index c44be4a6289fd92926ad60846939a14b06d56bf6..b33d42955d2cd59527d65ce1be1c40bdfdf7b4cf 100644 (file)
@@ -17,6 +17,7 @@ import (
        "context"
        "fmt"
        "math/rand"
+       "strings"
        "testing"
        "time"
 
@@ -31,15 +32,16 @@ type testDoc struct {
 }
 
 func (d *testDoc) String() string {
-       s := "\n"
+       var s strings.Builder
+       s.WriteString("\n")
        for k, v := range d.keywords {
-               s += k + ":\t\t"
+               s.WriteString(k + ":\t\t")
                for _, vv := range v {
-                       s += "  " + vv.String()
+                       s.WriteString("  " + vv.String())
                }
-               s += "\n"
+               s.WriteString("\n")
        }
-       return s
+       return s.String()
 }
 
 func (d *testDoc) Name() string {
index 19a31acd234eee1e63359e05bc4e283a1a926879..fe625eba56ce14f29b73323787d6eb8674cdd30a 100644 (file)
@@ -16,6 +16,7 @@ package related_test
 import (
        "fmt"
        "math/rand"
+       "strings"
        "testing"
 
        "github.com/gohugoio/hugo/hugolib"
@@ -134,7 +135,8 @@ Related 2: 2
 }
 
 func BenchmarkRelatedSite(b *testing.B) {
-       files := `
+       var files strings.Builder
+       files.WriteString(`
 -- hugo.toml --
 baseURL = "http://example.com/"
 disableKinds = ["taxonomy", "term", "RSS", "sitemap", "robotsTXT"]
@@ -151,7 +153,7 @@ disableKinds = ["taxonomy", "term", "RSS", "sitemap", "robotsTXT"]
   weight = 30  
 -- layouts/single.html --
 Len related: {{ site.RegularPages.Related . | len }}
-`
+`)
 
        createContent := func(n int) string {
                base := `---
@@ -168,12 +170,12 @@ keywords: ['k%d']
        }
 
        for i := 1; i < 100; i++ {
-               files += fmt.Sprintf("\n-- content/posts/p%d.md --\n"+createContent(i+1), i+1)
+               files.WriteString(fmt.Sprintf("\n-- content/posts/p%d.md --\n"+createContent(i+1), i+1))
        }
 
        cfg := hugolib.IntegrationTestConfig{
                T:           b,
-               TxtarString: files,
+               TxtarString: files.String(),
        }
 
        for b.Loop() {
index c7f3b9eb6a1ac1aa5a31574379324be061bc6376..47c2848b9f461d1ab85be4d0cd18396f3544695c 100644 (file)
@@ -172,11 +172,11 @@ func hexStringToColorGo(s string) (color.Color, error) {
        s = strings.ToLower(s)
 
        if len(s) == 3 || len(s) == 4 {
-               var v string
+               var v strings.Builder
                for _, r := range s {
-                       v += string(r) + string(r)
+                       v.WriteString(string(r) + string(r))
                }
-               s = v
+               s = v.String()
        }
 
        // Standard colors.
index d720b8a42099df91a0fb2f6e53fcada89f8f6de4..87e766a7e14ddf856915bc31658cff991c85a615 100644 (file)
@@ -19,6 +19,7 @@ import (
        "os"
        "path/filepath"
        "reflect"
+       "strings"
 
        "github.com/gohugoio/hugo/codegen"
        "github.com/gohugoio/hugo/resources/page"
@@ -41,7 +42,7 @@ const header = `// Copyright 2019 The Hugo Authors. All rights reserved.
 `
 
 var (
-       pageInterface = reflect.TypeOf((*page.PageMetaProvider)(nil)).Elem()
+       pageInterface = reflect.TypeFor[page.PageMetaProvider]()
 
        packageDir = filepath.FromSlash("resources/page")
 )
@@ -105,10 +106,11 @@ func importsString(imps []string) string {
                return fmt.Sprintf("import %q", imps[0])
        }
 
-       impsStr := "import (\n"
+       var impsStr strings.Builder
+       impsStr.WriteString("import (\n")
        for _, imp := range imps {
-               impsStr += fmt.Sprintf("%q\n", imp)
+               impsStr.WriteString(fmt.Sprintf("%q\n", imp))
        }
 
-       return impsStr + ")"
+       return impsStr.String() + ")"
 }
index 6cbc71d10c54936d6d25d7715ee2dfd9d4f39832..44e540bac91da15d11f955dddb7b002eff88ae09 100644 (file)
@@ -46,9 +46,7 @@ func TestPageCache(t *testing.T) {
        }
 
        for range 100 {
-               wg.Add(1)
-               go func() {
-                       defer wg.Done()
+               wg.Go(func() {
                        for k, pages := range testPageSets {
                                l1.Lock()
                                p, ca := c1.get("k1", nil, pages)
@@ -67,7 +65,7 @@ func TestPageCache(t *testing.T) {
                                c.Assert(p3, qt.Not(qt.IsNil))
                                c.Assert("changed", qt.Equals, p3[0].(*testPage).description)
                        }
-               }()
+               })
        }
        wg.Wait()
 }
index 5393f1d0e28752cf5bcbe8f54e9ff07900b4dcf9..bd213267f35d5903f1416a345aa10e6dbfada56b 100644 (file)
@@ -59,7 +59,8 @@ title: p#2
 func TestMiscPathIssues(t *testing.T) {
        t.Parallel()
 
-       filesTemplate := `
+       var filesTemplate strings.Builder
+       filesTemplate.WriteString(`
 -- hugo.toml --
 uglyURLs = false
 
@@ -98,7 +99,7 @@ title: tags
 ---
 title: red
 ---
-`
+`)
 
        templates := []string{
                "layouts/home.html",
@@ -116,10 +117,10 @@ title: red
        const code string = "TITLE: {{ .Title }} | AOFRP: {{ range .AlternativeOutputFormats }}{{ .RelPermalink }}{{ end }} | TEMPLATE: {{ templates.Current.Name }}"
 
        for _, template := range templates {
-               filesTemplate += "-- " + template + " --\n" + code + "\n"
+               filesTemplate.WriteString("-- " + template + " --\n" + code + "\n")
        }
 
-       files := filesTemplate
+       files := filesTemplate.String()
 
        b := hugolib.Test(t, files)
 
@@ -137,7 +138,7 @@ title: red
        b.AssertFileContent("public/print/tags/index.txt", "TITLE: tags | AOFRP: /tags/ | TEMPLATE: taxonomy.print.txt")
        b.AssertFileContent("public/print/tags/red/index.txt", "TITLE: red | AOFRP: /tags/red/ | TEMPLATE: term.print.txt")
 
-       files = strings.ReplaceAll(filesTemplate, "uglyURLs = false", "uglyURLs = true")
+       files = strings.ReplaceAll(filesTemplate.String(), "uglyURLs = false", "uglyURLs = true")
        b = hugolib.Test(t, files)
 
        // uglyURLs: true, outputFormat: html
index 23c6a74976ad9efc58918a52876233ce2803b64b..ca8b0075b1759e84ecb63f62e88af3ccc8a52d99 100644 (file)
@@ -64,7 +64,7 @@ func (ns *Namespace) Apply(ctx context.Context, c any, fname string, args ...any
        }
 }
 
-var typeOfReflectValue = reflect.TypeOf(reflect.Value{})
+var typeOfReflectValue = reflect.TypeFor[reflect.Value]()
 
 func applyFnToThis(ctx context.Context, fn, this reflect.Value, args ...any) (reflect.Value, error) {
        num := fn.Type().NumIn()
index 749ed612f2f257b095d545721911ade09f63ee28..04840f8c436ddb0405a15a07ffb82df28bb6312d 100644 (file)
@@ -121,7 +121,7 @@ func (ns *Namespace) Delimit(ctx context.Context, l, sep any, last ...any) (stri
                return "", errors.New("can't iterate over a nil value")
        }
 
-       var str string
+       var str strings.Builder
        switch lv.Kind() {
        case reflect.Map:
                sortSeq, err := ns.Sort(ctx, l)
@@ -139,11 +139,11 @@ func (ns *Namespace) Delimit(ctx context.Context, l, sep any, last ...any) (stri
                        }
                        switch {
                        case i == lv.Len()-2 && dLast != nil:
-                               str += valStr + *dLast
+                               str.WriteString(valStr + *dLast)
                        case i == lv.Len()-1:
-                               str += valStr
+                               str.WriteString(valStr)
                        default:
-                               str += valStr + d
+                               str.WriteString(valStr + d)
                        }
                }
 
@@ -151,7 +151,7 @@ func (ns *Namespace) Delimit(ctx context.Context, l, sep any, last ...any) (stri
                return "", fmt.Errorf("can't iterate over %T", l)
        }
 
-       return str, nil
+       return str.String(), nil
 }
 
 // Dictionary creates a new map from the given parameters by
@@ -621,7 +621,7 @@ func (i *intersector) handleValuePair(l1vv, l2vv reflect.Value) {
                if err1 == nil && err2 == nil && f1 == f2 {
                        i.appendIfNotSeen(l1vv)
                }
-       case kind == reflect.Ptr, kind == reflect.Struct:
+       case kind == reflect.Pointer, kind == reflect.Struct:
                if types.Unwrapv(l1vv.Interface()) == types.Unwrapv(l2vv.Interface()) {
                        i.appendIfNotSeen(l1vv)
                }
@@ -701,7 +701,7 @@ func (ns *Namespace) Union(l1, l2 any) (any, error) {
                                        if err == nil {
                                                ins.appendIfNotSeen(l2vv)
                                        }
-                               case kind == reflect.Interface, kind == reflect.Struct, kind == reflect.Ptr:
+                               case kind == reflect.Interface, kind == reflect.Struct, kind == reflect.Pointer:
                                        ins.appendIfNotSeen(l2vv)
 
                                }
index 750ea7cd841948bc6296704406f5f609c795b120..5f5ce10ddfb1c238d358639b560580d202f35e9f 100644 (file)
@@ -16,6 +16,7 @@ package collections_test
 import (
        "context"
        "fmt"
+       "strings"
        "testing"
 
        "github.com/gohugoio/hugo/hugolib"
@@ -568,17 +569,18 @@ title: Page%04d
 ---
 `
 
-       files := `
+       var files strings.Builder
+       files.WriteString(`
 -- hugo.toml --
 -- layouts/all.html --
 All.
-`
+`)
 
-       for i := 0; i < 500; i++ {
-               files += fmt.Sprintf(pageTemplate, i, i)
+       for i := range 500 {
+               files.WriteString(fmt.Sprintf(pageTemplate, i, i))
        }
 
-       bb := hugolib.Test(b, files, hugolib.TestOptWithConfig(func(conf *hugolib.IntegrationTestConfig) {
+       bb := hugolib.Test(b, files.String(), hugolib.TestOptWithConfig(func(conf *hugolib.IntegrationTestConfig) {
                conf.BuildCfg = hugolib.BuildCfg{
                        SkipRender: true,
                }
index 999abf829c243fc9bb6705777ae65a0f9486bb1f..6209a7e58174cd3ee6835839cfc3e8435eb9dee2 100644 (file)
@@ -138,7 +138,7 @@ func prepareArg(value reflect.Value, argType reflect.Type) (reflect.Value, error
 // Copied from Go stdlib src/text/template/exec.go.
 func canBeNil(typ reflect.Type) bool {
        switch typ.Kind() {
-       case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice:
+       case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Pointer, reflect.Slice:
                return true
        }
        return false
index 14b10c32fed751e7d960744ac3c017430aad3e8a..56634fd42813ec1d3bc61399bb9dd9fc09b034d6 100644 (file)
@@ -108,7 +108,7 @@ func newSliceElement(items any) any {
        switch tp.Kind() {
        case reflect.Array, reflect.Slice:
                tp = tp.Elem()
-               if tp.Kind() == reflect.Ptr {
+               if tp.Kind() == reflect.Pointer {
                        tp = tp.Elem()
                }
 
index 022d2474fcf228020440505895cefcf2450976fb..04ea82bfd3f679563db1b95451abcf9c70014c1a 100644 (file)
@@ -205,7 +205,8 @@ D1
 
 // gobench --package ./tpl/partials
 func BenchmarkIncludeCached(b *testing.B) {
-       files := `
+       var files strings.Builder
+       files.WriteString(`
 -- hugo.toml --
 baseURL = 'http://example.com/'
 -- layouts/home.html --
@@ -228,15 +229,15 @@ ABCDE
 {{ end }}
 
 
-`
+`)
 
        for i := 1; i < 100; i++ {
-               files += fmt.Sprintf("\n-- content/p%d.md --\n---\ntitle: page\n---\n"+strings.Repeat("FOO ", i), i)
+               files.WriteString(fmt.Sprintf("\n-- content/p%d.md --\n---\ntitle: page\n---\n"+strings.Repeat("FOO ", i), i))
        }
 
        cfg := hugolib.IntegrationTestConfig{
                T:           b,
-               TxtarString: files,
+               TxtarString: files.String(),
        }
 
        for b.Loop() {
index 0a9f5c2621f5c370aa3fea9effca0964c3593f40..66811c74e86c074988f92890cb1e48087fa504c2 100644 (file)
@@ -126,9 +126,10 @@ func (ns *Namespace) Truncate(s any, options ...any) (template.HTML, error) {
                        } else {
                                endTextPos = lastWordIndex
                        }
-                       out := text[0:endTextPos]
+                       var out strings.Builder
+                       out.WriteString(text[0:endTextPos])
                        if isHTML {
-                               out += ellipsis
+                               out.WriteString(ellipsis)
                                // Close out any open HTML tags
                                var currentTag *htmlTag
                                for i := len(tags) - 1; i >= 0; i-- {
@@ -141,15 +142,15 @@ func (ns *Namespace) Truncate(s any, options ...any) (template.HTML, error) {
                                        }
 
                                        if tag.openTag {
-                                               out += ("</" + tag.name + ">")
+                                               out.WriteString(("</" + tag.name + ">"))
                                        } else {
                                                currentTag = &tag
                                        }
                                }
 
-                               return template.HTML(out), nil
+                               return template.HTML(out.String()), nil
                        }
-                       return template.HTML(html.EscapeString(out) + ellipsis), nil
+                       return template.HTML(html.EscapeString(out.String()) + ellipsis), nil
                }
        }
 
index 43a8bdfbe67ef64489b48177159e03ee61594fae..f6a72d22a7d3766ecdcdb1e201a65867994ec84f 100644 (file)
@@ -83,7 +83,7 @@ func (t *templateExecHelper) GetMapValue(ctx context.Context, tmpl texttemplate.
        return v, v.IsValid()
 }
 
-var typeParams = reflect.TypeOf(hmaps.Params{})
+var typeParams = reflect.TypeFor[hmaps.Params]()
 
 func (t *templateExecHelper) GetMethod(ctx context.Context, tmpl texttemplate.Preparer, receiver reflect.Value, name string) (method reflect.Value, firstArg reflect.Value) {
        if strings.EqualFold(name, "mainsections") && receiver.Type() == typeParams && receiver.Pointer() == t.siteParams.Pointer() {