Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion codegen/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions codegen/methods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 2 additions & 4 deletions common/hashing/hashing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -50,7 +48,7 @@ func TestXxHashFromReaderPara(t *testing.T) {
expect, _ := XXHashFromString(s)
c.Assert(got, qt.Equals, expect)
}
}()
})
}

wg.Wait()
Expand Down
6 changes: 3 additions & 3 deletions common/herrors/file_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion common/hreflect/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions common/hreflect/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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()
}

Expand Down Expand Up @@ -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]()

Expand Down
6 changes: 2 additions & 4 deletions common/types/evictingqueue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -68,7 +66,7 @@ func TestEvictingStringQueueConcurrent(t *testing.T) {
if len(vals) != 1 || vals[0] != val {
t.Error("wrong val")
}
}()
})
}
wg.Wait()
}
2 changes: 1 addition & 1 deletion common/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
2 changes: 1 addition & 1 deletion config/security/securityConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions helpers/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions helpers/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}

Expand All @@ -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))
}
}
Expand Down
2 changes: 1 addition & 1 deletion htesting/hqt/checkers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
12 changes: 7 additions & 5 deletions hugolib/cascade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package hugolib

import (
"fmt"
"strings"
"testing"

"github.com/gohugoio/hugo/hugolib/sitesmatrix"
Expand All @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion hugolib/doctree/simpletree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion hugolib/hugo_sites_build_errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ foo bar
}

for _, test := range tests {
test := test
if test.name != "Base template parse failed" {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions hugolib/hugo_sites_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
}
Expand Down
13 changes: 7 additions & 6 deletions hugolib/hugo_smoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -828,7 +829,7 @@ weight = 4
{{ .Content }}
-- layouts/_shortcodes/myshort.html --
{{ .Inner }}
`
`)

contentTemplate := `
---
Expand All @@ -855,23 +856,23 @@ 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)
if leafBundles {
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()
}
1 change: 0 additions & 1 deletion hugolib/language_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 --
Expand Down
Loading