aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorMoritz Poldrack <git@moritz.sh>2022-07-31 14:32:48 +0200
committerRobin Jarry <robin@jarry.cc>2022-08-04 21:58:01 +0200
commit978d35d356e8752bdd272884df48a6289d88b40a (patch)
tree3910243e688ef503159d07ce44b22cfea5d6c6fd /commands
parentc882cf9960be691fe55617b87cdfcfbabd5d5557 (diff)
downloadaerc-978d35d356e8752bdd272884df48a6289d88b40a.tar.gz
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 <moritz@poldrack.dev> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'commands')
-rw-r--r--commands/account/clear.go3
-rw-r--r--commands/account/import-mbox.go3
-rw-r--r--commands/account/recover.go10
-rw-r--r--commands/account/rmdir.go3
-rw-r--r--commands/compose/header.go3
-rw-r--r--commands/compose/send.go25
-rw-r--r--commands/ct.go7
-rw-r--r--commands/msg/copy.go3
-rw-r--r--commands/msg/mark.go14
-rw-r--r--commands/msg/move.go3
-rw-r--r--commands/msg/read.go7
-rw-r--r--commands/msg/recall.go3
-rw-r--r--commands/new-account.go3
-rw-r--r--commands/quit.go3
14 files changed, 42 insertions, 48 deletions
diff --git a/commands/account/clear.go b/commands/account/clear.go
index af7da324..6d1e7b0a 100644
--- a/commands/account/clear.go
+++ b/commands/account/clear.go
@@ -39,8 +39,7 @@ func (Clear) Execute(aerc *widgets.Aerc, args []string) error {
}
for _, opt := range opts {
- switch opt.Option {
- case 's':
+ if opt.Option == 's' {
clearSelected = true
}
}
diff --git a/commands/account/import-mbox.go b/commands/account/import-mbox.go
index 9f0e7004..5a8a2ee6 100644
--- a/commands/account/import-mbox.go
+++ b/commands/account/import-mbox.go
@@ -135,8 +135,7 @@ func (ImportMbox) Execute(aerc *widgets.Aerc, args []string) error {
func(option string, err error) {
aerc.CloseDialog()
aerc.Invalidate()
- switch option {
- case "Yes":
+ if option == "Yes" {
go importFolder()
}
},
diff --git a/commands/account/recover.go b/commands/account/recover.go
index 165e88e8..7a1100e4 100644
--- a/commands/account/recover.go
+++ b/commands/account/recover.go
@@ -36,9 +36,10 @@ func (Recover) Complete(aerc *widgets.Aerc, args []string) []string {
if len(args) == 0 {
return files
}
- if args[0] == "-" {
+ switch args[0] {
+ case "-":
return []string{"-f"}
- } else if args[0] == "-f" {
+ case "-f":
if len(args) == 1 {
for i, file := range files {
files[i] = args[0] + " " + file
@@ -49,7 +50,7 @@ func (Recover) Complete(aerc *widgets.Aerc, args []string) []string {
return commands.FilterList(files, args[1], args[0]+" ",
aerc.SelectedAccountUiConfig().FuzzyComplete)
}
- } else {
+ default:
// only accepts one file to recover
return commands.FilterList(files, args[0], "", aerc.SelectedAccountUiConfig().FuzzyComplete)
}
@@ -68,8 +69,7 @@ func (Recover) Execute(aerc *widgets.Aerc, args []string) error {
return err
}
for _, opt := range opts {
- switch opt.Option {
- case 'f':
+ if opt.Option == 'f' {
force = true
}
}
diff --git a/commands/account/rmdir.go b/commands/account/rmdir.go
index be493777..e45a7a7a 100644
--- a/commands/account/rmdir.go
+++ b/commands/account/rmdir.go
@@ -37,8 +37,7 @@ func (RemoveDir) Execute(aerc *widgets.Aerc, args []string) error {
return err
}
for _, opt := range opts {
- switch opt.Option {
- case 'f':
+ if opt.Option == 'f' {
force = true
}
}
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, ':')]
}
diff --git a/commands/ct.go b/commands/ct.go
index 092d9739..3bd3428e 100644
--- a/commands/ct.go
+++ b/commands/ct.go
@@ -40,15 +40,16 @@ func (ChangeTab) Execute(aerc *widgets.Aerc, args []string) error {
} else {
n, err := strconv.Atoi(joinedArgs)
if err == nil {
- if strings.HasPrefix(joinedArgs, "+") {
+ switch {
+ case strings.HasPrefix(joinedArgs, "+"):
for ; n > 0; n-- {
aerc.NextTab()
}
- } else if strings.HasPrefix(joinedArgs, "-") {
+ case strings.HasPrefix(joinedArgs, "-"):
for ; n < 0; n++ {
aerc.PrevTab()
}
- } else {
+ default:
ok := aerc.SelectTabIndex(n)
if !ok {
return errors.New(
diff --git a/commands/msg/copy.go b/commands/msg/copy.go
index 44257a74..6a106cf8 100644
--- a/commands/msg/copy.go
+++ b/commands/msg/copy.go
@@ -36,8 +36,7 @@ func (Copy) Execute(aerc *widgets.Aerc, args []string) error {
}
var createParents bool
for _, opt := range opts {
- switch opt.Option {
- case 'p':
+ if opt.Option == 'p' {
createParents = true
}
}
diff --git a/commands/msg/mark.go b/commands/msg/mark.go
index c446fc62..e15a9f6e 100644
--- a/commands/msg/mark.go
+++ b/commands/msg/mark.go
@@ -61,16 +61,17 @@ func (Mark) Execute(aerc *widgets.Aerc, args []string) error {
} else {
modFunc = store.Mark
}
- if all {
+ switch {
+ case all:
uids := store.Uids()
for _, uid := range uids {
modFunc(uid)
}
return nil
- } else if visual {
+ case visual:
store.ToggleVisualMark()
return nil
- } else {
+ default:
modFunc(selected.Uid)
return nil
}
@@ -80,16 +81,17 @@ func (Mark) Execute(aerc *widgets.Aerc, args []string) error {
return fmt.Errorf("visual mode not supported for this command")
}
- if all && toggle {
+ switch {
+ case all && toggle:
uids := store.Uids()
for _, uid := range uids {
store.ToggleMark(uid)
}
return nil
- } else if all && !toggle {
+ case all && !toggle:
store.ClearVisualMark()
return nil
- } else {
+ default:
store.Unmark(selected.Uid)
return nil
}
diff --git a/commands/msg/move.go b/commands/msg/move.go
index 2e3d4385..6eca6675 100644
--- a/commands/msg/move.go
+++ b/commands/msg/move.go
@@ -36,8 +36,7 @@ func (Move) Execute(aerc *widgets.Aerc, args []string) error {
}
var createParents bool
for _, opt := range opts {
- switch opt.Option {
- case 'p':
+ if opt.Option == 'p' {
createParents = true
}
}
diff --git a/commands/msg/read.go b/commands/msg/read.go
index 4c169b3b..e4d091f7 100644
--- a/commands/msg/read.go
+++ b/commands/msg/read.go
@@ -102,11 +102,12 @@ func (FlagMsg) Execute(aerc *widgets.Aerc, args []string) error {
flagChosen = true
}
}
- if toggle {
+ switch {
+ case toggle:
actionName = "Toggling"
- } else if enable {
+ case enable:
actionName = "Setting"
- } else {
+ default:
actionName = "Unsetting"
}
if optind != len(args) {
diff --git a/commands/msg/recall.go b/commands/msg/recall.go
index 8434b8d8..5fc3a265 100644
--- a/commands/msg/recall.go
+++ b/commands/msg/recall.go
@@ -42,8 +42,7 @@ func (Recall) Execute(aerc *widgets.Aerc, args []string) error {
return err
}
for _, opt := range opts {
- switch opt.Option {
- case 'f':
+ if opt.Option == 'f' {
force = true
}
}
diff --git a/commands/new-account.go b/commands/new-account.go
index 77ca3f80..2b28a1b1 100644
--- a/commands/new-account.go
+++ b/commands/new-account.go
@@ -28,8 +28,7 @@ func (NewAccount) Execute(aerc *widgets.Aerc, args []string) error {
}
wizard := widgets.NewAccountWizard(aerc.Config(), aerc)
for _, opt := range opts {
- switch opt.Option {
- case 't':
+ if opt.Option == 't' {
wizard.ConfigureTemporaryAccount(true)
}
}
diff --git a/commands/quit.go b/commands/quit.go
index ee5f46c1..09791a74 100644
--- a/commands/quit.go
+++ b/commands/quit.go
@@ -36,8 +36,7 @@ func (Quit) Execute(aerc *widgets.Aerc, args []string) error {
return err
}
for _, opt := range opts {
- switch opt.Option {
- case 'f':
+ if opt.Option == 'f' {
force = true
}
}