Skip to content

Commit eb18234

Browse files
committed
all: modernize -fix ./...
1 parent dd6dbb2 commit eb18234

File tree

15 files changed

+89
-93
lines changed

15 files changed

+89
-93
lines changed

cache/cache.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func Open(dir string) (*Cache, error) {
5555
if !info.IsDir() {
5656
return nil, &fs.PathError{Op: "open", Path: dir, Err: fmt.Errorf("not a directory")}
5757
}
58-
for i := 0; i < 256; i++ {
58+
for i := range 256 {
5959
name := filepath.Join(dir, fmt.Sprintf("%02x", i))
6060
if err := os.MkdirAll(name, 0777); err != nil {
6161
return nil, err
@@ -332,7 +332,7 @@ func (c *Cache) Trim() error {
332332
// We subtract an additional mtimeInterval
333333
// to account for the imprecision of our "last used" mtimes.
334334
cutoff := now.Add(-trimLimit - mtimeInterval)
335-
for i := 0; i < 256; i++ {
335+
for i := range 256 {
336336
subdir := filepath.Join(c.dir, fmt.Sprintf("%02x", i))
337337
c.trimSubdir(subdir, cutoff)
338338
}

cache/cache_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func TestGrowth(t *testing.T) {
8080
n = 10
8181
}
8282

83-
for i := 0; i < n; i++ {
83+
for i := range n {
8484
if err := c.putIndexEntry(dummyID(i), dummyID(i*99), int64(i)*101, true); err != nil {
8585
t.Fatalf("addIndexEntry: %v", err)
8686
}
@@ -93,7 +93,7 @@ func TestGrowth(t *testing.T) {
9393
t.Errorf("Get(%x) = %x, %d, want %x, %d", id, entry.OutputID, entry.Size, dummyID(i*99), int64(i)*101)
9494
}
9595
}
96-
for i := 0; i < n; i++ {
96+
for i := range n {
9797
id := ActionID(dummyID(i))
9898
entry, err := c.Get(id)
9999
if err != nil {

cmd/testscript/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,11 @@ type runT struct {
184184
failed atomic.Bool
185185
}
186186

187-
func (r *runT) Skip(is ...interface{}) {
187+
func (r *runT) Skip(is ...any) {
188188
panic(skipRun)
189189
}
190190

191-
func (r *runT) Fatal(is ...interface{}) {
191+
func (r *runT) Fatal(is ...any) {
192192
r.Log(is...)
193193
r.FailNow()
194194
}
@@ -197,7 +197,7 @@ func (r *runT) Parallel() {
197197
// TODO run tests in parallel.
198198
}
199199

200-
func (r *runT) Log(is ...interface{}) {
200+
func (r *runT) Log(is ...any) {
201201
msg := fmt.Sprint(is...)
202202
if r.stdinTempFile != "" {
203203
msg = strings.ReplaceAll(msg, r.stdinTempFile, "<stdin>")

cmd/txtar-addmod/addmod.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ It is acceptable to edit the archive afterward to remove or shorten files.
5555

5656
var tmpdir string
5757

58-
func fatalf(format string, args ...interface{}) {
58+
func fatalf(format string, args ...any) {
5959
os.RemoveAll(tmpdir)
6060
log.Fatalf(format, args...)
6161
}
@@ -150,7 +150,7 @@ func main() {
150150
filePrefix = ".gomodproxy/" + modDir + "/"
151151
} else {
152152
// No comment if we're writing to stdout.
153-
a.Comment = []byte(fmt.Sprintf("module %s\n\n", title))
153+
a.Comment = fmt.Appendf(nil, "module %s\n\n", title)
154154
}
155155
a.Files = []txtar.File{
156156
{Name: filePrefix + ".mod", Data: mod},

diff/diff.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,7 @@ func Diff(oldName string, old []byte, newName string, new []byte) []byte {
116116

117117
// End chunk with common lines for context.
118118
if len(ctext) > 0 {
119-
n := end.x - start.x
120-
if n > C {
121-
n = C
122-
}
119+
n := min(end.x-start.x, C)
123120
for _, s := range x[start.x : start.x+n] {
124121
ctext = append(ctext, " "+s)
125122
count.x++
@@ -234,7 +231,7 @@ func tgs(x, y []string) []pair {
234231
for i := range T {
235232
T[i] = n + 1
236233
}
237-
for i := 0; i < n; i++ {
234+
for i := range n {
238235
k := sort.Search(n, func(k int) bool {
239236
return T[k] >= J[i]
240237
})

fmtsort/sort.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,14 @@ func compare(aVal, bVal reflect.Value) int {
143143
return 0
144144
}
145145
case reflect.Struct:
146-
for i := 0; i < aVal.NumField(); i++ {
146+
for i := range aVal.NumField() {
147147
if c := compare(aVal.Field(i), bVal.Field(i)); c != 0 {
148148
return c
149149
}
150150
}
151151
return 0
152152
case reflect.Array:
153-
for i := 0; i < aVal.Len(); i++ {
153+
for i := range aVal.Len() {
154154
if c := compare(aVal.Index(i), bVal.Index(i)); c != 0 {
155155
return c
156156
}

fmtsort/sort_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ var compareTests = [][]reflect.Value{
3636
ct(reflect.TypeOf(chans[0]), chans[0], chans[1], chans[2]),
3737
ct(reflect.TypeOf(toy{}), toy{0, 1}, toy{0, 2}, toy{1, -1}, toy{1, 1}),
3838
ct(reflect.TypeOf([2]int{}), [2]int{1, 1}, [2]int{1, 2}, [2]int{2, 0}),
39-
ct(reflect.TypeOf(interface{}(interface{}(0))), iFace, 1, 2, 3),
39+
ct(reflect.TypeOf(any(any(0))), iFace, 1, 2, 3),
4040
}
4141

42-
var iFace interface{}
42+
var iFace any
4343

44-
func ct(typ reflect.Type, args ...interface{}) []reflect.Value {
44+
func ct(typ reflect.Type, args ...any) []reflect.Value {
4545
value := make([]reflect.Value, len(args))
4646
for i, v := range args {
4747
x := reflect.ValueOf(v)
@@ -82,9 +82,9 @@ func TestCompare(t *testing.T) {
8282
}
8383

8484
type sortTest struct {
85-
data interface{} // Always a map.
86-
print string // Printed result using our custom printer.
87-
printBrokenNaNs string // Printed result when NaN support is broken (pre Go1.12).
85+
data any // Always a map.
86+
print string // Printed result using our custom printer.
87+
printBrokenNaNs string // Printed result when NaN support is broken (pre Go1.12).
8888
}
8989

9090
var sortTests = []sortTest{
@@ -132,7 +132,7 @@ var sortTests = []sortTest{
132132
},
133133
}
134134

135-
func sprint(data interface{}) string {
135+
func sprint(data any) string {
136136
om := fmtsort.Sort(reflect.ValueOf(data))
137137
if om == nil {
138138
return "nil"
@@ -219,7 +219,7 @@ func TestInterface(t *testing.T) {
219219
// A map containing multiple concrete types should be sorted by type,
220220
// then value. However, the relative ordering of types is unspecified,
221221
// so test this by checking the presence of sorted subgroups.
222-
m := map[interface{}]string{
222+
m := map[any]string{
223223
[2]int{1, 0}: "",
224224
[2]int{0, 1}: "",
225225
true: "",

goproxytest/allhex.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package goproxytest
88

99
// allHex reports whether the revision rev is entirely lower-case hexadecimal digits.
1010
func allHex(rev string) bool {
11-
for i := 0; i < len(rev); i++ {
11+
for i := range len(rev) {
1212
c := rev[i]
1313
if '0' <= c && c <= '9' || 'a' <= c && c <= 'f' {
1414
continue

goproxytest/proxy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ func (srv *Server) handler(w http.ResponseWriter, r *http.Request) {
239239
zip []byte
240240
err error
241241
}
242-
c := srv.zipCache.Do(a, func() interface{} {
242+
c := srv.zipCache.Do(a, func() any {
243243
var buf bytes.Buffer
244244
z := zip.NewWriter(&buf)
245245
for _, f := range a.Files {
@@ -305,7 +305,7 @@ func (srv *Server) readArchive(path, vers string) *txtar.Archive {
305305
name := filepath.Join(srv.dir, prefix+"_"+encVers)
306306
txtName := name + ".txt"
307307
txtarName := name + ".txtar"
308-
a := srv.archiveCache.Do(name, func() interface{} {
308+
a := srv.archiveCache.Do(name, func() any {
309309
a, err := txtar.ParseFile(txtarName)
310310
if os.IsNotExist(err) {
311311
// fall back to trying with the .txt extension

imports/read.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func (r *importReader) nextByte(skipSpace bool) byte {
123123
// If the keyword is not present, readKeyword records a syntax error.
124124
func (r *importReader) readKeyword(kw string) {
125125
r.peekByte(true)
126-
for i := 0; i < len(kw); i++ {
126+
for i := range len(kw) {
127127
if r.nextByte(false) != kw[i] {
128128
r.syntaxError()
129129
return

0 commit comments

Comments
 (0)