From d712c2f1993fbb281519234213bc81dca90f35b9 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 23 Aug 2024 20:14:32 +0200 Subject: [PATCH 1/7] Use format arguments instead of concatenating strings That's what they are for. --- pkg/commands/git_config/cached_git_config.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/commands/git_config/cached_git_config.go b/pkg/commands/git_config/cached_git_config.go index da18d0866..539691e13 100644 --- a/pkg/commands/git_config/cached_git_config.go +++ b/pkg/commands/git_config/cached_git_config.go @@ -69,7 +69,7 @@ func (self *CachedGitConfig) getGeneralAux(args string) string { cmd := getGitConfigGeneralCmd(args) value, err := self.runGitConfigCmd(cmd) if err != nil { - self.log.Debugf("Error getting git config value for args: " + args + ". Error: " + err.Error()) + self.log.Debugf("Error getting git config value for args: %s. Error: %v", args, err.Error()) return "" } return strings.TrimSpace(value) @@ -79,7 +79,7 @@ func (self *CachedGitConfig) getAux(key string) string { cmd := getGitConfigCmd(key) value, err := self.runGitConfigCmd(cmd) if err != nil { - self.log.Debugf("Error getting git config value for key: " + key + ". Error: " + err.Error()) + self.log.Debugf("Error getting git config value for key: %s. Error: %v", key, err.Error()) return "" } return strings.TrimSpace(value) From 24841f22f16a7c73ac98a3ca82bd27e9a5ad4a92 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 23 Aug 2024 20:11:28 +0200 Subject: [PATCH 2/7] Use print instead of printf when there are no arguments --- pkg/commands/git_config/cached_git_config.go | 4 ++-- pkg/gui/controllers/branches_controller.go | 2 +- pkg/integration/clients/cli.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/commands/git_config/cached_git_config.go b/pkg/commands/git_config/cached_git_config.go index 539691e13..9c12b45ee 100644 --- a/pkg/commands/git_config/cached_git_config.go +++ b/pkg/commands/git_config/cached_git_config.go @@ -42,7 +42,7 @@ func (self *CachedGitConfig) Get(key string) string { defer self.mutex.Unlock() if value, ok := self.cache[key]; ok { - self.log.Debugf("using cache for key " + key) + self.log.Debug("using cache for key " + key) return value } @@ -56,7 +56,7 @@ func (self *CachedGitConfig) GetGeneral(args string) string { defer self.mutex.Unlock() if value, ok := self.cache[args]; ok { - self.log.Debugf("using cache for args " + args) + self.log.Debug("using cache for args " + args) return value } diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go index f0d0899a5..d22e56f1c 100644 --- a/pkg/gui/controllers/branches_controller.go +++ b/pkg/gui/controllers/branches_controller.go @@ -810,7 +810,7 @@ func (self *BranchesController) createPullRequestMenu(selectedBranch *models.Bra menuItems = append(menuItems, menuItemsForBranch(selectedBranch)...) - return self.c.Menu(types.CreateMenuOptions{Title: fmt.Sprintf(self.c.Tr.CreatePullRequestOptions), Items: menuItems}) + return self.c.Menu(types.CreateMenuOptions{Title: fmt.Sprint(self.c.Tr.CreatePullRequestOptions), Items: menuItems}) } func (self *BranchesController) createPullRequest(from string, to string) error { diff --git a/pkg/integration/clients/cli.go b/pkg/integration/clients/cli.go index 10958c164..34a5f85bd 100644 --- a/pkg/integration/clients/cli.go +++ b/pkg/integration/clients/cli.go @@ -49,7 +49,7 @@ func RunCLI(testNames []string, slow bool, sandbox bool, waitForDebugger bool, r func runAndPrintFatalError(test *components.IntegrationTest, f func() error) { if err := f(); err != nil { - log.Fatalf(err.Error()) + log.Fatal(err.Error()) } } From 63aa32c52199bfd8b1e9082b398f042d79896bc7 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 23 Aug 2024 20:15:56 +0200 Subject: [PATCH 3/7] Remove "double" formatting --- pkg/gui/controllers/helpers/refresh_helper.go | 5 ++--- pkg/gui/services/custom_commands/handler_creator.go | 8 +++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/pkg/gui/controllers/helpers/refresh_helper.go b/pkg/gui/controllers/helpers/refresh_helper.go index 579bc9d3e..7af45d142 100644 --- a/pkg/gui/controllers/helpers/refresh_helper.go +++ b/pkg/gui/controllers/helpers/refresh_helper.go @@ -1,7 +1,6 @@ package helpers import ( - "fmt" "strings" "sync" "time" @@ -60,7 +59,7 @@ func (self *RefreshHelper) Refresh(options types.RefreshOptions) error { t := time.Now() defer func() { - self.c.Log.Infof(fmt.Sprintf("Refresh took %s", time.Since(t))) + self.c.Log.Infof("Refresh took %s", time.Since(t)) }() if options.Scope == nil { @@ -114,7 +113,7 @@ func (self *RefreshHelper) Refresh(options types.RefreshOptions) error { t := time.Now() defer wg.Done() f() - self.c.Log.Infof(fmt.Sprintf("refreshed %s in %s", name, time.Since(t))) + self.c.Log.Infof("refreshed %s in %s", name, time.Since(t)) }) } } diff --git a/pkg/gui/services/custom_commands/handler_creator.go b/pkg/gui/services/custom_commands/handler_creator.go index c1cfe09cb..2c9e090f9 100644 --- a/pkg/gui/services/custom_commands/handler_creator.go +++ b/pkg/gui/services/custom_commands/handler_creator.go @@ -131,11 +131,9 @@ func (self *HandlerCreator) inputPrompt(prompt *config.CustomCommandPrompt, wrap func (self *HandlerCreator) generateFindSuggestionsFunc(prompt *config.CustomCommandPrompt) (func(string) []*types.Suggestion, error) { if prompt.Suggestions.Preset != "" && prompt.Suggestions.Command != "" { return nil, fmt.Errorf( - fmt.Sprintf( - "Custom command prompt cannot have both a preset and a command for suggestions. Preset: '%s', Command: '%s'", - prompt.Suggestions.Preset, - prompt.Suggestions.Command, - ), + "Custom command prompt cannot have both a preset and a command for suggestions. Preset: '%s', Command: '%s'", + prompt.Suggestions.Preset, + prompt.Suggestions.Command, ) } else if prompt.Suggestions.Preset != "" { return self.getPresetSuggestionsFn(prompt.Suggestions.Preset) From 8dea2dab8844946a1c0654afa35f30952b1c45b9 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 23 Aug 2024 20:17:15 +0200 Subject: [PATCH 4/7] Ignore return values of fmt.Scanln --- pkg/gui/gui.go | 2 +- pkg/integration/clients/tui.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index d608fb3a4..8db1571c2 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -970,7 +970,7 @@ func (gui *Gui) runSubprocess(cmdObj oscommands.ICmdObj) error { //nolint:unpara // scan to buffer to prevent run unintentional operations when TUI resumes. var buffer string - fmt.Scanln(&buffer) // wait for enter press + _, _ = fmt.Scanln(&buffer) // wait for enter press } return err diff --git a/pkg/integration/clients/tui.go b/pkg/integration/clients/tui.go index ded94f74d..af4432d60 100644 --- a/pkg/integration/clients/tui.go +++ b/pkg/integration/clients/tui.go @@ -292,7 +292,7 @@ func suspendAndRunTest(test *components.IntegrationTest, sandbox bool, waitForDe runTuiTest(test, sandbox, waitForDebugger, raceDetector, inputDelay) fmt.Fprintf(os.Stdout, "\n%s", style.FgGreen.Sprint("press enter to return")) - fmt.Scanln() // wait for enter press + _, _ = fmt.Scanln() // wait for enter press if err := gocui.Screen.Resume(); err != nil { panic(err) From a709caf1388c7fd5705d0586335991582036b628 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 23 Aug 2024 20:17:47 +0200 Subject: [PATCH 5/7] Remove error return value from functions that always return nil --- .../helpers/confirmation_helper.go | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/pkg/gui/controllers/helpers/confirmation_helper.go b/pkg/gui/controllers/helpers/confirmation_helper.go index 8b5919c3c..60329cbed 100644 --- a/pkg/gui/controllers/helpers/confirmation_helper.go +++ b/pkg/gui/controllers/helpers/confirmation_helper.go @@ -157,7 +157,7 @@ func (self *ConfirmationHelper) getPopupPanelWidth() int { func (self *ConfirmationHelper) prepareConfirmationPanel( opts types.ConfirmOpts, -) error { +) { self.c.Views().Confirmation.Title = opts.Title // for now we do not support wrapping in our editor self.c.Views().Confirmation.Wrap = !opts.Editable @@ -176,8 +176,6 @@ func (self *ConfirmationHelper) prepareConfirmationPanel( suggestionsView.Title = fmt.Sprintf(self.c.Tr.SuggestionsTitle, self.c.UserConfig().Keybinding.Universal.TogglePanel) suggestionsView.Subtitle = "" } - - return nil } func runeForMask(mask bool) rune { @@ -207,7 +205,7 @@ func (self *ConfirmationHelper) CreatePopupPanel(ctx goContext.Context, opts typ // remove any previous keybindings self.clearConfirmationViewKeyBindings() - err := self.prepareConfirmationPanel( + self.prepareConfirmationPanel( types.ConfirmOpts{ Title: opts.Title, Prompt: opts.Prompt, @@ -215,10 +213,6 @@ func (self *ConfirmationHelper) CreatePopupPanel(ctx goContext.Context, opts typ Editable: opts.Editable, Mask: opts.Mask, }) - if err != nil { - cancel() - return err - } confirmationView := self.c.Views().Confirmation confirmationView.Editable = opts.Editable @@ -232,10 +226,7 @@ func (self *ConfirmationHelper) CreatePopupPanel(ctx goContext.Context, opts typ self.c.SetViewContent(confirmationView, style.AttrBold.Sprint(underlineLinks(opts.Prompt))) } - if err := self.setKeyBindings(cancel, opts); err != nil { - cancel() - return err - } + self.setKeyBindings(cancel, opts) self.c.Contexts().Suggestions.State.AllowEditSuggestion = opts.AllowEditSuggestion @@ -266,7 +257,7 @@ func underlineLinks(text string) string { return result + remaining } -func (self *ConfirmationHelper) setKeyBindings(cancel goContext.CancelFunc, opts types.CreatePopupPanelOpts) error { +func (self *ConfirmationHelper) setKeyBindings(cancel goContext.CancelFunc, opts types.CreatePopupPanelOpts) { var onConfirm func() error if opts.HandleConfirmPrompt != nil { onConfirm = self.wrappedPromptConfirmationFunction(cancel, opts.HandleConfirmPrompt, func() string { return self.c.Views().Confirmation.TextArea.GetContent() }) @@ -296,8 +287,6 @@ func (self *ConfirmationHelper) setKeyBindings(cancel goContext.CancelFunc, opts self.c.Contexts().Suggestions.State.OnConfirm = onSuggestionConfirm self.c.Contexts().Suggestions.State.OnClose = onClose self.c.Contexts().Suggestions.State.OnDeleteSuggestion = onDeleteSuggestion - - return nil } func (self *ConfirmationHelper) clearConfirmationViewKeyBindings() { From 8c553dcde9cc4d7a231ed6912bff612ef7e35055 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 24 Aug 2024 13:01:50 +0200 Subject: [PATCH 6/7] Upgrade golang-ci to 1.60 --- .github/workflows/ci.yml | 2 +- .golangci.yml | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index db819ccc4..733573be8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -172,7 +172,7 @@ jobs: - name: Lint uses: golangci/golangci-lint-action@v3.7.0 with: - version: v1.58 + version: v1.60 - name: errors run: golangci-lint run if: ${{ failure() }} diff --git a/.golangci.yml b/.golangci.yml index 3a8e66bc3..9fbf5329e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,13 +1,10 @@ linters: - disable: - - structcheck # gives false positives enable: - gofumpt - thelper - goimports - tparallel - wastedassign - - exportloopref - unparam - prealloc - unconvert From 457c4c248ddde8bca10b137eb33655d45034c4d1 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 24 Aug 2024 13:16:30 +0200 Subject: [PATCH 7/7] Upgrade golangci-lint-action to latest version --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 733573be8..9c57a6391 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -170,7 +170,7 @@ jobs: with: go-version: 1.22.x - name: Lint - uses: golangci/golangci-lint-action@v3.7.0 + uses: golangci/golangci-lint-action@v6.1.0 with: version: v1.60 - name: errors