Skip to content

Commit 7aa426f

Browse files
committed
Enable errorlint linter, and fix warnings
1 parent 0471dba commit 7aa426f

File tree

6 files changed

+17
-17
lines changed

6 files changed

+17
-17
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ run:
44
linters:
55
enable:
66
- copyloopvar
7+
- errorlint
78
- exhaustive
89
- intrange
910
- makezero

pkg/commands/git_config/get_key.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package git_config
22

33
import (
44
"bytes"
5+
"errors"
56
"fmt"
67
"io"
78
"os/exec"
@@ -39,7 +40,8 @@ func runGitConfigCmd(cmd *exec.Cmd) (string, error) {
3940
cmd.Stderr = io.Discard
4041

4142
err := cmd.Run()
42-
if exitError, ok := err.(*exec.ExitError); ok {
43+
var exitError *exec.ExitError
44+
if errors.As(err, &exitError) {
4345
if waitStatus, ok := exitError.Sys().(syscall.WaitStatus); ok {
4446
if waitStatus.ExitStatus() == 1 {
4547
return "", fmt.Errorf("the key is not found for %s", cmd.Args)

pkg/config/app_config.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ func computeMigratedConfig(path string, content []byte, changes *ChangesSet) ([]
288288
for _, pathToReplace := range pathsToReplace {
289289
err, didReplace := yaml_utils.RenameYamlKey(&rootNode, pathToReplace.oldPath, pathToReplace.newName)
290290
if err != nil {
291-
return nil, false, fmt.Errorf("Couldn't migrate config file at `%s` for key %s: %s", path, strings.Join(pathToReplace.oldPath, "."), err)
291+
return nil, false, fmt.Errorf("Couldn't migrate config file at `%s` for key %s: %w", path, strings.Join(pathToReplace.oldPath, "."), err)
292292
}
293293
if didReplace {
294294
changes.Add(fmt.Sprintf("Renamed '%s' to '%s'", strings.Join(pathToReplace.oldPath, "."), pathToReplace.newName))
@@ -297,27 +297,27 @@ func computeMigratedConfig(path string, content []byte, changes *ChangesSet) ([]
297297

298298
err = changeNullKeybindingsToDisabled(&rootNode, changes)
299299
if err != nil {
300-
return nil, false, fmt.Errorf("Couldn't migrate config file at `%s`: %s", path, err)
300+
return nil, false, fmt.Errorf("Couldn't migrate config file at `%s`: %w", path, err)
301301
}
302302

303303
err = changeElementToSequence(&rootNode, []string{"git", "commitPrefix"}, changes)
304304
if err != nil {
305-
return nil, false, fmt.Errorf("Couldn't migrate config file at `%s`: %s", path, err)
305+
return nil, false, fmt.Errorf("Couldn't migrate config file at `%s`: %w", path, err)
306306
}
307307

308308
err = changeCommitPrefixesMap(&rootNode, changes)
309309
if err != nil {
310-
return nil, false, fmt.Errorf("Couldn't migrate config file at `%s`: %s", path, err)
310+
return nil, false, fmt.Errorf("Couldn't migrate config file at `%s`: %w", path, err)
311311
}
312312

313313
err = changeCustomCommandStreamAndOutputToOutputEnum(&rootNode, changes)
314314
if err != nil {
315-
return nil, false, fmt.Errorf("Couldn't migrate config file at `%s`: %s", path, err)
315+
return nil, false, fmt.Errorf("Couldn't migrate config file at `%s`: %w", path, err)
316316
}
317317

318318
err = migrateAllBranchesLogCmd(&rootNode, changes)
319319
if err != nil {
320-
return nil, false, fmt.Errorf("Couldn't migrate config file at `%s`: %s", path, err)
320+
return nil, false, fmt.Errorf("Couldn't migrate config file at `%s`: %w", path, err)
321321
}
322322

323323
// Add more migrations here...

pkg/gui/controllers/commit_message_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func (self *CommitMessageController) handleCommitIndexChange(value int) error {
153153
func (self *CommitMessageController) setCommitMessageAtIndex(index int) (bool, error) {
154154
commitMessage, err := self.c.Git().Commit.GetCommitMessageFromHistory(index)
155155
if err != nil {
156-
if err == git_commands.ErrInvalidCommitIndex {
156+
if errors.Is(err, git_commands.ErrInvalidCommitIndex) {
157157
return false, nil
158158
}
159159
return false, errors.New(self.c.Tr.CommitWithoutMessageErr)

pkg/gui/gui.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package gui
22

33
import (
44
goContext "context"
5+
"errors"
56
"fmt"
67
"io"
78
"os"
@@ -872,8 +873,7 @@ func (gui *Gui) RunAndHandleError(startArgs appTypes.StartArgs) error {
872873

873874
close(gui.stopChan)
874875

875-
switch err {
876-
case gocui.ErrQuit:
876+
if errors.Is(err, gocui.ErrQuit) {
877877
if gui.c.State().GetRetainOriginalDir() {
878878
if err := gui.helpers.RecordDirectory.RecordDirectory(gui.InitialDir); err != nil {
879879
return err
@@ -885,10 +885,9 @@ func (gui *Gui) RunAndHandleError(startArgs appTypes.StartArgs) error {
885885
}
886886

887887
return nil
888-
889-
default:
890-
return err
891888
}
889+
890+
return err
892891
}
893892

894893
return nil

pkg/integration/clients/tui.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,10 @@ func RunTUI(raceDetector bool) {
214214

215215
err = g.MainLoop()
216216
g.Close()
217-
switch err {
218-
case gocui.ErrQuit:
217+
if errors.Is(err, gocui.ErrQuit) {
219218
return
220-
default:
221-
log.Panicln(err)
222219
}
220+
log.Panicln(err)
223221
}
224222

225223
type app struct {

0 commit comments

Comments
 (0)