From 781fabf4e406aae6b888d4f9f68331e7f13e89aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sun, 7 Jun 2026 17:02:03 +0200 Subject: [PATCH] all: Run go fix ./... --- codegen/methods.go | 4 +--- common/types/types.go | 5 ----- htesting/hqt/checkers.go | 4 ++-- hugolib/page_test.go | 11 ++++++----- internal/js/esbuild/options.go | 5 ++--- internal/warpc/avif.go | 2 +- modules/npm/package_builder.go | 22 +++++++--------------- related/related_integration_test.go | 9 +++++---- resources/postpub/fields.go | 7 +++---- tpl/internal/templatefuncsRegistry.go | 4 ++-- 10 files changed, 29 insertions(+), 44 deletions(-) diff --git a/codegen/methods.go b/codegen/methods.go index d705914bc..cfd425d0a 100644 --- a/codegen/methods.go +++ b/codegen/methods.go @@ -103,9 +103,7 @@ func (c *Inspector) MethodsFromTypes(include []reflect.Type, exclude []reflect.T } for _, t := range include { - for i := range t.NumMethod() { - - m := t.Method(i) + for m := range t.Methods() { if excludes[m.Name] || seen[m.Name] { continue } diff --git a/common/types/types.go b/common/types/types.go index 733a10946..55d61fdc7 100644 --- a/common/types/types.go +++ b/common/types/types.go @@ -134,11 +134,6 @@ func (l LowHigh[S]) Value(source S) S { // This is only used for debugging purposes. var InvocationCounter atomic.Int64 -// NewTrue returns a pointer to b. -func NewBool(b bool) *bool { - return &b -} - // WeightProvider provides a weight. type WeightProvider interface { Weight() int diff --git a/htesting/hqt/checkers.go b/htesting/hqt/checkers.go index a118967c1..7e9952d5a 100644 --- a/htesting/hqt/checkers.go +++ b/htesting/hqt/checkers.go @@ -200,8 +200,8 @@ func structTypes(v reflect.Value, m map[reflect.Type]struct{}) { } case reflect.Struct: m[v.Type()] = struct{}{} - for i := range v.NumField() { - structTypes(v.Field(i), m) + for _, field := range v.Fields() { + structTypes(field, m) } } } diff --git a/hugolib/page_test.go b/hugolib/page_test.go index aa4b6c159..f6225cac5 100644 --- a/hugolib/page_test.go +++ b/hugolib/page_test.go @@ -2034,16 +2034,17 @@ func BenchmarkIsTranslatedOneLanguage(b *testing.B) { // Set it reasonably high to get a balance between cached and uncached calls to IsTranslated. const numPages = 3000 - files := ` + var files strings.Builder + files.WriteString(` -- hugo.toml -- disableKinds = ["taxonomy", "term"] -` +`) for i := range numPages { - files += fmt.Sprintf(` --- content/sect/p%d.md --`, i) + files.WriteString(fmt.Sprintf(` +-- content/sect/p%d.md --`, i)) } - bb := Test(b, files, TestOptSkipRender()) + bb := Test(b, files.String(), TestOptSkipRender()) p := bb.H.Sites[0].RegularPages() b.ResetTimer() diff --git a/internal/js/esbuild/options.go b/internal/js/esbuild/options.go index 11d14c3db..88a5405a1 100644 --- a/internal/js/esbuild/options.go +++ b/internal/js/esbuild/options.go @@ -16,6 +16,7 @@ package esbuild import ( "encoding/json" "fmt" + "maps" "path/filepath" "sort" "strings" @@ -301,9 +302,7 @@ OUTER: loaders = make(map[string]api.Loader) // Add default CSS file loaders. // May be overridden by opts.Loaders. - for ext, loader := range extensionToLoaderMapCSS { - loaders[ext] = loader - } + maps.Copy(loaders, extensionToLoaderMapCSS) } if opts.Loaders != nil { if loaders == nil { diff --git a/internal/warpc/avif.go b/internal/warpc/avif.go index 773d1caea..baadaadd7 100644 --- a/internal/warpc/avif.go +++ b/internal/warpc/avif.go @@ -159,7 +159,7 @@ func (d *AvifCodec) Decode(r io.Reader) (image.Image, error) { return nil, fmt.Errorf("decoded AVIF frame count %d does not match frame durations %d", frameCount, len(out.Data.Params.FrameDurations)) } frames := make([]image.Image, frameCount) - for i := 0; i < len(frames); i++ { + for i := range frames { frameBytes := destination.Bytes()[i*frameSize : (i+1)*frameSize] if isHDR { // NRGBA64 for HDR - libavif returns non-premultiplied alpha. diff --git a/modules/npm/package_builder.go b/modules/npm/package_builder.go index 3294936bb..cea1dc8cd 100644 --- a/modules/npm/package_builder.go +++ b/modules/npm/package_builder.go @@ -22,6 +22,7 @@ import ( "os" "path/filepath" "runtime" + "slices" "strings" "github.com/gohugoio/hugo/common/hashing" @@ -255,23 +256,23 @@ func ensureWorkspaceRef(fsys afero.Fs, workspacePath string) error { wsVal, hasWS := pkg["workspaces"] switch v := wsVal.(type) { - case []interface{}: + case []any: // Array form: ["pkg-a", "pkg-b", ...] - if containsString(toStringSlice(v), workspacePath) { + if slices.Contains(toStringSlice(v), workspacePath) { if runtime.GOOS == "windows" { return afero.WriteFile(fsys, packageJSONName, data, 0o666) } return nil } // Fall through to byte-based insertion into the existing array below. - case map[string]interface{}: + case map[string]any: // Object form: { "workspaces": { "packages": [...] } } packagesVal, ok := v["packages"] if !ok { return fmt.Errorf("npm pack: unsupported workspaces object; missing \"packages\" field") } packagesSlice := toStringSlice(packagesVal) - if containsString(packagesSlice, workspacePath) { + if slices.Contains(packagesSlice, workspacePath) { if runtime.GOOS == "windows" { return afero.WriteFile(fsys, packageJSONName, data, 0o666) } @@ -279,7 +280,7 @@ func ensureWorkspaceRef(fsys afero.Fs, workspacePath string) error { } // Append the new workspace path to the packages slice. - newPkgs := make([]interface{}, 0, len(packagesSlice)+1) + newPkgs := make([]any, 0, len(packagesSlice)+1) for _, s := range packagesSlice { newPkgs = append(newPkgs, s) } @@ -349,7 +350,7 @@ func ensureWorkspaceRef(fsys afero.Fs, workspacePath string) error { } func detectIndent(data []byte) string { - for _, line := range bytes.Split(data, []byte("\n")) { + for line := range bytes.SplitSeq(data, []byte("\n")) { trimmed := bytes.TrimLeft(line, " \t") if len(trimmed) < len(line) && len(trimmed) > 0 && trimmed[0] == '"' { return string(line[:len(line)-len(trimmed)]) @@ -385,15 +386,6 @@ func toStringSlice(v any) []string { return nil } -func containsString(ss []string, s string) bool { - for _, v := range ss { - if v == s { - return true - } - } - return false -} - // resolveProjectWorkspaces resolves workspace patterns from the project's // package source, skipping the hugoautogen workspace. func resolveProjectWorkspaces(sourceFs afero.Fs, workspacesSource map[string]any, skipPath string) []string { diff --git a/related/related_integration_test.go b/related/related_integration_test.go index fe625eba5..e1387d3c5 100644 --- a/related/related_integration_test.go +++ b/related/related_integration_test.go @@ -156,17 +156,18 @@ Len related: {{ site.RegularPages.Related . | len }} `) createContent := func(n int) string { - base := `--- + var base strings.Builder + base.WriteString(`--- title: "Page %d" keywords: ['k%d'] --- -` +`) for range 32 { - base += fmt.Sprintf("\n## Title %d", rand.Intn(100)) + base.WriteString(fmt.Sprintf("\n## Title %d", rand.Intn(100))) } - return fmt.Sprintf(base, n, rand.Intn(32)) + return fmt.Sprintf(base.String(), n, rand.Intn(32)) } for i := 1; i < 100; i++ { diff --git a/resources/postpub/fields.go b/resources/postpub/fields.go index 12b3be2eb..e990b0417 100644 --- a/resources/postpub/fields.go +++ b/resources/postpub/fields.go @@ -31,8 +31,8 @@ func structToMap(s any) map[string]any { m := make(map[string]any) t := reflect.TypeOf(s) - for i := range t.NumMethod() { - method := t.Method(i) + for method := range t.Methods() { + if method.PkgPath != "" { continue } @@ -41,8 +41,7 @@ func structToMap(s any) map[string]any { } } - for i := range t.NumField() { - field := t.Field(i) + for field := range t.Fields() { if field.PkgPath != "" { continue } diff --git a/tpl/internal/templatefuncsRegistry.go b/tpl/internal/templatefuncsRegistry.go index 991433a56..9c6cc1371 100644 --- a/tpl/internal/templatefuncsRegistry.go +++ b/tpl/internal/templatefuncsRegistry.go @@ -214,8 +214,8 @@ func (t *TemplateFuncsNamespace) toJSON(ctx context.Context) ([]byte, error) { return nil, nil } ctxType := reflect.TypeOf(tctx) - for i := range ctxType.NumMethod() { - method := ctxType.Method(i) + for method := range ctxType.Methods() { + method := method if ignoreFuncs[method.Name] { continue }