diff --git a/.golangci.yml b/.golangci.yml index ecc8193e2..b2329171f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -4,6 +4,7 @@ run: linters: enable: - copyloopvar + - errorlint - exhaustive - intrange - makezero diff --git a/pkg/commands/git_config/get_key.go b/pkg/commands/git_config/get_key.go index cd5a678ef..7369fa08e 100644 --- a/pkg/commands/git_config/get_key.go +++ b/pkg/commands/git_config/get_key.go @@ -2,6 +2,7 @@ package git_config import ( "bytes" + "errors" "fmt" "io" "os/exec" @@ -39,7 +40,8 @@ func runGitConfigCmd(cmd *exec.Cmd) (string, error) { cmd.Stderr = io.Discard err := cmd.Run() - if exitError, ok := err.(*exec.ExitError); ok { + var exitError *exec.ExitError + if errors.As(err, &exitError) { if waitStatus, ok := exitError.Sys().(syscall.WaitStatus); ok { if waitStatus.ExitStatus() == 1 { return "", fmt.Errorf("the key is not found for %s", cmd.Args) diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 5d6b5e219..90c6c1013 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -288,7 +288,7 @@ func computeMigratedConfig(path string, content []byte, changes *ChangesSet) ([] for _, pathToReplace := range pathsToReplace { err, didReplace := yaml_utils.RenameYamlKey(&rootNode, pathToReplace.oldPath, pathToReplace.newName) if err != nil { - return nil, false, fmt.Errorf("Couldn't migrate config file at `%s` for key %s: %s", path, strings.Join(pathToReplace.oldPath, "."), err) + return nil, false, fmt.Errorf("Couldn't migrate config file at `%s` for key %s: %w", path, strings.Join(pathToReplace.oldPath, "."), err) } if didReplace { 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) ([] err = changeNullKeybindingsToDisabled(&rootNode, changes) if err != nil { - return nil, false, fmt.Errorf("Couldn't migrate config file at `%s`: %s", path, err) + return nil, false, fmt.Errorf("Couldn't migrate config file at `%s`: %w", path, err) } err = changeElementToSequence(&rootNode, []string{"git", "commitPrefix"}, changes) if err != nil { - return nil, false, fmt.Errorf("Couldn't migrate config file at `%s`: %s", path, err) + return nil, false, fmt.Errorf("Couldn't migrate config file at `%s`: %w", path, err) } err = changeCommitPrefixesMap(&rootNode, changes) if err != nil { - return nil, false, fmt.Errorf("Couldn't migrate config file at `%s`: %s", path, err) + return nil, false, fmt.Errorf("Couldn't migrate config file at `%s`: %w", path, err) } err = changeCustomCommandStreamAndOutputToOutputEnum(&rootNode, changes) if err != nil { - return nil, false, fmt.Errorf("Couldn't migrate config file at `%s`: %s", path, err) + return nil, false, fmt.Errorf("Couldn't migrate config file at `%s`: %w", path, err) } err = migrateAllBranchesLogCmd(&rootNode, changes) if err != nil { - return nil, false, fmt.Errorf("Couldn't migrate config file at `%s`: %s", path, err) + return nil, false, fmt.Errorf("Couldn't migrate config file at `%s`: %w", path, err) } // Add more migrations here... diff --git a/pkg/gui/controllers/commit_message_controller.go b/pkg/gui/controllers/commit_message_controller.go index b72d5d45a..6f96cdd21 100644 --- a/pkg/gui/controllers/commit_message_controller.go +++ b/pkg/gui/controllers/commit_message_controller.go @@ -153,7 +153,7 @@ func (self *CommitMessageController) handleCommitIndexChange(value int) error { func (self *CommitMessageController) setCommitMessageAtIndex(index int) (bool, error) { commitMessage, err := self.c.Git().Commit.GetCommitMessageFromHistory(index) if err != nil { - if err == git_commands.ErrInvalidCommitIndex { + if errors.Is(err, git_commands.ErrInvalidCommitIndex) { return false, nil } return false, errors.New(self.c.Tr.CommitWithoutMessageErr) diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 84ab86a62..2f65cde8c 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -2,6 +2,7 @@ package gui import ( goContext "context" + "errors" "fmt" "io" "os" @@ -872,8 +873,7 @@ func (gui *Gui) RunAndHandleError(startArgs appTypes.StartArgs) error { close(gui.stopChan) - switch err { - case gocui.ErrQuit: + if errors.Is(err, gocui.ErrQuit) { if gui.c.State().GetRetainOriginalDir() { if err := gui.helpers.RecordDirectory.RecordDirectory(gui.InitialDir); err != nil { return err @@ -885,10 +885,9 @@ func (gui *Gui) RunAndHandleError(startArgs appTypes.StartArgs) error { } return nil - - default: - return err } + + return err } return nil diff --git a/pkg/integration/clients/tui.go b/pkg/integration/clients/tui.go index f93644597..992f107e8 100644 --- a/pkg/integration/clients/tui.go +++ b/pkg/integration/clients/tui.go @@ -214,12 +214,10 @@ func RunTUI(raceDetector bool) { err = g.MainLoop() g.Close() - switch err { - case gocui.ErrQuit: + if errors.Is(err, gocui.ErrQuit) { return - default: - log.Panicln(err) } + log.Panicln(err) } type app struct {