all: Run modernize -fix ./...

Closes #14107
This commit is contained in:
Bjørn Erik Pedersen
2025-11-05 20:41:17 +01:00
parent 264022a75a
commit 04650ce778
122 changed files with 275 additions and 351 deletions
+8 -11
View File
@@ -38,7 +38,6 @@ func TestXxHashFromReaderPara(t *testing.T) {
var wg sync.WaitGroup
for i := range 10 {
i := i
wg.Add(1)
go func() {
defer wg.Done()
@@ -75,8 +74,8 @@ func TestXxHashFromStringHexEncoded(t *testing.T) {
func BenchmarkXXHashFromReader(b *testing.B) {
r := strings.NewReader("Hello World")
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
XXHashFromReader(r)
r.Seek(0, 0)
}
@@ -84,16 +83,16 @@ func BenchmarkXXHashFromReader(b *testing.B) {
func BenchmarkXXHashFromString(b *testing.B) {
s := "Hello World"
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
XXHashFromString(s)
}
}
func BenchmarkXXHashFromStringHexEncoded(b *testing.B) {
s := "The quick brown fox jumps over the lazy dog"
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
XxHashFromStringHexEncoded(s)
}
}
@@ -136,7 +135,7 @@ func BenchmarkHashString(b *testing.B) {
for _, test := range tests {
b.Run(fmt.Sprintf("n%d", len(test)), func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
HashString(test)
}
})
@@ -149,9 +148,7 @@ func BenchmarkHashMap(b *testing.B) {
m[fmt.Sprintf("key%d", i)] = i
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
HashString(m)
}
}
+1 -1
View File
@@ -278,7 +278,7 @@ func TestConvertIfPossibleMisc(t *testing.T) {
func BenchmarkToInt64(b *testing.B) {
v := reflect.ValueOf(int(42))
for i := 0; i < b.N; i++ {
for b.Loop() {
ToInt64(v)
}
}
+6 -9
View File
@@ -156,12 +156,12 @@ func BenchmarkIsContextType(b *testing.B) {
b.Run("value", func(b *testing.B) {
ctx := context.Background()
ctxs := make([]reflect.Type, b.N)
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
ctxs[i] = reflect.TypeOf(context.WithValue(ctx, k("key"), i))
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
if !IsContextType(ctxs[i]) {
b.Fatal("not context")
}
@@ -170,7 +170,7 @@ func BenchmarkIsContextType(b *testing.B) {
b.Run("background", func(b *testing.B) {
var ctxt reflect.Type = reflect.TypeOf(context.Background())
for i := 0; i < b.N; i++ {
for b.Loop() {
if !IsContextType(ctxt) {
b.Fatal("not context")
}
@@ -189,8 +189,7 @@ func BenchmarkIsTruthFulValue(b *testing.B) {
nilPointer = reflect.ValueOf((*zeroStruct)(nil))
)
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
IsTruthfulValue(stringHugo)
IsTruthfulValue(stringEmpty)
IsTruthfulValue(zero)
@@ -227,8 +226,7 @@ func BenchmarkGetMethodByNameForType(b *testing.B) {
tp := reflect.TypeFor[*testStruct]()
methods := []string{"Method1", "Method2", "Method3", "Method4", "Method5"}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
for _, method := range methods {
_ = GetMethodByNameForType(tp, method)
}
@@ -239,8 +237,7 @@ func BenchmarkGetMethodByName(b *testing.B) {
v := reflect.ValueOf(&testStruct{})
methods := []string{"Method1", "Method2", "Method3", "Method4", "Method5"}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
for _, method := range methods {
_ = GetMethodByName(v, method)
}
+2 -2
View File
@@ -214,8 +214,8 @@ func TestScratchGetSortedMapValues(t *testing.T) {
func BenchmarkScratchGet(b *testing.B) {
scratch := NewScratch()
scratch.Add("A", 1)
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
scratch.Get("A")
}
}
+7 -7
View File
@@ -75,7 +75,7 @@ func BenchmarkUniqueStrings(b *testing.B) {
input := []string{"a", "b", "d", "e", "d", "h", "a", "i"}
b.Run("Safe", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
result := UniqueStrings(input)
if len(result) != 6 {
b.Fatalf("invalid count: %d", len(result))
@@ -86,13 +86,13 @@ func BenchmarkUniqueStrings(b *testing.B) {
b.Run("Reuse slice", func(b *testing.B) {
b.StopTimer()
inputs := make([][]string, b.N)
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
inputc := make([]string, len(input))
copy(inputc, input)
inputs[i] = inputc
}
b.StartTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
inputc := inputs[i]
result := UniqueStringsReuse(inputc)
@@ -105,13 +105,13 @@ func BenchmarkUniqueStrings(b *testing.B) {
b.Run("Reuse slice sorted", func(b *testing.B) {
b.StopTimer()
inputs := make([][]string, b.N)
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
inputc := make([]string, len(input))
copy(inputc, input)
inputs[i] = inputc
}
b.StartTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
inputc := inputs[i]
result := UniqueStringsSorted(inputc)
@@ -123,13 +123,13 @@ func BenchmarkUniqueStrings(b *testing.B) {
}
func BenchmarkGetOrCompileRegexp(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
GetOrCompileRegexp(`\d+`)
}
}
func BenchmarkCompileRegexp(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
regexp.MustCompile(`\d+`)
}
}
+1 -1
View File
@@ -67,7 +67,7 @@ func BenchmarkOnceMoreValue(b *testing.B) {
return counter
}
for range b.N {
for b.Loop() {
omf := OnceMoreValue(f)
for range 10 {
omf.Value(context.Background())
+3 -3
View File
@@ -112,7 +112,7 @@ func BenchmarkTimeFormatter(b *testing.B) {
june06, _ := time.Parse("2006-Jan-02", "2018-Jun-06")
b.Run("Native", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
got := june06.Format("Monday Jan 2 2006")
if got != "Wednesday Jun 6 2018" {
b.Fatalf("invalid format, got %q", got)
@@ -123,7 +123,7 @@ func BenchmarkTimeFormatter(b *testing.B) {
b.Run("Localized", func(b *testing.B) {
f := NewTimeFormatter(translators.GetTranslator("nn"))
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
got := f.Format(june06, "Monday Jan 2 2006")
if got != "onsdag juni 6 2018" {
b.Fatalf("invalid format, got %q", got)
@@ -134,7 +134,7 @@ func BenchmarkTimeFormatter(b *testing.B) {
b.Run("Localized Custom", func(b *testing.B) {
f := NewTimeFormatter(translators.GetTranslator("nn"))
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
got := f.Format(june06, ":date_medium")
if got != "6. juni 2018" {
b.Fatalf("invalid format, got %q", got)
+1 -1
View File
@@ -24,7 +24,7 @@ func TestCacheSize(t *testing.T) {
cache := NewCacheWithOptions[string, string](CacheOptions{Size: 10})
for i := 0; i < 30; i++ {
for i := range 30 {
cache.Set(string(rune('a'+i)), "value")
}
+7 -7
View File
@@ -68,31 +68,31 @@ func BenchmarkOrderedIntSet(b *testing.B) {
}
b.Run("New", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
NewOrderedIntSet(1, 2, 3, 4, 5, 6, 7, 8)
}
})
b.Run("Has small", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
smallSet.Has(i % 32)
}
})
b.Run("Has medium", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
mediumSet.Has(i % 32)
}
})
b.Run("Next", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
mediumSet.Next(i % 32)
}
})
b.Run("ForEachKey small", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
smallSet.ForEachKey(func(key int) bool {
return true
})
@@ -100,7 +100,7 @@ func BenchmarkOrderedIntSet(b *testing.B) {
})
b.Run("ForEachKey medium", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
mediumSet.ForEachKey(func(key int) bool {
return true
})
@@ -108,7 +108,7 @@ func BenchmarkOrderedIntSet(b *testing.B) {
})
b.Run("ForEachKey large", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
largeSet.ForEachKey(func(key int) bool {
return true
})
-1
View File
@@ -52,7 +52,6 @@ func TestPara(t *testing.T) {
var result []int
var mu sync.Mutex
for i := range n {
i := i
r.Run(func() error {
mu.Lock()
defer mu.Unlock()
+2 -2
View File
@@ -115,8 +115,8 @@ func ReplaceExtension(path string, newExt string) string {
func makePathRelative(inPath string, possibleDirectories ...string) (string, error) {
for _, currentPath := range possibleDirectories {
if strings.HasPrefix(inPath, currentPath) {
return strings.TrimPrefix(inPath, currentPath), nil
if after, ok := strings.CutPrefix(inPath, currentPath); ok {
return after, nil
}
}
return inPath, errors.New("can't extract relative path, unknown prefix")
+5 -5
View File
@@ -225,7 +225,7 @@ func BenchmarkSanitize(b *testing.B) {
// This should not allocate any memory.
b.Run("All allowed", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
got := Sanitize(allAlowedPath)
if got != allAlowedPath {
b.Fatal(got)
@@ -235,7 +235,7 @@ func BenchmarkSanitize(b *testing.B) {
// This will allocate some memory.
b.Run("Spaces", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
got := Sanitize(spacePath)
if got != "foo-bar" {
b.Fatal(got)
@@ -320,7 +320,7 @@ func BenchmarkAddLeadingSlash(b *testing.B) {
// This should not allocate any memory.
b.Run("With leading slash", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
got := AddLeadingSlash(withLeadingSlash)
if got != withLeadingSlash {
b.Fatal(got)
@@ -330,7 +330,7 @@ func BenchmarkAddLeadingSlash(b *testing.B) {
// This will allocate some memory.
b.Run("Without leading slash", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
got := AddLeadingSlash(noLeadingSlash)
if got != "/a/b/c" {
b.Fatal(got)
@@ -339,7 +339,7 @@ func BenchmarkAddLeadingSlash(b *testing.B) {
})
b.Run("Blank string", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
got := AddLeadingSlash("")
if got != "/" {
b.Fatal(got)
+2 -2
View File
@@ -637,7 +637,7 @@ func TestHasExt(t *testing.T) {
func BenchmarkParseIdentity(b *testing.B) {
parser := newTestParser()
for i := 0; i < b.N; i++ {
for b.Loop() {
parser.ParseIdentity(files.ComponentFolderAssets, "/a/b.css")
}
}
@@ -656,7 +656,7 @@ func TestSitesMatrixFromPath(t *testing.T) {
func BenchmarkSitesMatrixFromPath(b *testing.B) {
parser := newTestParser()
p := parser.Parse(files.ComponentFolderContent, "/a/b/c.fr.md")
for i := 0; i < b.N; i++ {
for b.Loop() {
parser.SitesMatrixFromPath(p)
}
}
+4 -4
View File
@@ -150,7 +150,7 @@ func BenchmarkPredicate(b *testing.B) {
b.Run("and or no match", func(b *testing.B) {
var p predicate.PR[int] = intP1
p = p.And(intP2).Or(intP3)
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = p(3).OK()
}
})
@@ -158,7 +158,7 @@ func BenchmarkPredicate(b *testing.B) {
b.Run("and and no match", func(b *testing.B) {
var p predicate.PR[int] = intP1
p = p.And(intP2)
for range b.N {
for b.Loop() {
_ = p(3).OK()
}
})
@@ -166,7 +166,7 @@ func BenchmarkPredicate(b *testing.B) {
b.Run("and and match", func(b *testing.B) {
var p predicate.PR[int] = intP1
p = p.And(intP2)
for range b.N {
for b.Loop() {
_ = p(10).OK()
}
})
@@ -174,7 +174,7 @@ func BenchmarkPredicate(b *testing.B) {
b.Run("or or match", func(b *testing.B) {
var p predicate.PR[int] = intP1
p = p.Or(intP2).Or(intP3)
for range b.N {
for b.Loop() {
_ = p(2).OK()
}
})
+1 -1
View File
@@ -65,7 +65,7 @@ func BenchmarkVisitLinesAfter(b *testing.B) {
line 3`
for i := 0; i < b.N; i++ {
for b.Loop() {
VisitLinesAfter(lines, func(s string) {
})
}