mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-13 01:30:53 +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:
@ -144,7 +144,7 @@ func (self *MenuViewModel) GetNonModelItems() []*NonModelItem {
|
||||
}
|
||||
|
||||
menuItems := self.FilteredListViewModel.GetItems()
|
||||
var prevSection *types.MenuSection = nil
|
||||
var prevSection *types.MenuSection
|
||||
for i, menuItem := range menuItems {
|
||||
if menuItem.Section != nil && menuItem.Section != prevSection {
|
||||
if prevSection != nil {
|
||||
|
@ -79,9 +79,8 @@ func (self *SuggestionsContext) RefreshSuggestions() {
|
||||
if findSuggestionsFn != nil {
|
||||
suggestions := findSuggestionsFn(self.c.GetPromptInput())
|
||||
return func() { self.SetSuggestions(suggestions) }
|
||||
} else {
|
||||
return func() {}
|
||||
}
|
||||
return func() {}
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -77,9 +77,8 @@ func (self *ListCursor) SetSelectionRangeAndMode(selectedIdx, rangeStartIdx int,
|
||||
func (self *ListCursor) GetSelectionRangeAndMode() (int, int, RangeSelectMode) {
|
||||
if self.IsSelectingRange() {
|
||||
return self.selectedIdx, self.rangeStartIdx, self.rangeSelectMode
|
||||
} else {
|
||||
return self.selectedIdx, self.selectedIdx, self.rangeSelectMode
|
||||
}
|
||||
return self.selectedIdx, self.selectedIdx, self.rangeSelectMode
|
||||
}
|
||||
|
||||
func (self *ListCursor) clampValue(value int) int {
|
||||
|
@ -24,7 +24,7 @@ func OnFocusWrapper(f func() error) func(opts types.OnFocusOpts) error {
|
||||
func (gui *Gui) defaultSideContext() types.Context {
|
||||
if gui.State.Modes.Filtering.Active() {
|
||||
return gui.State.Contexts.LocalCommits
|
||||
} else {
|
||||
return gui.State.Contexts.Files
|
||||
}
|
||||
|
||||
return gui.State.Contexts.Files
|
||||
}
|
||||
|
@ -54,9 +54,8 @@ func (self *BisectController) openMenu(commit *models.Commit) error {
|
||||
info := self.c.Git().Bisect.GetInfo()
|
||||
if info.Started() {
|
||||
return self.openMidBisectMenu(info, commit)
|
||||
} else {
|
||||
return self.openStartBisectMenu(info, commit)
|
||||
}
|
||||
return self.openStartBisectMenu(info, commit)
|
||||
}
|
||||
|
||||
func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, commit *models.Commit) error {
|
||||
@ -280,11 +279,11 @@ func (self *BisectController) afterBisectMarkRefresh(selectCurrent bool, waitToR
|
||||
|
||||
if waitToReselect {
|
||||
return self.c.Refresh(types.RefreshOptions{Mode: types.SYNC, Scope: []types.RefreshableView{}, Then: selectFn})
|
||||
} else {
|
||||
_ = selectFn()
|
||||
|
||||
return self.c.Helpers().Bisect.PostBisectCommandRefresh()
|
||||
}
|
||||
|
||||
_ = selectFn()
|
||||
|
||||
return self.c.Helpers().Bisect.PostBisectCommandRefresh()
|
||||
}
|
||||
|
||||
func (self *BisectController) selectCurrentBisectCommit() {
|
||||
|
@ -657,15 +657,15 @@ func (self *BranchesController) fastForward(branch *models.Branch) error {
|
||||
)
|
||||
_ = self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
|
||||
return err
|
||||
} else {
|
||||
self.c.LogAction(action)
|
||||
|
||||
err := self.c.Git().Sync.FastForward(
|
||||
task, branch.Name, branch.UpstreamRemote, branch.UpstreamBranch,
|
||||
)
|
||||
_ = self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.BRANCHES}})
|
||||
return err
|
||||
}
|
||||
|
||||
self.c.LogAction(action)
|
||||
|
||||
err := self.c.Git().Sync.FastForward(
|
||||
task, branch.Name, branch.UpstreamRemote, branch.UpstreamBranch,
|
||||
)
|
||||
_ = self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.BRANCHES}})
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -189,9 +189,9 @@ func (self *CustomPatchOptionsMenuAction) handleMovePatchIntoWorkingTree() error
|
||||
})
|
||||
|
||||
return nil
|
||||
} else {
|
||||
return pull(false)
|
||||
}
|
||||
|
||||
return pull(false)
|
||||
}
|
||||
|
||||
func (self *CustomPatchOptionsMenuAction) handlePullPatchIntoNewCommit() error {
|
||||
|
@ -901,11 +901,10 @@ func (self *FilesController) setStatusFiltering(filter filetree.FileTreeDisplayF
|
||||
// because the untracked files filter applies when running `git status`.
|
||||
if previousFilter != filter && (previousFilter == filetree.DisplayUntracked || filter == filetree.DisplayUntracked) {
|
||||
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES}, Mode: types.ASYNC})
|
||||
} else {
|
||||
self.c.PostRefreshUpdate(self.context())
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
self.c.PostRefreshUpdate(self.context())
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *FilesController) edit(nodes []*filetree.FileNode) error {
|
||||
|
@ -37,9 +37,9 @@ func (self *GpgHelper) WithGpgHandling(cmdObj *oscommands.CmdObj, configKey git_
|
||||
}
|
||||
|
||||
return err
|
||||
} else {
|
||||
return self.runAndStream(cmdObj, waitingStatus, onSuccess, refreshScope)
|
||||
}
|
||||
|
||||
return self.runAndStream(cmdObj, waitingStatus, onSuccess, refreshScope)
|
||||
}
|
||||
|
||||
func (self *GpgHelper) runAndStream(cmdObj *oscommands.CmdObj, waitingStatus string, onSuccess func() error, refreshScope []types.RefreshableView) error {
|
||||
|
@ -162,9 +162,8 @@ func (self *MergeAndRebaseHelper) CheckMergeOrRebaseWithRefreshOptions(result er
|
||||
} else if strings.Contains(result.Error(), "No rebase in progress?") {
|
||||
// assume in this case that we're already done
|
||||
return nil
|
||||
} else {
|
||||
return self.CheckForConflicts(result)
|
||||
}
|
||||
return self.CheckForConflicts(result)
|
||||
}
|
||||
|
||||
func (self *MergeAndRebaseHelper) CheckMergeOrRebase(result error) error {
|
||||
|
@ -56,9 +56,9 @@ func (self *RefsHelper) CheckoutRef(ref string, options types.CheckoutRefOptions
|
||||
withCheckoutStatus := func(f func(gocui.Task) error) error {
|
||||
if found {
|
||||
return self.c.WithInlineStatus(localBranch, types.ItemOperationCheckingOut, context.LOCAL_BRANCHES_CONTEXT_KEY, f)
|
||||
} else {
|
||||
return self.c.WithWaitingStatus(waitingStatus, f)
|
||||
}
|
||||
|
||||
return self.c.WithWaitingStatus(waitingStatus, f)
|
||||
}
|
||||
|
||||
return withCheckoutStatus(func(gocui.Task) error {
|
||||
|
@ -385,9 +385,8 @@ func splitMainPanelSideBySide(args WindowArrangementArgs) bool {
|
||||
default:
|
||||
if args.Width < 200 && args.Height > 30 { // 2 80 character width panels + 40 width for side panel
|
||||
return false
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@ -431,11 +430,11 @@ func sidePanelChildren(args WindowArrangementArgs) func(width int, height int) [
|
||||
Window: window,
|
||||
Weight: 1,
|
||||
}
|
||||
} else {
|
||||
return &boxlayout.Box{
|
||||
Window: window,
|
||||
Size: 0,
|
||||
}
|
||||
}
|
||||
|
||||
return &boxlayout.Box{
|
||||
Window: window,
|
||||
Size: 0,
|
||||
}
|
||||
}
|
||||
|
||||
@ -469,33 +468,33 @@ func sidePanelChildren(args WindowArrangementArgs) func(width int, height int) [
|
||||
accordionBox(&boxlayout.Box{Window: "commits", Weight: 1}),
|
||||
accordionBox(getDefaultStashWindowBox(args)),
|
||||
}
|
||||
} else {
|
||||
squashedHeight := 1
|
||||
if height >= 21 {
|
||||
squashedHeight = 3
|
||||
}
|
||||
}
|
||||
|
||||
squashedSidePanelBox := func(window string) *boxlayout.Box {
|
||||
if window == args.CurrentSideWindow {
|
||||
return &boxlayout.Box{
|
||||
Window: window,
|
||||
Weight: 1,
|
||||
}
|
||||
} else {
|
||||
return &boxlayout.Box{
|
||||
Window: window,
|
||||
Size: squashedHeight,
|
||||
}
|
||||
squashedHeight := 1
|
||||
if height >= 21 {
|
||||
squashedHeight = 3
|
||||
}
|
||||
|
||||
squashedSidePanelBox := func(window string) *boxlayout.Box {
|
||||
if window == args.CurrentSideWindow {
|
||||
return &boxlayout.Box{
|
||||
Window: window,
|
||||
Weight: 1,
|
||||
}
|
||||
}
|
||||
|
||||
return []*boxlayout.Box{
|
||||
squashedSidePanelBox("status"),
|
||||
squashedSidePanelBox("files"),
|
||||
squashedSidePanelBox("branches"),
|
||||
squashedSidePanelBox("commits"),
|
||||
squashedSidePanelBox("stash"),
|
||||
return &boxlayout.Box{
|
||||
Window: window,
|
||||
Size: squashedHeight,
|
||||
}
|
||||
}
|
||||
|
||||
return []*boxlayout.Box{
|
||||
squashedSidePanelBox("status"),
|
||||
squashedSidePanelBox("files"),
|
||||
squashedSidePanelBox("branches"),
|
||||
squashedSidePanelBox("commits"),
|
||||
squashedSidePanelBox("stash"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -245,7 +245,7 @@ func (self *WorkingTreeHelper) commitPrefixConfigsForRepo() []config.CommitPrefi
|
||||
cfg, ok := self.c.UserConfig().Git.CommitPrefixes[self.c.Git().RepoPaths.RepoName()]
|
||||
if ok {
|
||||
return append(cfg, self.c.UserConfig().Git.CommitPrefix...)
|
||||
} else {
|
||||
return self.c.UserConfig().Git.CommitPrefix
|
||||
}
|
||||
|
||||
return self.c.UserConfig().Git.CommitPrefix
|
||||
}
|
||||
|
@ -132,24 +132,24 @@ func (self *WorktreeHelper) NewWorktreeCheckout(base string, canCheckoutBase boo
|
||||
},
|
||||
})
|
||||
|
||||
return nil
|
||||
} else {
|
||||
// prompt for the new branch name where a blank means we just check out the branch
|
||||
self.c.Prompt(types.PromptOpts{
|
||||
Title: self.c.Tr.NewBranchName,
|
||||
HandleConfirm: func(branchName string) error {
|
||||
if branchName == "" {
|
||||
return errors.New(self.c.Tr.BranchNameCannotBeBlank)
|
||||
}
|
||||
|
||||
opts.Branch = branchName
|
||||
|
||||
return f()
|
||||
},
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// prompt for the new branch name where a blank means we just check out the branch
|
||||
self.c.Prompt(types.PromptOpts{
|
||||
Title: self.c.Tr.NewBranchName,
|
||||
HandleConfirm: func(branchName string) error {
|
||||
if branchName == "" {
|
||||
return errors.New(self.c.Tr.BranchNameCannotBeBlank)
|
||||
}
|
||||
|
||||
opts.Branch = branchName
|
||||
|
||||
return f()
|
||||
},
|
||||
})
|
||||
|
||||
return nil
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -92,27 +92,27 @@ func (self *SyncController) push(currentBranch *models.Branch) error {
|
||||
opts := pushOpts{remoteBranchStoredLocally: currentBranch.RemoteBranchStoredLocally()}
|
||||
if currentBranch.IsBehindForPush() {
|
||||
return self.requestToForcePush(currentBranch, opts)
|
||||
} else {
|
||||
return self.pushAux(currentBranch, opts)
|
||||
}
|
||||
} else {
|
||||
if self.c.Git().Config.GetPushToCurrent() {
|
||||
return self.pushAux(currentBranch, pushOpts{setUpstream: true})
|
||||
} else {
|
||||
return self.c.Helpers().Upstream.PromptForUpstreamWithInitialContent(currentBranch, func(upstream string) error {
|
||||
upstreamRemote, upstreamBranch, err := self.c.Helpers().Upstream.ParseUpstream(upstream)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return self.pushAux(currentBranch, pushOpts{
|
||||
setUpstream: true,
|
||||
upstreamRemote: upstreamRemote,
|
||||
upstreamBranch: upstreamBranch,
|
||||
})
|
||||
})
|
||||
}
|
||||
return self.pushAux(currentBranch, opts)
|
||||
}
|
||||
|
||||
if self.c.Git().Config.GetPushToCurrent() {
|
||||
return self.pushAux(currentBranch, pushOpts{setUpstream: true})
|
||||
}
|
||||
|
||||
return self.c.Helpers().Upstream.PromptForUpstreamWithInitialContent(currentBranch, func(upstream string) error {
|
||||
upstreamRemote, upstreamBranch, err := self.c.Helpers().Upstream.ParseUpstream(upstream)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return self.pushAux(currentBranch, pushOpts{
|
||||
setUpstream: true,
|
||||
upstreamRemote: upstreamRemote,
|
||||
upstreamBranch: upstreamBranch,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (self *SyncController) pull(currentBranch *models.Branch) error {
|
||||
|
@ -138,9 +138,8 @@ func (self *FileTreeViewModel) findNewSelectedIdx(prevNodes []*FileNode, currNod
|
||||
}
|
||||
if node.File != nil && node.File.IsRename() {
|
||||
return node.File.Names()
|
||||
} else {
|
||||
return []string{node.path}
|
||||
}
|
||||
return []string{node.path}
|
||||
}
|
||||
|
||||
for _, prevNode := range prevNodes {
|
||||
|
@ -611,9 +611,9 @@ func initialScreenMode(startArgs appTypes.StartArgs, config config.AppConfigurer
|
||||
return parseScreenModeArg(startArgs.ScreenMode)
|
||||
} else if startArgs.FilterPath != "" || startArgs.GitArg != appTypes.GitArgNone {
|
||||
return types.SCREEN_HALF
|
||||
} else {
|
||||
return parseScreenModeArg(config.GetUserConfig().Gui.ScreenMode)
|
||||
}
|
||||
|
||||
return parseScreenModeArg(config.GetUserConfig().Gui.ScreenMode)
|
||||
}
|
||||
|
||||
func parseScreenModeArg(screenModeArg string) types.ScreenMode {
|
||||
|
@ -17,9 +17,9 @@ func (gui *Gui) informationStr() string {
|
||||
donate := style.FgMagenta.Sprint(style.PrintHyperlink(gui.c.Tr.Donate, constants.Links.Donate))
|
||||
askQuestion := style.FgYellow.Sprint(style.PrintHyperlink(gui.c.Tr.AskQuestion, constants.Links.Discussions))
|
||||
return fmt.Sprintf("%s %s %s", donate, askQuestion, gui.Config.GetVersion())
|
||||
} else {
|
||||
return gui.Config.GetVersion()
|
||||
}
|
||||
|
||||
return gui.Config.GetVersion()
|
||||
}
|
||||
|
||||
func (gui *Gui) handleInfoClick() error {
|
||||
|
@ -41,9 +41,8 @@ func GetKey(key string) types.Key {
|
||||
binding, ok := config.KeyByLabel[strings.ToLower(key)]
|
||||
if !ok {
|
||||
log.Fatalf("Unrecognized key %s for keybinding. For permitted values see %s", strings.ToLower(key), constants.Links.Docs.CustomKeybindings)
|
||||
} else {
|
||||
return binding
|
||||
}
|
||||
return binding
|
||||
} else if runeCount == 1 {
|
||||
return []rune(key)[0]
|
||||
}
|
||||
|
@ -50,9 +50,8 @@ func (s Selection) bounds(c *mergeConflict) (int, int) {
|
||||
case TOP:
|
||||
if c.hasAncestor() {
|
||||
return c.start, c.ancestor
|
||||
} else {
|
||||
return c.start, c.target
|
||||
}
|
||||
return c.start, c.target
|
||||
case MIDDLE:
|
||||
return c.ancestor, c.target
|
||||
case BOTTOM:
|
||||
@ -72,7 +71,6 @@ func (s Selection) selected(c *mergeConflict, idx int) bool {
|
||||
func availableSelections(c *mergeConflict) []Selection {
|
||||
if c.hasAncestor() {
|
||||
return []Selection{TOP, MIDDLE, BOTTOM}
|
||||
} else {
|
||||
return []Selection{TOP, BOTTOM}
|
||||
}
|
||||
return []Selection{TOP, BOTTOM}
|
||||
}
|
||||
|
@ -25,9 +25,8 @@ func calculateNewOriginWithNeededAndWantedIdx(currentOrigin int, bufferHeight in
|
||||
requiredChange := wantToSeeIdx - bottom
|
||||
allowedChange := needToSeeIdx - origin
|
||||
return origin + min(requiredChange, allowedChange)
|
||||
} else {
|
||||
return origin
|
||||
}
|
||||
return origin
|
||||
}
|
||||
|
||||
func getNeedAndWantLineIdx(firstLineIdx int, lastLineIdx int, selectedLineIdx int, mode selectMode) (int, int) {
|
||||
@ -37,9 +36,8 @@ func getNeedAndWantLineIdx(firstLineIdx int, lastLineIdx int, selectedLineIdx in
|
||||
case RANGE:
|
||||
if selectedLineIdx == firstLineIdx {
|
||||
return firstLineIdx, lastLineIdx
|
||||
} else {
|
||||
return lastLineIdx, firstLineIdx
|
||||
}
|
||||
return lastLineIdx, firstLineIdx
|
||||
case HUNK:
|
||||
return firstLineIdx, lastLineIdx
|
||||
default:
|
||||
|
@ -267,9 +267,8 @@ func (s *State) SelectedViewRange() (int, int) {
|
||||
case RANGE:
|
||||
if s.rangeStartLineIdx > s.selectedLineIdx {
|
||||
return s.selectedLineIdx, s.rangeStartLineIdx
|
||||
} else {
|
||||
return s.rangeStartLineIdx, s.selectedLineIdx
|
||||
}
|
||||
return s.rangeStartLineIdx, s.selectedLineIdx
|
||||
case LINE:
|
||||
return s.selectedLineIdx, s.selectedLineIdx
|
||||
default:
|
||||
|
@ -145,9 +145,8 @@ func GetCommitListDisplayStrings(
|
||||
getGraphLine = func(idx int) string {
|
||||
if idx >= graphOffset {
|
||||
return graphLines[idx-graphOffset]
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -305,9 +304,8 @@ func getBisectStatus(index int, commitHash string, bisectInfo *git_commands.Bise
|
||||
} else {
|
||||
if bisectBounds != nil && index >= bisectBounds.newIndex && index <= bisectBounds.oldIndex {
|
||||
return BisectStatusCandidate
|
||||
} else {
|
||||
return BisectStatusNone
|
||||
}
|
||||
return BisectStatusNone
|
||||
}
|
||||
|
||||
// should never land here
|
||||
|
@ -63,9 +63,8 @@ func commitFilePatchStatus(node *filetree.Node[models.CommitFile], tree *filetre
|
||||
return patchBuilder.GetFileStatus(file.Path, tree.GetRef().RefName()) == patch.UNSELECTED
|
||||
}) {
|
||||
return patch.UNSELECTED
|
||||
} else {
|
||||
return patch.PART
|
||||
}
|
||||
return patch.PART
|
||||
}
|
||||
|
||||
func renderAux[T any](
|
||||
|
@ -177,7 +177,7 @@ func getBoxDrawingChars(up, down, left, right bool) (string, string) {
|
||||
return "╶", "─"
|
||||
} else if !up && !down && !left && !right {
|
||||
return " ", " "
|
||||
} else {
|
||||
panic("should not be possible")
|
||||
}
|
||||
|
||||
panic("should not be possible")
|
||||
}
|
||||
|
@ -246,9 +246,8 @@ func getNextPipes(prevPipes []Pipe, commit *models.Commit, getStyle func(c *mode
|
||||
for i := pipe.toPos; i > pos; i-- {
|
||||
if takenSpots.Includes(int(i)) || traversedSpots.Includes(int(i)) {
|
||||
break
|
||||
} else {
|
||||
last = i
|
||||
}
|
||||
last = i
|
||||
}
|
||||
newPipes = append(newPipes, Pipe{
|
||||
fromPos: pipe.toPos,
|
||||
|
Reference in New Issue
Block a user