Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix linter warnings #3854

Merged
merged 7 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ 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.58
version: v1.60
- name: errors
run: golangci-lint run
if: ${{ failure() }}
Expand Down
3 changes: 0 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
linters:
disable:
- structcheck # gives false positives
enable:
- gofumpt
- thelper
- goimports
- tparallel
- wastedassign
- exportloopref
- unparam
- prealloc
- unconvert
Expand Down
8 changes: 4 additions & 4 deletions pkg/commands/git_config/cached_git_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/controllers/branches_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Copy link
Owner

@jesseduffield jesseduffield Aug 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope this thing checks the value of CreatePullRequestOptions cos for some of these we have a '%s' in there (in english.go that is)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it doesn't. It simply warns when you are using printf with only a format string, without additional args.

It can (and does) check for '%s' only if the format string is a literal.

}

func (self *BranchesController) createPullRequest(from string, to string) error {
Expand Down
19 changes: 4 additions & 15 deletions pkg/gui/controllers/helpers/confirmation_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -207,18 +205,14 @@ 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,
FindSuggestionsFunc: opts.FindSuggestionsFunc,
Editable: opts.Editable,
Mask: opts.Mask,
})
if err != nil {
cancel()
return err
}
confirmationView := self.c.Views().Confirmation
confirmationView.Editable = opts.Editable

Expand All @@ -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

Expand Down Expand Up @@ -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() })
Expand Down Expand Up @@ -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() {
Expand Down
5 changes: 2 additions & 3 deletions pkg/gui/controllers/helpers/refresh_helper.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package helpers

import (
"fmt"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions pkg/gui/services/custom_commands/handler_creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/integration/clients/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/integration/clients/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading