mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-03 00:57:52 +02:00
Enable errorlint linter, and fix warnings
This commit is contained in:
@ -4,6 +4,7 @@ run:
|
|||||||
linters:
|
linters:
|
||||||
enable:
|
enable:
|
||||||
- copyloopvar
|
- copyloopvar
|
||||||
|
- errorlint
|
||||||
- exhaustive
|
- exhaustive
|
||||||
- intrange
|
- intrange
|
||||||
- makezero
|
- makezero
|
||||||
|
@ -2,6 +2,7 @@ package git_config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -39,7 +40,8 @@ func runGitConfigCmd(cmd *exec.Cmd) (string, error) {
|
|||||||
cmd.Stderr = io.Discard
|
cmd.Stderr = io.Discard
|
||||||
|
|
||||||
err := cmd.Run()
|
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, ok := exitError.Sys().(syscall.WaitStatus); ok {
|
||||||
if waitStatus.ExitStatus() == 1 {
|
if waitStatus.ExitStatus() == 1 {
|
||||||
return "", fmt.Errorf("the key is not found for %s", cmd.Args)
|
return "", fmt.Errorf("the key is not found for %s", cmd.Args)
|
||||||
|
@ -288,7 +288,7 @@ func computeMigratedConfig(path string, content []byte, changes *ChangesSet) ([]
|
|||||||
for _, pathToReplace := range pathsToReplace {
|
for _, pathToReplace := range pathsToReplace {
|
||||||
err, didReplace := yaml_utils.RenameYamlKey(&rootNode, pathToReplace.oldPath, pathToReplace.newName)
|
err, didReplace := yaml_utils.RenameYamlKey(&rootNode, pathToReplace.oldPath, pathToReplace.newName)
|
||||||
if err != nil {
|
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 {
|
if didReplace {
|
||||||
changes.Add(fmt.Sprintf("Renamed '%s' to '%s'", strings.Join(pathToReplace.oldPath, "."), pathToReplace.newName))
|
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)
|
err = changeNullKeybindingsToDisabled(&rootNode, changes)
|
||||||
if err != nil {
|
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)
|
err = changeElementToSequence(&rootNode, []string{"git", "commitPrefix"}, changes)
|
||||||
if err != nil {
|
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)
|
err = changeCommitPrefixesMap(&rootNode, changes)
|
||||||
if err != nil {
|
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)
|
err = changeCustomCommandStreamAndOutputToOutputEnum(&rootNode, changes)
|
||||||
if err != nil {
|
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)
|
err = migrateAllBranchesLogCmd(&rootNode, changes)
|
||||||
if err != nil {
|
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...
|
// Add more migrations here...
|
||||||
|
@ -153,7 +153,7 @@ func (self *CommitMessageController) handleCommitIndexChange(value int) error {
|
|||||||
func (self *CommitMessageController) setCommitMessageAtIndex(index int) (bool, error) {
|
func (self *CommitMessageController) setCommitMessageAtIndex(index int) (bool, error) {
|
||||||
commitMessage, err := self.c.Git().Commit.GetCommitMessageFromHistory(index)
|
commitMessage, err := self.c.Git().Commit.GetCommitMessageFromHistory(index)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == git_commands.ErrInvalidCommitIndex {
|
if errors.Is(err, git_commands.ErrInvalidCommitIndex) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
return false, errors.New(self.c.Tr.CommitWithoutMessageErr)
|
return false, errors.New(self.c.Tr.CommitWithoutMessageErr)
|
||||||
|
@ -2,6 +2,7 @@ package gui
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
goContext "context"
|
goContext "context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
@ -872,8 +873,7 @@ func (gui *Gui) RunAndHandleError(startArgs appTypes.StartArgs) error {
|
|||||||
|
|
||||||
close(gui.stopChan)
|
close(gui.stopChan)
|
||||||
|
|
||||||
switch err {
|
if errors.Is(err, gocui.ErrQuit) {
|
||||||
case gocui.ErrQuit:
|
|
||||||
if gui.c.State().GetRetainOriginalDir() {
|
if gui.c.State().GetRetainOriginalDir() {
|
||||||
if err := gui.helpers.RecordDirectory.RecordDirectory(gui.InitialDir); err != nil {
|
if err := gui.helpers.RecordDirectory.RecordDirectory(gui.InitialDir); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -885,10 +885,9 @@ func (gui *Gui) RunAndHandleError(startArgs appTypes.StartArgs) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
default:
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -214,12 +214,10 @@ func RunTUI(raceDetector bool) {
|
|||||||
|
|
||||||
err = g.MainLoop()
|
err = g.MainLoop()
|
||||||
g.Close()
|
g.Close()
|
||||||
switch err {
|
if errors.Is(err, gocui.ErrQuit) {
|
||||||
case gocui.ErrQuit:
|
|
||||||
return
|
return
|
||||||
default:
|
|
||||||
log.Panicln(err)
|
|
||||||
}
|
}
|
||||||
|
log.Panicln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
type app struct {
|
type app struct {
|
||||||
|
Reference in New Issue
Block a user