From 8cac83dfb5f0840bd3760a313d1d6cceca832b90 Mon Sep 17 00:00:00 2001 From: Ville Vesilehto Date: Mon, 2 Jun 2025 02:30:41 +0300 Subject: [PATCH] lint: enable wastedassign linter (#7340) --- .golangci.yml | 1 + plugin/cache/handler.go | 3 +-- plugin/dnstap/setup.go | 4 ++-- plugin/hosts/hostsfile.go | 2 +- plugin/kubernetes/kubernetes.go | 3 ++- plugin/pkg/dnsutil/reverse.go | 4 +--- plugin/pkg/proxy/connect.go | 2 +- 7 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index fcd4d4217..026ec473a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -13,6 +13,7 @@ linters: - unconvert - unused - usetesting + - wastedassign - whitespace exclusions: generated: lax diff --git a/plugin/cache/handler.go b/plugin/cache/handler.go index 394dc7b61..4de37ea8b 100644 --- a/plugin/cache/handler.go +++ b/plugin/cache/handler.go @@ -34,14 +34,13 @@ func (c *Cache) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) // in which upstream doesn't support DNSSEC, the two cache items will effectively be the same. Regardless, any // DNSSEC RRs in the response are written to cache with the response. - ttl := 0 i := c.getIgnoreTTL(now, state, server) if i == nil { crr := &ResponseWriter{ResponseWriter: w, Cache: c, state: state, server: server, do: do, ad: ad, cd: cd, nexcept: c.nexcept, pexcept: c.pexcept, wildcardFunc: wildcardFunc(ctx)} return c.doRefresh(ctx, state, crr) } - ttl = i.ttl(now) + ttl := i.ttl(now) if ttl < 0 { // serve stale behavior if c.verifyStale { diff --git a/plugin/dnstap/setup.go b/plugin/dnstap/setup.go index 5e6b31d3a..6e85a4a2c 100644 --- a/plugin/dnstap/setup.go +++ b/plugin/dnstap/setup.go @@ -25,7 +25,7 @@ func parseConfig(c *caddy.Controller) ([]*Dnstap, error) { MultipleTcpWriteBuf: 1, MultipleQueue: 1, } - endpoint := "" + d.repl = replacer.New() args := c.RemainingArgs() @@ -34,7 +34,7 @@ func parseConfig(c *caddy.Controller) ([]*Dnstap, error) { return nil, c.ArgErr() } - endpoint = args[0] + endpoint := args[0] if len(args) >= 3 { d.MultipleTcpWriteBuf, _ = strconv.Atoi(args[2]) diff --git a/plugin/hosts/hostsfile.go b/plugin/hosts/hostsfile.go index 04747ef8d..84e451029 100644 --- a/plugin/hosts/hostsfile.go +++ b/plugin/hosts/hostsfile.go @@ -171,7 +171,7 @@ func (h *Hostsfile) parse(r io.Reader) *Map { continue } - family := 0 + var family int if addr.To4() != nil { family = 1 } else { diff --git a/plugin/kubernetes/kubernetes.go b/plugin/kubernetes/kubernetes.go index 63a85e363..d1c007bda 100644 --- a/plugin/kubernetes/kubernetes.go +++ b/plugin/kubernetes/kubernetes.go @@ -379,7 +379,8 @@ func (k *Kubernetes) findPods(r recordRequest, zone string) (pods []msg.Service, } zonePath := msg.Path(zone, coredns) - ip := "" + + var ip string if strings.Count(podname, "-") == 3 && !strings.Contains(podname, "--") { ip = strings.ReplaceAll(podname, "-", ".") } else { diff --git a/plugin/pkg/dnsutil/reverse.go b/plugin/pkg/dnsutil/reverse.go index 91c3fba42..72ce40f64 100644 --- a/plugin/pkg/dnsutil/reverse.go +++ b/plugin/pkg/dnsutil/reverse.go @@ -11,10 +11,8 @@ import ( // 54.119.58.176.in-addr.arpa. becomes 176.58.119.54. If the conversion // fails the empty string is returned. func ExtractAddressFromReverse(reverseName string) string { - search := "" - f := reverse - + var search string switch { case strings.HasSuffix(reverseName, IP4arpa): search = strings.TrimSuffix(reverseName, IP4arpa) diff --git a/plugin/pkg/proxy/connect.go b/plugin/pkg/proxy/connect.go index a855120fa..a838ac247 100644 --- a/plugin/pkg/proxy/connect.go +++ b/plugin/pkg/proxy/connect.go @@ -107,7 +107,7 @@ func (t *Transport) Dial(proto string) (*persistConn, bool, error) { func (p *Proxy) Connect(ctx context.Context, state request.Request, opts Options) (*dns.Msg, error) { start := time.Now() - proto := "" + var proto string switch { case opts.ForceTCP: // TCP flag has precedence over UDP flag proto = "tcp"