From f7e0e9fe65d54b8e88001af0e5ebfa37cb78b621 Mon Sep 17 00:00:00 2001 From: Alberto Bertogli Date: Fri, 24 Oct 2025 12:00:18 +0100 Subject: [PATCH] Minor cleanups for staticcheck issues staticcheck found a couple of minor code cleanup improvements, like unused variables or an out-of-order defer, mostly in tests. This patch fixes those problems by making the necessary adjustments. They're all fairly small, and should not change the logic in any significant way. --- internal/dkim/dns_test.go | 4 ---- internal/localrpc/e2e_test.go | 6 +++--- internal/smtpsrv/conn.go | 3 ++- internal/smtpsrv/server.go | 1 - test/util/smtpc/smtpc.go | 2 +- 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/internal/dkim/dns_test.go b/internal/dkim/dns_test.go index 5d25ce7..2f7784d 100644 --- a/internal/dkim/dns_test.go +++ b/internal/dkim/dns_test.go @@ -3,8 +3,6 @@ package dkim import ( "context" "crypto" - "crypto/ed25519" - "crypto/x509" "encoding/base64" "errors" "testing" @@ -36,7 +34,6 @@ const exampleRSAKeyB64 = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQ" + "tdY9tf6mcwGjaNBcWToIMmPSPDdQPNUYckcQ2QIDAQAB" var exampleRSAKeyBuf, _ = base64.StdEncoding.DecodeString(exampleRSAKeyB64) -var exampleRSAKey, _ = x509.ParsePKCS1PublicKey(exampleRSAKeyBuf) // Ed25519 key from the RFC example. // https://datatracker.ietf.org/doc/html/rfc8463#appendix-A.2 @@ -44,7 +41,6 @@ const exampleEd25519KeyB64 = "11qYAYKxCrfVS/7TyWQHOg7hcvPapiMlrwIaaPcHURo=" var exampleEd25519KeyBuf, _ = base64.StdEncoding.DecodeString( exampleEd25519KeyB64) -var exampleEd25519Key = ed25519.PublicKey(exampleEd25519KeyBuf) var results = map[string][]string{} var resultErr = map[string]error{} diff --git a/internal/localrpc/e2e_test.go b/internal/localrpc/e2e_test.go index 1366a62..7f72d90 100644 --- a/internal/localrpc/e2e_test.go +++ b/internal/localrpc/e2e_test.go @@ -22,10 +22,10 @@ func Hola(tr *trace.Trace, input url.Values) (url.Values, error) { return output, nil } -var testErr = errors.New("test error") +var errTest = errors.New("test error") func HolaErr(tr *trace.Trace, input url.Values) (url.Values, error) { - return nil, testErr + return nil, errTest } type testServer struct { @@ -86,7 +86,7 @@ func TestEndToEnd(t *testing.T) { {"Echo", nil, mkV(), nil}, {"Echo", mkV("msg", "hola"), mkV("msg", "hola"), nil}, {"Hola", mkV("name", "marola"), mkV("greeting", "Hola marola"), nil}, - {"HolaErr", nil, nil, testErr}, + {"HolaErr", nil, nil, errTest}, {"UnknownMethod", nil, nil, errUnknownMethod}, } diff --git a/internal/smtpsrv/conn.go b/internal/smtpsrv/conn.go index 8a67e42..b0a8208 100644 --- a/internal/smtpsrv/conn.go +++ b/internal/smtpsrv/conn.go @@ -5,6 +5,7 @@ import ( "bytes" "context" "crypto/tls" + "errors" "flag" "fmt" "io" @@ -944,7 +945,7 @@ func (c *Conn) runPostDataHook(data []byte) ([]byte, bool, error) { // The error contains the last line of stdout, so filters can pass // some rejection information back to the sender. - err = fmt.Errorf(lastLine(string(out))) + err = errors.New(lastLine(string(out))) return nil, permanent, err } diff --git a/internal/smtpsrv/server.go b/internal/smtpsrv/server.go index ea27185..9f503af 100644 --- a/internal/smtpsrv/server.go +++ b/internal/smtpsrv/server.go @@ -282,7 +282,6 @@ func (s *Server) periodicallyReload() { return } - //lint:ignore SA1015 This lasts the program's lifetime. for range time.Tick(*reloadEvery) { s.Reload() } diff --git a/test/util/smtpc/smtpc.go b/test/util/smtpc/smtpc.go index 9b85312..0d95972 100644 --- a/test/util/smtpc/smtpc.go +++ b/test/util/smtpc/smtpc.go @@ -56,11 +56,11 @@ func main() { } conn, err = tls.Dial("tcp", *addr, tlsConfig) - defer conn.Close() } else { conn, err = net.Dial("tcp", *addr) } notnil(err) + defer conn.Close() // Send the message. client, err := smtp.NewClient(conn, *addr)