aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMoritz Poldrack <git@moritz.sh>2022-07-29 21:42:02 +0200
committerRobin Jarry <robin@jarry.cc>2022-08-04 21:57:52 +0200
commitef599aa8fc9faf2747d3ec9fb02fb7b80af27cc6 (patch)
tree83b3757f85dc336a8f3bef89f03b96c6970c0119
parent03f9f4c3ab633f3b567813b55b90ba9aac604e3e (diff)
downloadaerc-ef599aa8fc9faf2747d3ec9fb02fb7b80af27cc6.tar.gz
lint: simplify code (gosimple)
Replaces infinite for loops containing a select on a channel with a single case with a range over the channel. Removes redundant assignments to blank identifiers. Remove unnecessary guard clause around delete(). Remove `if condition { return true } return false` with return condition Signed-off-by: Moritz Poldrack <moritz@poldrack.dev> Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r--commands/mode/noquit.go5
-rw-r--r--lib/msgstore.go4
-rw-r--r--widgets/account-wizard.go2
-rw-r--r--widgets/dirtree.go2
-rw-r--r--worker/imap/idler.go29
-rw-r--r--worker/mbox/worker.go25
6 files changed, 28 insertions, 39 deletions
diff --git a/commands/mode/noquit.go b/commands/mode/noquit.go
index ad664165..92f83ee8 100644
--- a/commands/mode/noquit.go
+++ b/commands/mode/noquit.go
@@ -19,8 +19,5 @@ func NoQuitDone() {
// QuitAllowed checks if aerc can exit normally (only when all goroutines that
// requested a no-quit mode were done and called the NoQuitDone() function)
func QuitAllowed() bool {
- if atomic.LoadInt32(&noquit) > 0 {
- return false
- }
- return true
+ return atomic.LoadInt32(&noquit) <= 0
}
diff --git a/lib/msgstore.go b/lib/msgstore.go
index bbaa70ad..ec15d420 100644
--- a/lib/msgstore.go
+++ b/lib/msgstore.go
@@ -452,9 +452,7 @@ func (store *MessageStore) Delete(uids []uint32,
func (store *MessageStore) revertDeleted(uids []uint32) {
for _, uid := range uids {
- if _, ok := store.Deleted[uid]; ok {
- delete(store.Deleted, uid)
- }
+ delete(store.Deleted, uid)
}
}
diff --git a/widgets/account-wizard.go b/widgets/account-wizard.go
index 57032884..9ddecfb0 100644
--- a/widgets/account-wizard.go
+++ b/widgets/account-wizard.go
@@ -194,7 +194,7 @@ func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard {
}
wizard.imapUri()
}
- hostport, srv = getSRV(server, []string{"submission"})
+ hostport, _ = getSRV(server, []string{"submission"})
if hostport != "" {
wizard.smtpServer.Set(hostport)
wizard.smtpMode = SMTP_STARTTLS
diff --git a/widgets/dirtree.go b/widgets/dirtree.go
index f135a0c3..b28d8072 100644
--- a/widgets/dirtree.go
+++ b/widgets/dirtree.go
@@ -385,7 +385,7 @@ func buildTree(node *types.Thread, stree [][]string, defaultUid uint32) {
}
sort.Strings(keys)
for _, key := range keys {
- next, _ := m[key]
+ next := m[key]
var uid uint32 = defaultUid
for _, testStr := range next {
if len(testStr) == 1 {
diff --git a/worker/imap/idler.go b/worker/imap/idler.go
index 055bab8b..69fdc4ca 100644
--- a/worker/imap/idler.go
+++ b/worker/imap/idler.go
@@ -134,23 +134,20 @@ func (i *idler) waitOnIdle() {
i.log("wait for idle in background")
go func() {
defer logging.PanicHandler()
- select {
- case err := <-i.done:
- if err == nil {
- i.log("<=(idle) waited")
- i.log("connect done->")
- i.worker.PostMessage(&types.Done{
- Message: types.RespondTo(&types.Connect{}),
- }, nil)
- } else {
- i.log("<=(idle) waited; with err: %v", err)
- }
- i.setWaiting(false)
- i.stop = make(chan struct{})
- i.log("restart")
- i.Start()
- return
+ err := <-i.done
+ if err == nil {
+ i.log("<=(idle) waited")
+ i.log("connect done->")
+ i.worker.PostMessage(&types.Done{
+ Message: types.RespondTo(&types.Connect{}),
+ }, nil)
+ } else {
+ i.log("<=(idle) waited; with err: %v", err)
}
+ i.setWaiting(false)
+ i.stop = make(chan struct{})
+ i.log("restart")
+ i.Start()
}()
}
diff --git a/worker/mbox/worker.go b/worker/mbox/worker.go
index ab16f91e..6114870e 100644
--- a/worker/mbox/worker.go
+++ b/worker/mbox/worker.go
@@ -363,20 +363,17 @@ func (w *mboxWorker) handleMessage(msg types.WorkerMessage) error {
}
func (w *mboxWorker) Run() {
- for {
- select {
- case msg := <-w.worker.Actions:
- msg = w.worker.ProcessAction(msg)
- if err := w.handleMessage(msg); err == errUnsupported {
- w.worker.PostMessage(&types.Unsupported{
- Message: types.RespondTo(msg),
- }, nil)
- } else if err != nil {
- w.worker.PostMessage(&types.Error{
- Message: types.RespondTo(msg),
- Error: err,
- }, nil)
- }
+ for msg := range w.worker.Actions {
+ msg = w.worker.ProcessAction(msg)
+ if err := w.handleMessage(msg); err == errUnsupported {
+ w.worker.PostMessage(&types.Unsupported{
+ Message: types.RespondTo(msg),
+ }, nil)
+ } else if err != nil {
+ w.worker.PostMessage(&types.Error{
+ Message: types.RespondTo(msg),
+ Error: err,
+ }, nil)
}
}
}