1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-05 00:59:19 +02:00

Enable revive linter, and fix a bunch of warnings

I took the set of enabled checks from revive's recommended configuration [1],
and removed some that I didn't like. There might be other useful checks in
revive that we might want to enable, but this is a nice improvement already.

The bulk of the changes here are removing unnecessary else statements after
returns, but there are a few others too.

[1] https://github.com/mgechev/revive?tab=readme-ov-file#recommended-configuration
This commit is contained in:
Stefan Haller
2025-06-30 19:13:12 +02:00
parent 7aa426fa71
commit ca05a2ccea
47 changed files with 152 additions and 170 deletions

View File

@ -356,9 +356,8 @@ func parseDifference(track string, regexStr string) string {
match := re.FindStringSubmatch(track)
if len(match) > 1 {
return match[1]
} else {
return "0"
}
return "0"
}
// TODO: only look at the new reflog commits, and otherwise store the recencies in

View File

@ -149,9 +149,8 @@ func (self *CommitCommands) CommitEditorCmdObj() *oscommands.CmdObj {
func (self *CommitCommands) signoffFlag() string {
if self.UserConfig().Git.Commit.SignOff {
return "--signoff"
} else {
return ""
}
return ""
}
func (self *CommitCommands) GetCommitMessage(commitHash string) (string, error) {

View File

@ -97,7 +97,7 @@ func buildGitCommon(deps commonDeps) *GitCommon {
func buildRepo() *gogit.Repository {
// TODO: think of a way to actually mock this out
var repo *gogit.Repository = nil
var repo *gogit.Repository
return repo
}

View File

@ -32,9 +32,8 @@ func (self *GitCommandBuilder) ArgIf(condition bool, ifTrue ...string) *GitComma
func (self *GitCommandBuilder) ArgIfElse(condition bool, ifTrue string, ifFalse string) *GitCommandBuilder {
if condition {
return self.Arg(ifTrue)
} else {
return self.Arg(ifFalse)
}
return self.Arg(ifFalse)
}
func (self *GitCommandBuilder) Config(value string) *GitCommandBuilder {

View File

@ -327,9 +327,8 @@ func (self *RebaseCommands) MoveFixupCommitDown(commits []*models.Commit, target
func todoFromCommit(commit *models.Commit) utils.Todo {
if commit.Action == todo.UpdateRef {
return utils.Todo{Ref: commit.Name}
} else {
return utils.Todo{Hash: commit.Hash()}
}
return utils.Todo{Hash: commit.Hash()}
}
// Sets the action for the given commits in the git-rebase-todo file
@ -412,9 +411,9 @@ func (self *RebaseCommands) BeginInteractiveRebaseForCommit(
instruction: daemon.NewInsertBreakInstruction(),
keepCommitsThatBecomeEmpty: keepCommitsThatBecomeEmpty,
}).Run()
} else {
return self.BeginInteractiveRebaseForCommitRange(commits, commitIndex, commitIndex, keepCommitsThatBecomeEmpty)
}
return self.BeginInteractiveRebaseForCommitRange(commits, commitIndex, commitIndex, keepCommitsThatBecomeEmpty)
}
func (self *RebaseCommands) BeginInteractiveRebaseForCommitRange(
@ -574,7 +573,7 @@ func getBaseHashOrRoot(commits []*models.Commit, index int) string {
// at time of writing)
if index < len(commits) {
return commits[index].Hash()
} else {
return "--root"
}
return "--root"
}

View File

@ -21,7 +21,7 @@ type RepoPaths struct {
isBareRepo bool
}
var gitPathFormatVersion GitVersion = GitVersion{2, 31, 0, ""}
var gitPathFormatVersion = GitVersion{2, 31, 0, ""}
// Path to the current worktree. If we're in the main worktree, this will
// be the same as RepoPath()

View File

@ -184,9 +184,7 @@ func TestGetRepoPaths(t *testing.T) {
Expected: nil,
Err: func(getRevParseArgs argFn) error {
args := strings.Join(getRevParseArgs(), " ")
return errors.New(
fmt.Sprintf("'git %v --show-toplevel --absolute-git-dir --git-common-dir --is-bare-repository --show-superproject-working-tree' failed: fatal: invalid gitfile format: /path/to/repo/worktree2/.git", args),
)
return fmt.Errorf("'git %v --show-toplevel --absolute-git-dir --git-common-dir --is-bare-repository --show-superproject-working-tree' failed: fatal: invalid gitfile format: /path/to/repo/worktree2/.git", args)
},
},
}

View File

@ -49,9 +49,8 @@ func (self *SubmoduleCommands) GetConfigs(parentModule *models.SubmoduleConfig)
if len(matches) > 0 {
return matches[1], true
} else {
return "", false
}
return "", false
}
configs := []*models.SubmoduleConfig{}

View File

@ -66,9 +66,8 @@ func (self *WorkingTreeCommands) UnstageAll() error {
func (self *WorkingTreeCommands) UnStageFile(paths []string, tracked bool) error {
if tracked {
return self.UnstageTrackedFiles(paths)
} else {
return self.UnstageUntrackedFiles(paths)
}
return self.UnstageUntrackedFiles(paths)
}
func (self *WorkingTreeCommands) UnstageTrackedFiles(paths []string) error {

View File

@ -46,9 +46,8 @@ func (self *HostingServiceMgr) GetPullRequestURL(from string, to string) (string
if to == "" {
return gitService.getPullRequestURLIntoDefaultBranch(url.QueryEscape(from)), nil
} else {
return gitService.getPullRequestURLIntoTargetBranch(url.QueryEscape(from), url.QueryEscape(to)), nil
}
return gitService.getPullRequestURLIntoTargetBranch(url.QueryEscape(from), url.QueryEscape(to)), nil
}
func (self *HostingServiceMgr) GetCommitURL(commitHash string) (string, error) {

View File

@ -211,9 +211,8 @@ func (p *PatchBuilder) RenderPatchForFile(opts RenderPatchForFileOpts) string {
if opts.Plain {
return patch.FormatPlain()
} else {
return patch.FormatView(FormatViewOpts{})
}
return patch.FormatView(FormatViewOpts{})
}
func (p *PatchBuilder) renderEachFilePatch(plain bool) []string {

View File

@ -84,9 +84,9 @@ func (self *patchTransformer) transformHeader() []string {
result = append(result, line)
}
return result
} else {
return self.patch.header
}
return self.patch.header
}
func (self *patchTransformer) transformHunks() []*Hunk {