lint: enable intrange linter (#7331)

Enable intrange linter to enforce modern Go range syntax over
traditional for loops, by converting:

for i := 0; i < n; i++

to:

for i := range n

Adding type conversions where needed for compatibility
with existing uint64 parameters.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
This commit is contained in:
Ville Vesilehto
2025-05-29 03:50:55 +03:00
committed by GitHub
parent b3acbe5046
commit 19a6ae4983
47 changed files with 82 additions and 81 deletions

View File

@@ -46,7 +46,7 @@ func TestCompressScrub(t *testing.T) {
// compression. This means we're looking for a combo where the pointers is detected and the offset is 12
// the position of the first name after the header. The erratic plugin adds 30 RRs that should all be compressed.
found := 0
for i := 0; i < len(buf)-1; i++ {
for i := range len(buf) - 1 {
if buf[i]&0xC0 == 0xC0 {
off := (int(buf[i])^0xC0)<<8 | int(buf[i+1])
if off == 12 {

View File

@@ -17,7 +17,7 @@ func TestLargeAXFR(t *testing.T) {
const numAAAAs = 6553
sb.WriteString("example.com. IN SOA . . 1 60 60 60 60\n")
sb.WriteString("example.com. IN NS ns.example.\n")
for i := 0; i < numAAAAs; i++ {
for i := range numAAAAs {
sb.WriteString(fmt.Sprintf("%d.example.com. IN AAAA 2001:db8::1\n", i))
}

View File

@@ -163,7 +163,7 @@ func TestMetricsRewriteRequestSize(t *testing.T) {
}
// Send multiple requests
for i := 0; i < numRequests; i++ {
for range numRequests {
if _, err = dns.Exchange(m, udp); err != nil {
t.Fatalf("Could not send message: %s", err)
}
@@ -195,7 +195,7 @@ func TestMetricsRewriteRequestSize(t *testing.T) {
defer srv2.Stop()
// Send the same requests with rewrite
for i := 0; i < numRequests; i++ {
for range numRequests {
if _, err = dns.Exchange(m, udp2); err != nil {
t.Fatalf("Could not send message: %s", err)
}

View File

@@ -65,7 +65,7 @@ func TestProxyThreeWay(t *testing.T) {
c := new(dns.Client)
c.Timeout = 10 * time.Millisecond
for i := 0; i < 10; i++ {
for range 10 {
r, _, err := c.Exchange(m, addr)
if err != nil {
continue

View File

@@ -71,7 +71,7 @@ func BenchmarkProxyLookup(b *testing.B) {
m.SetQuestion("example.org.", dns.TypeA)
b.ResetTimer()
for i := 0; i < b.N; i++ {
for range b.N {
if _, err := dns.Exchange(m, udp); err != nil {
b.Fatal("Expected to receive reply, but didn't")
}

View File

@@ -157,7 +157,7 @@ func TestQUICStreamLimits(t *testing.T) {
streamsMu := sync.Mutex{}
// Attempt to open exactly the configured number of streams
for i := 0; i < streamCount; i++ {
for i := range streamCount {
wg.Add(1)
go func(idx int) {
defer wg.Done()
@@ -237,7 +237,7 @@ func TestQUICStreamLimits(t *testing.T) {
done := make(chan struct{})
// Launch goroutines to attempt opening additional streams
for i := 0; i < extraCount; i++ {
for i := range extraCount {
extraWg.Add(1)
go func(idx int) {
defer extraWg.Done()

View File

@@ -181,7 +181,7 @@ func TestReloadSeveralTimeMetrics(t *testing.T) {
t.Errorf("Prometheus is not listening : %s", err)
}
reloadCount := 2
for i := 0; i < reloadCount; i++ {
for i := range reloadCount {
serverReload, err := serverWithMetrics.Restart(
NewInput(corefileWithMetrics),
)
@@ -305,7 +305,7 @@ func TestMetricsAvailableAfterReloadAndFailedReload(t *testing.T) {
t.Errorf("Could not scrap one of expected stats : %s", err)
}
for i := 0; i < 2; i++ {
for range 2 {
// now provide a failed reload
invInst, err := inst.Restart(
NewInput(invalidCorefileWithMetrics),

View File

@@ -72,7 +72,7 @@ func TestSecondaryZoneTransfer(t *testing.T) {
var r *dns.Msg
// This is now async; we need to wait for it to be transferred.
for i := 0; i < 10; i++ {
for range 10 {
r, _ = dns.Exchange(m, udp)
if len(r.Answer) != 0 {
break
@@ -114,7 +114,7 @@ func TestIxfrResponse(t *testing.T) {
c := new(dns.Client)
c.Net = "tcp"
// This is now async; we need to wait for it to be transferred.
for i := 0; i < 10; i++ {
for range 10 {
r, _, _ = c.Exchange(m, tcp)
if len(r.Answer) != 0 {
break

View File

@@ -127,7 +127,7 @@ func TestMultiZoneBlockConfigs(t *testing.T) {
server *caddy.Instance
err error
)
for j := 0; j < 3; j++ {
for j := range 3 {
corefile := `.:%d .:%d .:%d {
debug
}`
@@ -150,7 +150,7 @@ func TestMultiZoneBlockConfigs(t *testing.T) {
configs := reflect.ValueOf(ctxVal2.Interface()).Elem().FieldByName("configs")
configs2 := reflect.NewAt(configs.Type(), unsafe.Pointer(configs.UnsafeAddr())).Elem()
for i := 0; i < 3; i++ {
for i := range 3 {
v := configs2.Index(i)
config := v.Interface().(*dnsserver.Config)
if !config.Debug {