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 --- aerc.go | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'aerc.go') diff --git a/aerc.go b/aerc.go index 9ce704b0..6e6c1d14 100644 --- a/aerc.go +++ b/aerc.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "errors" "fmt" "os" "sort" @@ -59,19 +60,20 @@ func execCommand(aerc *widgets.Aerc, ui *libui.UI, cmd []string) error { cmds := getCommands(aerc.SelectedTabContent()) for i, set := range cmds { err := set.ExecuteCommand(aerc, cmd) - if _, ok := err.(commands.NoSuchCommand); ok { - if i == len(cmds)-1 { - return err + if err != nil { + if errors.As(err, new(commands.NoSuchCommand)) { + if i == len(cmds)-1 { + return err + } + continue + } + if errors.As(err, new(commands.ErrorExit)) { + ui.Exit() + return nil } - continue - } else if _, ok := err.(commands.ErrorExit); ok { - ui.Exit() - return nil - } else if err != nil { return err - } else { - break } + break } return nil } @@ -123,8 +125,7 @@ func main() { return } for _, opt := range opts { - switch opt.Option { - case 'v': + if opt.Option == 'v' { fmt.Println("aerc " + Version) return } @@ -153,7 +154,7 @@ func main() { conf, err := config.LoadConfigFromFile(nil) if err != nil { fmt.Fprintf(os.Stderr, "Failed to load config: %v\n", err) - os.Exit(1) + os.Exit(1) //nolint:gocritic // PanicHandler does not need to run as it's not a panic } var ( -- cgit