From 978d35d356e8752bdd272884df48a6289d88b40a Mon Sep 17 00:00:00 2001 From: Moritz Poldrack Date: Sun, 31 Jul 2022 14:32:48 +0200 Subject: lint: homogenize operations and minor fixes (gocritic) Apply GoDoc comment policy (comments for humans should have a space after the //; machine-readable comments shouldn't) Use strings.ReplaceAll instead of strings.Replace when appropriate Remove if/else chains by replacing them with switches Use short assignment/increment notation Replace single case switches with if statements Combine else and if when appropriate Signed-off-by: Moritz Poldrack Acked-by: Robin Jarry --- commands/compose/header.go | 3 +-- commands/compose/send.go | 25 ++++++++++++------------- 2 files changed, 13 insertions(+), 15 deletions(-) (limited to 'commands/compose') diff --git a/commands/compose/header.go b/commands/compose/header.go index dcee9aac..46cc23b9 100644 --- a/commands/compose/header.go +++ b/commands/compose/header.go @@ -50,8 +50,7 @@ func (Header) Execute(aerc *widgets.Aerc, args []string) error { var force bool = false for _, opt := range opts { - switch opt.Option { - case 'f': + if opt.Option == 'f' { force = true } } diff --git a/commands/compose/send.go b/commands/compose/send.go index 2bd61119..ec9e06b3 100644 --- a/commands/compose/send.go +++ b/commands/compose/send.go @@ -250,12 +250,13 @@ func parseScheme(uri *url.URL) (scheme string, auth string, err error) { auth = "plain" if uri.Scheme != "" { parts := strings.Split(uri.Scheme, "+") - if len(parts) == 1 { + switch len(parts) { + case 1: scheme = parts[0] - } else if len(parts) == 2 { + case 2: scheme = parts[0] auth = parts[1] - } else { + default: return "", "", fmt.Errorf("Unknown transfer protocol %s", uri.Scheme) } } @@ -380,7 +381,7 @@ func newSmtpSender(ctx sendCtx) (io.WriteCloser, error) { func connectSmtp(starttls bool, host string) (*smtp.Client, error) { serverName := host if !strings.ContainsRune(host, ':') { - host = host + ":587" // Default to submission port + host += ":587" // Default to submission port } else { serverName = host[:strings.IndexRune(host, ':')] } @@ -402,14 +403,12 @@ func connectSmtp(starttls bool, host string) (*smtp.Client, error) { conn.Close() return nil, errors.Wrap(err, "StartTLS") } - } else { - if starttls { - err := errors.New("STARTTLS requested, but not supported " + - "by this SMTP server. Is someone tampering with your " + - "connection?") - conn.Close() - return nil, err - } + } else if starttls { + err := errors.New("STARTTLS requested, but not supported " + + "by this SMTP server. Is someone tampering with your " + + "connection?") + conn.Close() + return nil, err } return conn, nil } @@ -417,7 +416,7 @@ func connectSmtp(starttls bool, host string) (*smtp.Client, error) { func connectSmtps(host string) (*smtp.Client, error) { serverName := host if !strings.ContainsRune(host, ':') { - host = host + ":465" // Default to smtps port + host += ":465" // Default to smtps port } else { serverName = host[:strings.IndexRune(host, ':')] } -- cgit