lint(revive): fix early-return violations (#7974)

This commit is contained in:
Ville Vesilehto
2026-03-30 02:59:22 +03:00
committed by GitHub
parent ff954b12b2
commit 54b06d9a3b
5 changed files with 69 additions and 72 deletions

View File

@@ -60,7 +60,8 @@ linters:
- name: dot-imports - name: dot-imports
- name: early-return - name: early-return
disabled: true arguments:
- "preserveScope"
- name: empty-block - name: empty-block
disabled: true disabled: true

View File

@@ -69,15 +69,14 @@ func setup(c *caddy.Controller) error {
case "upstream": case "upstream":
c.RemainingArgs() c.RemainingArgs()
case "credentials": case "credentials":
if c.NextArg() { if !c.NextArg() {
return plugin.Error("clouddns", c.ArgErr())
}
credType, err := getCredType(c.Val()) credType, err := getCredType(c.Val())
if err != nil { if err != nil {
return plugin.Error("clouddns", c.Errf("invalid credentials file %q: %v", c.Val(), err)) return plugin.Error("clouddns", c.Errf("invalid credentials file %q: %v", c.Val(), err))
} }
opt = option.WithAuthCredentialsFile(credType, c.Val()) opt = option.WithAuthCredentialsFile(credType, c.Val())
} else {
return plugin.Error("clouddns", c.ArgErr())
}
case "fallthrough": case "fallthrough":
fall.SetZonesFromArgs(c.RemainingArgs()) fall.SetZonesFromArgs(c.RemainingArgs())
default: default:

View File

@@ -46,25 +46,25 @@ func parseConfig(c *caddy.Controller) ([]*Dnstap, error) {
if len(args) >= 3 { if len(args) >= 3 {
tcpWriteBuf := args[2] tcpWriteBuf := args[2]
if v, err := strconv.Atoi(tcpWriteBuf); err == nil { v, err := strconv.Atoi(tcpWriteBuf)
if err != nil {
return nil, c.Errf("dnstap: invalid MultipleTcpWriteBuf %q: %v", tcpWriteBuf, err)
}
if v < 1 || v > maxMultipleTcpWriteBuf { if v < 1 || v > maxMultipleTcpWriteBuf {
return nil, c.Errf("dnstap: MultipleTcpWriteBuf must be between 1 and %d (MiB units): %d", maxMultipleTcpWriteBuf, v) return nil, c.Errf("dnstap: MultipleTcpWriteBuf must be between 1 and %d (MiB units): %d", maxMultipleTcpWriteBuf, v)
} }
d.MultipleTcpWriteBuf = v d.MultipleTcpWriteBuf = v
} else {
return nil, c.Errf("dnstap: invalid MultipleTcpWriteBuf %q: %v", tcpWriteBuf, err)
}
} }
if len(args) >= 4 { if len(args) >= 4 {
qSize := args[3] qSize := args[3]
if v, err := strconv.Atoi(qSize); err == nil { v, err := strconv.Atoi(qSize)
if err != nil {
return nil, c.Errf("dnstap: invalid MultipleQueue %q: %v", qSize, err)
}
if v < 1 || v > maxMultipleQueue { if v < 1 || v > maxMultipleQueue {
return nil, c.Errf("dnstap: MultipleQueue must be between 1 and %d (x10k messages): %d", maxMultipleQueue, v) return nil, c.Errf("dnstap: MultipleQueue must be between 1 and %d (x10k messages): %d", maxMultipleQueue, v)
} }
d.MultipleQueue = v d.MultipleQueue = v
} else {
return nil, c.Errf("dnstap: invalid MultipleQueue %q: %v", qSize, err)
}
} }
var dio *dio var dio *dio

View File

@@ -666,26 +666,29 @@ func optsEqual(a, b []dns.EDNS0) bool {
for i := range a { for i := range a {
switch aa := a[i].(type) { switch aa := a[i].(type) {
case *dns.EDNS0_LOCAL: case *dns.EDNS0_LOCAL:
if bb, ok := b[i].(*dns.EDNS0_LOCAL); ok { bb, ok := b[i].(*dns.EDNS0_LOCAL)
if !ok {
return false
}
if aa.Code != bb.Code { if aa.Code != bb.Code {
return false return false
} }
if !bytes.Equal(aa.Data, bb.Data) { if !bytes.Equal(aa.Data, bb.Data) {
return false return false
} }
} else { case *dns.EDNS0_NSID:
bb, ok := b[i].(*dns.EDNS0_NSID)
if !ok {
return false return false
} }
case *dns.EDNS0_NSID:
if bb, ok := b[i].(*dns.EDNS0_NSID); ok {
if aa.Nsid != bb.Nsid { if aa.Nsid != bb.Nsid {
return false return false
} }
} else { case *dns.EDNS0_SUBNET:
bb, ok := b[i].(*dns.EDNS0_SUBNET)
if !ok {
return false return false
} }
case *dns.EDNS0_SUBNET:
if bb, ok := b[i].(*dns.EDNS0_SUBNET); ok {
if aa.Code != bb.Code { if aa.Code != bb.Code {
return false return false
} }
@@ -701,9 +704,6 @@ func optsEqual(a, b []dns.EDNS0) bool {
if !aa.Address.Equal(bb.Address) { if !aa.Address.Equal(bb.Address) {
return false return false
} }
} else {
return false
}
default: default:
return false return false

View File

@@ -96,21 +96,19 @@ func setup(c *caddy.Controller) error {
cfgOpts = append(cfgOpts, config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(v[0], v[1], ""))) cfgOpts = append(cfgOpts, config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(v[0], v[1], "")))
log.Warningf("Save aws_access_key in Corefile has been deprecated, please use other authentication methods instead") log.Warningf("Save aws_access_key in Corefile has been deprecated, please use other authentication methods instead")
case "aws_endpoint": case "aws_endpoint":
if c.NextArg() { if !c.NextArg() {
return plugin.Error("route53", c.ArgErr())
}
clientOpts = append(clientOpts, func(o *route53.Options) { clientOpts = append(clientOpts, func(o *route53.Options) {
o.BaseEndpoint = aws.String(c.Val()) o.BaseEndpoint = aws.String(c.Val())
}) })
} else {
return plugin.Error("route53", c.ArgErr())
}
case "upstream": case "upstream":
c.RemainingArgs() // eats args c.RemainingArgs() // eats args
case "credentials": case "credentials":
if c.NextArg() { if !c.NextArg() {
cfgOpts = append(cfgOpts, config.WithSharedConfigProfile(c.Val()))
} else {
return c.ArgErr() return c.ArgErr()
} }
cfgOpts = append(cfgOpts, config.WithSharedConfigProfile(c.Val()))
if c.NextArg() { if c.NextArg() {
sharedConfigFiles := []string{c.Val()} sharedConfigFiles := []string{c.Val()}
// If AWS_SDK_LOAD_CONFIG is set also load ~/.aws/config to stay consistent // If AWS_SDK_LOAD_CONFIG is set also load ~/.aws/config to stay consistent
@@ -123,7 +121,9 @@ func setup(c *caddy.Controller) error {
case "fallthrough": case "fallthrough":
fall.SetZonesFromArgs(c.RemainingArgs()) fall.SetZonesFromArgs(c.RemainingArgs())
case "refresh": case "refresh":
if c.NextArg() { if !c.NextArg() {
return plugin.Error("route53", c.ArgErr())
}
refreshStr := c.Val() refreshStr := c.Val()
_, err := strconv.Atoi(refreshStr) _, err := strconv.Atoi(refreshStr)
if err == nil { if err == nil {
@@ -136,9 +136,6 @@ func setup(c *caddy.Controller) error {
if refresh <= 0 { if refresh <= 0 {
return plugin.Error("route53", c.Errf("refresh interval must be greater than 0: %q", refreshStr)) return plugin.Error("route53", c.Errf("refresh interval must be greater than 0: %q", refreshStr))
} }
} else {
return plugin.Error("route53", c.ArgErr())
}
default: default:
return plugin.Error("route53", c.Errf("unknown property %q", c.Val())) return plugin.Error("route53", c.Errf("unknown property %q", c.Val()))
} }