From 18f48a43d5401af97dae18aab07238146b7d587b Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sat, 8 Jan 2022 15:46:35 +1100 Subject: add some more linters --- pkg/app/app.go | 8 ++++---- pkg/app/app_test.go | 1 + pkg/app/logging.go | 5 +++-- pkg/commands/git_commands/branch_test.go | 4 ++++ pkg/commands/git_commands/commit_test.go | 3 +++ pkg/commands/git_commands/config.go | 2 +- pkg/commands/git_commands/rebase_test.go | 3 +++ pkg/commands/git_commands/stash_test.go | 1 + pkg/commands/git_commands/sync_test.go | 1 + pkg/commands/git_commands/working_tree_test.go | 10 ++++++++++ pkg/commands/git_test.go | 4 ++++ pkg/commands/hosting_service/hosting_service_test.go | 2 ++ pkg/commands/loaders/commits.go | 9 +++------ pkg/commands/loaders/commits_test.go | 1 + pkg/commands/loaders/files_test.go | 1 + pkg/commands/loaders/stash_test.go | 1 + pkg/commands/oscommands/cmd_obj_runner.go | 8 +++++--- pkg/commands/oscommands/exec_live.go | 20 ++++++++++---------- pkg/commands/oscommands/gui_io.go | 6 +++--- pkg/commands/oscommands/os_test.go | 1 + pkg/commands/patch/patch_modifier.go | 2 +- pkg/commands/patch/patch_modifier_test.go | 2 ++ pkg/commands/patch/patch_parser.go | 4 +++- pkg/gui/commits_panel.go | 12 +++++------- pkg/gui/credentials_panel.go | 8 ++++---- pkg/gui/custom_commands.go | 3 ++- pkg/gui/custom_commands_test.go | 1 + pkg/gui/files_panel_test.go | 2 +- pkg/gui/gui.go | 2 +- pkg/gui/patch_building_panel.go | 4 ++-- pkg/gui/presentation/commit_files.go | 4 +++- pkg/gui/presentation/graph/cell.go | 1 + pkg/gui/rebase_options_panel.go | 2 ++ pkg/gui/undoing.go | 4 ++++ pkg/gui/view_helpers.go | 4 ++-- pkg/updates/updates.go | 15 +++++---------- pkg/utils/slice_test.go | 3 +++ 37 files changed, 104 insertions(+), 60 deletions(-) (limited to 'pkg') diff --git a/pkg/app/app.go b/pkg/app/app.go index ad3246ace..c3df367ec 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -42,7 +42,7 @@ type errorMapping struct { newError string } -func newProductionLogger(config config.AppConfigurer) *logrus.Logger { +func newProductionLogger() *logrus.Logger { log := logrus.New() log.Out = ioutil.Discard log.SetLevel(logrus.ErrorLevel) @@ -58,7 +58,7 @@ func getLogLevel() logrus.Level { return level } -func newDevelopmentLogger(configurer config.AppConfigurer) *logrus.Logger { +func newDevelopmentLogger() *logrus.Logger { logger := logrus.New() logger.SetLevel(getLogLevel()) logPath, err := config.LogPath() @@ -76,9 +76,9 @@ func newDevelopmentLogger(configurer config.AppConfigurer) *logrus.Logger { func newLogger(config config.AppConfigurer) *logrus.Entry { var log *logrus.Logger if config.GetDebug() || os.Getenv("DEBUG") == "TRUE" { - log = newDevelopmentLogger(config) + log = newDevelopmentLogger() } else { - log = newProductionLogger(config) + log = newProductionLogger() } // highly recommended: tail -f development.log | humanlog diff --git a/pkg/app/app_test.go b/pkg/app/app_test.go index 1ec46f0f7..c2cd0c8c0 100644 --- a/pkg/app/app_test.go +++ b/pkg/app/app_test.go @@ -36,6 +36,7 @@ func TestIsGitVersionValid(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.versionStr, func(t *testing.T) { result := isGitVersionValid(s.versionStr) assert.Equal(t, result, s.expectedResult) diff --git a/pkg/app/logging.go b/pkg/app/logging.go index 40d58ad62..7df0bb0c2 100644 --- a/pkg/app/logging.go +++ b/pkg/app/logging.go @@ -4,10 +4,11 @@ package app import ( - "github.com/aybabtme/humanlog" - "github.com/jesseduffield/lazygit/pkg/secureexec" "log" "os" + + "github.com/aybabtme/humanlog" + "github.com/jesseduffield/lazygit/pkg/secureexec" ) func TailLogsForPlatform(logFilePath string, opts *humanlog.HandlerOptions) { diff --git a/pkg/commands/git_commands/branch_test.go b/pkg/commands/git_commands/branch_test.go index 447ccaaff..552165695 100644 --- a/pkg/commands/git_commands/branch_test.go +++ b/pkg/commands/git_commands/branch_test.go @@ -46,6 +46,7 @@ func TestBranchGetCommitDifferences(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { instance := NewBranchCommandsWithRunner(s.runner) pushables, pullables := instance.GetCommitDifferences("HEAD", "@{u}") @@ -93,6 +94,7 @@ func TestBranchDeleteBranch(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { instance := NewBranchCommandsWithRunner(s.runner) @@ -139,6 +141,7 @@ func TestBranchCheckout(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { instance := NewBranchCommandsWithRunner(s.runner) s.test(instance.Checkout("test", CheckoutOptions{Force: s.force})) @@ -218,6 +221,7 @@ func TestBranchCurrentBranchName(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { instance := NewBranchCommandsWithRunner(s.runner) s.test(instance.CurrentBranchName()) diff --git a/pkg/commands/git_commands/commit_test.go b/pkg/commands/git_commands/commit_test.go index 6408f440a..08ee7e5cc 100644 --- a/pkg/commands/git_commands/commit_test.go +++ b/pkg/commands/git_commands/commit_test.go @@ -75,6 +75,7 @@ func TestCommitCommitObj(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { userConfig := config.GetDefaultConfig() userConfig.Git.Commit.SignOff = s.configSignoff @@ -109,6 +110,7 @@ func TestCommitCreateFixupCommit(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { instance := buildCommitCommands(commonDeps{runner: s.runner}) s.test(instance.CreateFixupCommit(s.sha)) @@ -147,6 +149,7 @@ func TestCommitShowCmdObj(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { userConfig := config.GetDefaultConfig() userConfig.Git.DiffContextSize = s.contextSize diff --git a/pkg/commands/git_commands/config.go b/pkg/commands/git_commands/config.go index e22333541..76c8b5590 100644 --- a/pkg/commands/git_commands/config.go +++ b/pkg/commands/git_commands/config.go @@ -27,7 +27,7 @@ func NewConfigCommands( return &ConfigCommands{ Common: common, gitConfig: gitConfig, - repo: repo, + // repo: repo, } } diff --git a/pkg/commands/git_commands/rebase_test.go b/pkg/commands/git_commands/rebase_test.go index e4731ad83..56df77a86 100644 --- a/pkg/commands/git_commands/rebase_test.go +++ b/pkg/commands/git_commands/rebase_test.go @@ -42,6 +42,7 @@ func TestRebaseRebaseBranch(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { instance := buildRebaseCommands(commonDeps{runner: s.runner}) s.test(instance.RebaseBranch(s.arg)) @@ -62,6 +63,7 @@ func TestRebaseSkipEditorCommand(t *testing.T) { `^GIT_EDITOR=.*$`, "^LAZYGIT_CLIENT_COMMAND=EXIT_IMMEDIATELY$", } { + regexStr := regexStr foundMatch := utils.IncludesStringFunc(envVars, func(envVar string) bool { return regexp.MustCompile(regexStr).MatchString(envVar) }) @@ -135,6 +137,7 @@ func TestRebaseDiscardOldFileChanges(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { instance := buildRebaseCommands(commonDeps{ runner: s.runner, diff --git a/pkg/commands/git_commands/stash_test.go b/pkg/commands/git_commands/stash_test.go index f9f2428e0..b41f7815b 100644 --- a/pkg/commands/git_commands/stash_test.go +++ b/pkg/commands/git_commands/stash_test.go @@ -68,6 +68,7 @@ func TestStashStashEntryCmdObj(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { userConfig := config.GetDefaultConfig() userConfig.Git.DiffContextSize = s.contextSize diff --git a/pkg/commands/git_commands/sync_test.go b/pkg/commands/git_commands/sync_test.go index a1eae5dbb..9c33381fe 100644 --- a/pkg/commands/git_commands/sync_test.go +++ b/pkg/commands/git_commands/sync_test.go @@ -85,6 +85,7 @@ func TestSyncPush(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { instance := buildSyncCommands(commonDeps{}) s.test(instance.PushCmdObj(s.opts)) diff --git a/pkg/commands/git_commands/working_tree_test.go b/pkg/commands/git_commands/working_tree_test.go index a6d2345e9..ef3aedcf9 100644 --- a/pkg/commands/git_commands/working_tree_test.go +++ b/pkg/commands/git_commands/working_tree_test.go @@ -53,6 +53,7 @@ func TestWorkingTreeUnstageFile(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { instance := buildWorkingTreeCommands(commonDeps{runner: s.runner}) s.test(instance.UnStageFile([]string{"test.txt"}, s.reset)) @@ -181,6 +182,7 @@ func TestWorkingTreeDiscardAllFileChanges(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { instance := buildWorkingTreeCommands(commonDeps{runner: s.runner, removeFile: s.removeFile}) err := instance.DiscardAllFileChanges(s.file) @@ -296,6 +298,7 @@ func TestWorkingTreeDiff(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { userConfig := config.GetDefaultConfig() userConfig.Git.DiffContextSize = s.contextSize @@ -345,6 +348,7 @@ func TestWorkingTreeShowFileDiff(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { userConfig := config.GetDefaultConfig() userConfig.Git.DiffContextSize = s.contextSize @@ -392,6 +396,7 @@ func TestWorkingTreeCheckoutFile(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { instance := buildWorkingTreeCommands(commonDeps{runner: s.runner}) @@ -445,6 +450,7 @@ func TestWorkingTreeApplyPatch(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { instance := buildWorkingTreeCommands(commonDeps{runner: s.runner}) s.test(instance.ApplyPatch("test", "cached")) @@ -474,6 +480,7 @@ func TestWorkingTreeDiscardUnstagedFileChanges(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { instance := buildWorkingTreeCommands(commonDeps{runner: s.runner}) s.test(instance.DiscardUnstagedFileChanges(s.file)) @@ -501,6 +508,7 @@ func TestWorkingTreeDiscardAnyUnstagedFileChanges(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { instance := buildWorkingTreeCommands(commonDeps{runner: s.runner}) s.test(instance.DiscardAnyUnstagedFileChanges()) @@ -528,6 +536,7 @@ func TestWorkingTreeRemoveUntrackedFiles(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { instance := buildWorkingTreeCommands(commonDeps{runner: s.runner}) s.test(instance.RemoveUntrackedFiles()) @@ -557,6 +566,7 @@ func TestWorkingTreeResetHard(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { instance := buildWorkingTreeCommands(commonDeps{runner: s.runner}) s.test(instance.ResetHard(s.ref)) diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go index b730bf6dc..684696a8c 100644 --- a/pkg/commands/git_test.go +++ b/pkg/commands/git_test.go @@ -104,6 +104,7 @@ func TestNavigateToRepoRootDirectory(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { s.test(navigateToRepoRootDirectory(s.stat, s.chdir)) }) @@ -159,6 +160,7 @@ func TestSetupRepository(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { s.test(setupRepository(s.openGitRepository, s.errorStr)) }) @@ -206,6 +208,7 @@ func TestNewGitCommand(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { s.setup() s.test(NewGitCommand(utils.NewDummyCommon(), oscommands.NewDummyOSCommand(), git_config.NewFakeGitConfig(nil))) @@ -282,6 +285,7 @@ func TestFindDotGitDir(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { s.test(findDotGitDir(s.stat, s.readFile)) }) diff --git a/pkg/commands/hosting_service/hosting_service_test.go b/pkg/commands/hosting_service/hosting_service_test.go index ab7a2b402..f762135c3 100644 --- a/pkg/commands/hosting_service/hosting_service_test.go +++ b/pkg/commands/hosting_service/hosting_service_test.go @@ -56,6 +56,7 @@ func TestGetRepoInfoFromURL(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { result, err := s.serviceDefinition.getRepoInfoFromURL(s.repoURL) assert.NoError(t, err) @@ -222,6 +223,7 @@ func TestGetPullRequestURL(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { tr := i18n.EnglishTranslationSet() log := &test.FakeFieldLogger{} diff --git a/pkg/commands/loaders/commits.go b/pkg/commands/loaders/commits.go index cc2442c96..ea54a4e76 100644 --- a/pkg/commands/loaders/commits.go +++ b/pkg/commands/loaders/commits.go @@ -274,10 +274,7 @@ func (self *CommitLoader) getNormalRebasingCommits() ([]*models.Commit, error) { return err } content := string(bytesContent) - commit, err := self.commitFromPatch(content) - if err != nil { - return err - } + commit := self.commitFromPatch(content) commits = append([]*models.Commit{commit}, commits...) return nil }) @@ -334,7 +331,7 @@ func (self *CommitLoader) getInteractiveRebasingCommits() ([]*models.Commit, err // From: Lazygit Tester // Date: Wed, 5 Dec 2018 21:03:23 +1100 // Subject: second commit on master -func (self *CommitLoader) commitFromPatch(content string) (*models.Commit, error) { +func (self *CommitLoader) commitFromPatch(content string) *models.Commit { lines := strings.Split(content, "\n") sha := strings.Split(lines[0], " ")[1] name := strings.TrimPrefix(lines[3], "Subject: ") @@ -342,7 +339,7 @@ func (self *CommitLoader) commitFromPatch(content string) (*models.Commit, error Sha: sha, Name: name, Status: "rebasing", - }, nil + } } func (self *CommitLoader) setCommitMergedStatuses(refName string, commits []*models.Commit) ([]*models.Commit, error) { diff --git a/pkg/commands/loaders/commits_test.go b/pkg/commands/loaders/commits_test.go index 5491fb4a5..9eda80708 100644 --- a/pkg/commands/loaders/commits_test.go +++ b/pkg/commands/loaders/commits_test.go @@ -186,6 +186,7 @@ func TestGetCommits(t *testing.T) { } for _, scenario := range scenarios { + scenario := scenario t.Run(scenario.testName, func(t *testing.T) { builder := &CommitLoader{ Common: utils.NewDummyCommon(), diff --git a/pkg/commands/loaders/files_test.go b/pkg/commands/loaders/files_test.go index 2f1b12704..825164e01 100644 --- a/pkg/commands/loaders/files_test.go +++ b/pkg/commands/loaders/files_test.go @@ -186,6 +186,7 @@ func TestFileGetStatusFiles(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { cmd := oscommands.NewDummyCmdObjBuilder(s.runner) gitConfig := git_config.NewFakeGitConfig(map[string]string{"status.showUntrackedFiles": "yes"}) diff --git a/pkg/commands/loaders/stash_test.go b/pkg/commands/loaders/stash_test.go index 31c83792f..e7999e861 100644 --- a/pkg/commands/loaders/stash_test.go +++ b/pkg/commands/loaders/stash_test.go @@ -48,6 +48,7 @@ func TestGetStashEntries(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { cmd := oscommands.NewDummyCmdObjBuilder(s.runner) diff --git a/pkg/commands/oscommands/cmd_obj_runner.go b/pkg/commands/oscommands/cmd_obj_runner.go index 816e56ad6..bbd3c85cc 100644 --- a/pkg/commands/oscommands/cmd_obj_runner.go +++ b/pkg/commands/oscommands/cmd_obj_runner.go @@ -26,11 +26,13 @@ func (self *cmdObjRunner) runWithCredentialHandling(cmdObj ICmdObj) error { case PROMPT: return self.RunAndDetectCredentialRequest(cmdObj, self.guiIO.promptForCredentialFn) case FAIL: - return self.RunAndDetectCredentialRequest(cmdObj, func(CredentialName) string { return "\n" }) + return self.RunAndDetectCredentialRequest(cmdObj, func(CredentialType) string { return "\n" }) + case NONE: + // we should never land here + return errors.New("runWithCredentialHandling called but cmdObj does not have a a credential strategy") } - // we should never land here - return errors.New("runWithCredentialHandling called but cmdObj does not have a a credential strategy") + return errors.New("unexpected credential strategy") } func (self *cmdObjRunner) Run(cmdObj ICmdObj) error { diff --git a/pkg/commands/oscommands/exec_live.go b/pkg/commands/oscommands/exec_live.go index 3526cdbd2..efddf355e 100644 --- a/pkg/commands/oscommands/exec_live.go +++ b/pkg/commands/oscommands/exec_live.go @@ -13,27 +13,27 @@ import ( "github.com/jesseduffield/lazygit/pkg/utils" ) -type CredentialName string +type CredentialType int const ( - Password CredentialName = "password" - Username = "username" - Passphrase = "passphrase" + Password CredentialType = iota + Username + Passphrase ) // RunAndDetectCredentialRequest detect a username / password / passphrase question in a command // promptUserForCredential is a function that gets executed when this function detect you need to fillin a password or passphrase // The promptUserForCredential argument will be "username", "password" or "passphrase" and expects the user's password/passphrase or username back -func (self *cmdObjRunner) RunAndDetectCredentialRequest(cmdObj ICmdObj, promptUserForCredential func(CredentialName) string) error { +func (self *cmdObjRunner) RunAndDetectCredentialRequest(cmdObj ICmdObj, promptUserForCredential func(CredentialType) string) error { ttyText := "" err := self.RunCommandWithOutputLive(cmdObj, func(word string) string { ttyText = ttyText + " " + word - prompts := map[string]CredentialName{ - `.+'s password:`: "password", - `Password\s*for\s*'.+':`: "password", - `Username\s*for\s*'.+':`: "username", - `Enter\s*passphrase\s*for\s*key\s*'.+':`: "passphrase", + prompts := map[string]CredentialType{ + `.+'s password:`: Password, + `Password\s*for\s*'.+':`: Password, + `Username\s*for\s*'.+':`: Username, + `Enter\s*passphrase\s*for\s*key\s*'.+':`: Passphrase, } for pattern, askFor := range prompts { diff --git a/pkg/commands/oscommands/gui_io.go b/pkg/commands/oscommands/gui_io.go index 5a174d46c..33a02874b 100644 --- a/pkg/commands/oscommands/gui_io.go +++ b/pkg/commands/oscommands/gui_io.go @@ -27,10 +27,10 @@ type guiIO struct { // this allows us to request info from the user like username/password, in the event // that a command requests it. // the 'credential' arg is something like 'username' or 'password' - promptForCredentialFn func(credential CredentialName) string + promptForCredentialFn func(credential CredentialType) string } -func NewGuiIO(log *logrus.Entry, logCommandFn func(string, bool), newCmdWriterFn func() io.Writer, promptForCredentialFn func(CredentialName) string) *guiIO { +func NewGuiIO(log *logrus.Entry, logCommandFn func(string, bool), newCmdWriterFn func() io.Writer, promptForCredentialFn func(CredentialType) string) *guiIO { return &guiIO{ log: log, logCommandFn: logCommandFn, @@ -44,6 +44,6 @@ func NewNullGuiIO(log *logrus.Entry) *guiIO { log: log, logCommandFn: func(string, bool) {}, newCmdWriterFn: func() io.Writer { return ioutil.Discard }, - promptForCredentialFn: func(CredentialName) string { return "" }, + promptForCredentialFn: func(CredentialType) string { return "" }, } } diff --git a/pkg/commands/oscommands/os_test.go b/pkg/commands/oscommands/os_test.go index b5d8879b9..efda5a3a1 100644 --- a/pkg/commands/oscommands/os_test.go +++ b/pkg/commands/oscommands/os_test.go @@ -190,6 +190,7 @@ func TestOSCommandCreateTempFile(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { s.test(NewDummyOSCommand().CreateTempFile(s.filename, s.content)) }) diff --git a/pkg/commands/patch/patch_modifier.go b/pkg/commands/patch/patch_modifier.go index 3ab13931b..2109ad1f0 100644 --- a/pkg/commands/patch/patch_modifier.go +++ b/pkg/commands/patch/patch_modifier.go @@ -22,7 +22,7 @@ func GetHeaderFromDiff(diff string) string { func GetHunksFromDiff(diff string) []*PatchHunk { hunks := []*PatchHunk{} firstLineIdx := -1 - var hunkLines []string + var hunkLines []string //nolint:prealloc pastDiffHeader := false for lineIdx, line := range strings.SplitAfter(diff, "\n") { diff --git a/pkg/commands/patch/patch_modifier_test.go b/pkg/commands/patch/patch_modifier_test.go index 8b866019b..ec79cbe32 100644 --- a/pkg/commands/patch/patch_modifier_test.go +++ b/pkg/commands/patch/patch_modifier_test.go @@ -511,6 +511,7 @@ func TestModifyPatchForRange(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { result := ModifiedPatchForRange(nil, s.filename, s.diffText, s.firstLineIndex, s.lastLineIndex, s.reverse, false) if !assert.Equal(t, s.expected, result) { @@ -538,6 +539,7 @@ func TestLineNumberOfLine(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { result := s.hunk.LineNumberOfLine(s.idx) if !assert.Equal(t, s.expected, result) { diff --git a/pkg/commands/patch/patch_parser.go b/pkg/commands/patch/patch_parser.go index 1fefe0748..c2be120c9 100644 --- a/pkg/commands/patch/patch_parser.go +++ b/pkg/commands/patch/patch_parser.go @@ -98,7 +98,7 @@ func (l *PatchLine) render(selected bool, included bool) string { return coloredString(style.FgCyan, match[1], selected, included) + coloredString(theme.DefaultTextColor, match[2], selected, false) } - textStyle := theme.DefaultTextColor + var textStyle style.TextStyle switch l.Kind { case PATCH_HEADER: textStyle = textStyle.SetBold() @@ -108,6 +108,8 @@ func (l *PatchLine) render(selected bool, included bool) string { textStyle = style.FgRed case COMMIT_SHA: textStyle = style.FgYellow + default: + textStyle = theme.DefaultTextColor } return coloredString(textStyle, content, selected, included) diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go index 3817e9e47..fcc49d839 100644 --- a/pkg/gui/commits_panel.go +++ b/pkg/gui/commits_panel.go @@ -79,7 +79,7 @@ func (gui *Gui) refreshReflogCommitsConsideringStartup() { // whenever we change commits, we should update branches because the upstream/downstream // counts can change. Whenever we change branches we should probably also change commits // e.g. in the case of switching branches. -func (gui *Gui) refreshCommits() error { +func (gui *Gui) refreshCommits() { wg := sync.WaitGroup{} wg.Add(2) @@ -110,8 +110,6 @@ func (gui *Gui) refreshCommits() error { }) wg.Wait() - - return nil } func (gui *Gui) refreshCommitsWithLimit() error { @@ -605,7 +603,7 @@ func (gui *Gui) createTagMenu(commitSha string) error { return gui.createMenu(gui.Tr.TagMenuTitle, items, createMenuOptions{showCancel: true}) } -func (gui *Gui) afterTagCreate(tagName string) error { +func (gui *Gui) afterTagCreate() error { gui.State.Panels.Tags.SelectedLineIdx = 0 // Set to the top return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{COMMITS, TAGS}}) } @@ -621,7 +619,7 @@ func (gui *Gui) handleCreateAnnotatedTag(commitSha string) error { if err := gui.Git.Tag.CreateAnnotated(tagName, commitSha, msg); err != nil { return gui.surfaceError(err) } - return gui.afterTagCreate(tagName) + return gui.afterTagCreate() }, }) }, @@ -636,7 +634,7 @@ func (gui *Gui) handleCreateLightweightTag(commitSha string) error { if err := gui.Git.Tag.CreateLightweight(tagName, commitSha); err != nil { return gui.surfaceError(err) } - return gui.afterTagCreate(tagName) + return gui.afterTagCreate() }, }) } @@ -666,7 +664,7 @@ func (gui *Gui) handleCreateCommitResetMenu() error { return gui.createResetMenu(commit.Sha) } -func (gui *Gui) handleOpenSearchForCommitsPanel(_viewName string) error { +func (gui *Gui) handleOpenSearchForCommitsPanel(string) error { // we usually lazyload these commits but now that we're searching we need to load them now if gui.State.Panels.Commits.LimitCommits { gui.State.Panels.Commits.LimitCommits = false diff --git a/pkg/gui/credentials_panel.go b/pkg/gui/credentials_panel.go index 69c08359f..b4c313e07 100644 --- a/pkg/gui/credentials_panel.go +++ b/pkg/gui/credentials_panel.go @@ -11,18 +11,18 @@ import ( type credentials chan string // promptUserForCredential wait for a username, password or passphrase input from the credentials popup -func (gui *Gui) promptUserForCredential(passOrUname oscommands.CredentialName) string { +func (gui *Gui) promptUserForCredential(passOrUname oscommands.CredentialType) string { gui.credentials = make(chan string) gui.g.Update(func(g *gocui.Gui) error { credentialsView := gui.Views.Credentials switch passOrUname { - case "username": + case oscommands.Username: credentialsView.Title = gui.Tr.CredentialsUsername credentialsView.Mask = 0 - case "password": + case oscommands.Password: credentialsView.Title = gui.Tr.CredentialsPassword credentialsView.Mask = '*' - case "passphrase": + case oscommands.Passphrase: credentialsView.Title = gui.Tr.CredentialsPassphrase credentialsView.Mask = '*' } diff --git a/pkg/gui/custom_commands.go b/pkg/gui/custom_commands.go index 7d8cdd281..c55b58a02 100644 --- a/pkg/gui/custom_commands.go +++ b/pkg/gui/custom_commands.go @@ -144,7 +144,7 @@ func (gui *Gui) GenerateMenuCandidates(commandOutput, filter, valueFormat, label } candidates := []commandMenuEntry{} - for _, str := range strings.Split(string(commandOutput), "\n") { + for _, str := range strings.Split(commandOutput, "\n") { if str == "" { continue } @@ -216,6 +216,7 @@ func (gui *Gui) menuPromptFromCommand(prompt config.CustomCommandPrompt, promptR menuItems := make([]*menuItem, len(candidates)) for i := range candidates { + i := i menuItems[i] = &menuItem{ displayStrings: []string{candidates[i].label}, onPress: func() error { diff --git a/pkg/gui/custom_commands_test.go b/pkg/gui/custom_commands_test.go index d51617c09..d31bcf291 100644 --- a/pkg/gui/custom_commands_test.go +++ b/pkg/gui/custom_commands_test.go @@ -56,6 +56,7 @@ func TestGuiGenerateMenuCandidates(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { s.test(NewDummyGui().GenerateMenuCandidates(s.cmdOut, s.filter, s.valueFormat, s.labelFormat)) }) diff --git a/pkg/gui/files_panel_test.go b/pkg/gui/files_panel_test.go index fcf8fe66b..8946898e5 100644 --- a/pkg/gui/files_panel_test.go +++ b/pkg/gui/files_panel_test.go @@ -24,7 +24,7 @@ func TestGetSuggestedRemote(t *testing.T) { } func mkRemoteList(names ...string) []*models.Remote { - var result []*models.Remote + result := make([]*models.Remote, 0, len(names)) for _, name := range names { result = append(result, &models.Remote{Name: name}) diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 41ccf2283..ded51cd7d 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -648,7 +648,7 @@ func (gui *Gui) runSubprocessWithSuspense(subprocess oscommands.ICmdObj) (bool, return cmdErr == nil, gui.surfaceError(cmdErr) } -func (gui *Gui) runSubprocess(cmdObj oscommands.ICmdObj) error { +func (gui *Gui) runSubprocess(cmdObj oscommands.ICmdObj) error { //nolint:unparam gui.logCommand(cmdObj.ToString(), true) subprocess := cmdObj.GetCmd() diff --git a/pkg/gui/patch_building_panel.go b/pkg/gui/patch_building_panel.go index 5f99b42b5..ee1610fb4 100644 --- a/pkg/gui/patch_building_panel.go +++ b/pkg/gui/patch_building_panel.go @@ -17,7 +17,7 @@ func (gui *Gui) getFromAndReverseArgsForDiff(to string) (string, bool) { return from, reverse } -func (gui *Gui) refreshPatchBuildingPanel(selectedLineIdx int, state *LblPanelState) error { +func (gui *Gui) refreshPatchBuildingPanel(selectedLineIdx int) error { if !gui.Git.Patch.PatchManager.Active() { return gui.handleEscapePatchBuildingPanel() } @@ -59,7 +59,7 @@ func (gui *Gui) handleRefreshPatchBuildingPanel(selectedLineIdx int) error { gui.Mutexes.LineByLinePanelMutex.Lock() defer gui.Mutexes.LineByLinePanelMutex.Unlock() - return gui.refreshPatchBuildingPanel(selectedLineIdx, gui.State.Panels.LineByLine) + return gui.refreshPatchBuildingPanel(selectedLineIdx) } func (gui *Gui) handleToggleSelectionForPatch() error { diff --git a/pkg/gui/presentation/commit_files.go b/pkg/gui/presentation/commit_files.go index 3b68b9eeb..6a351be48 100644 --- a/pkg/gui/presentation/commit_files.go +++ b/pkg/gui/presentation/commit_files.go @@ -9,7 +9,7 @@ import ( ) func GetCommitFileLine(name string, diffName string, commitFile *models.CommitFile, status patch.PatchStatus) string { - colour := theme.DefaultTextColor + var colour style.TextStyle if diffName == name { colour = theme.DiffTerminalColor } else { @@ -18,6 +18,8 @@ func GetCommitFileLine(name string, diffName string, commitFile *models.CommitFi colour = style.FgGreen case patch.PART: colour = style.FgYellow + case patch.UNSELECTED: + colour = theme.DefaultTextColor } } diff --git a/pkg/gui/presentation/graph/cell.go b/pkg/gui/presentation/graph/cell.go index 9ba7d92fb..e970c6dd2 100644 --- a/pkg/gui/presentation/graph/cell.go +++ b/pkg/gui/presentation/graph/cell.go @@ -121,6 +121,7 @@ func (cell *Cell) setLeft(style style.TextStyle) *Cell { return cell } +//nolint:unparam func (cell *Cell) setRight(style style.TextStyle, override bool) *Cell { cell.right = true if cell.rightStyle == nil || override { diff --git a/pkg/gui/rebase_options_panel.go b/pkg/gui/rebase_options_panel.go index e3e8ab621..a9e7d9317 100644 --- a/pkg/gui/rebase_options_panel.go +++ b/pkg/gui/rebase_options_panel.go @@ -59,6 +59,8 @@ func (gui *Gui) genericMergeCommand(command string) error { commandType = "merge" case enums.REBASE_MODE_REBASING: commandType = "rebase" + default: + // shouldn't be possible to land here } // we should end up with a command like 'git merge --continue' diff --git a/pkg/gui/undoing.go b/pkg/gui/undoing.go index 09e1a0328..72a4ef302 100644 --- a/pkg/gui/undoing.go +++ b/pkg/gui/undoing.go @@ -110,6 +110,8 @@ func (gui *Gui) reflogUndo() error { EnvVars: undoEnvVars, WaitingStatus: undoingStatus, }) + case CURRENT_REBASE: + // do nothing } gui.Log.Error("didn't match on the user action when trying to undo") @@ -146,6 +148,8 @@ func (gui *Gui) reflogRedo() error { EnvVars: redoEnvVars, WaitingStatus: redoingStatus, }) + case CURRENT_REBASE: + // do nothing } gui.Log.Error("didn't match on the user action when trying to redo") diff --git a/pkg/gui/view_helpers.go b/pkg/gui/view_helpers.go index 3401ce81b..00b28b45c 100644 --- a/pkg/gui/view_helpers.go +++ b/pkg/gui/view_helpers.go @@ -114,9 +114,9 @@ func (gui *Gui) refreshSidePanels(options refreshOptions) error { wg.Add(1) func() { if options.mode == ASYNC { - go utils.Safe(func() { _ = gui.refreshCommits() }) + go utils.Safe(func() { gui.refreshCommits() }) } else { - _ = gui.refreshCommits() + gui.refreshCommits() } wg.Done() }() diff --git a/pkg/updates/updates.go b/pkg/updates/updates.go index ef873fdf7..1c52d0419 100644 --- a/pkg/updates/updates.go +++ b/pkg/updates/updates.go @@ -121,10 +121,8 @@ func (u *Updater) checkForNewUpdate() (string, error) { return "", errors.New(errMessage) } - rawUrl, err := u.getBinaryUrl(newVersion) - if err != nil { - return "", err - } + rawUrl := u.getBinaryUrl(newVersion) + u.Log.Info("Checking for resource at url " + rawUrl) if !u.verifyResourceFound(rawUrl) { errMessage := utils.ResolvePlaceholderString( @@ -224,7 +222,7 @@ func (u *Updater) zipExtension() string { } // example: https://github.com/jesseduffield/lazygit/releases/download/v0.1.73/lazygit_0.1.73_Darwin_x86_64.tar.gz -func (u *Updater) getBinaryUrl(newVersion string) (string, error) { +func (u *Updater) getBinaryUrl(newVersion string) string { url := fmt.Sprintf( "%s/releases/download/%s/lazygit_%s_%s_%s.%s", constants.Links.RepoUrl, @@ -235,7 +233,7 @@ func (u *Updater) getBinaryUrl(newVersion string) (string, error) { u.zipExtension(), ) u.Log.Info("Url for latest release is " + url) - return url, nil + return url } // Update downloads the latest binary and replaces the current binary with it @@ -249,10 +247,7 @@ func (u *Updater) Update(newVersion string, onFinish func(error) error) { } func (u *Updater) update(newVersion string) error { - rawUrl, err := u.getBinaryUrl(newVersion) - if err != nil { - return err - } + rawUrl := u.getBinaryUrl(newVersion) u.Log.Info("Updating with url " + rawUrl) return u.downloadAndInstall(rawUrl) } diff --git a/pkg/utils/slice_test.go b/pkg/utils/slice_test.go index 67dcd00bf..fc80a46d7 100644 --- a/pkg/utils/slice_test.go +++ b/pkg/utils/slice_test.go @@ -85,6 +85,7 @@ func TestNextIndex(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { assert.EqualValues(t, s.expected, NextIndex(s.list, s.element)) }) @@ -128,6 +129,7 @@ func TestPrevIndex(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { assert.EqualValues(t, s.expected, PrevIndex(s.list, s.element)) }) @@ -160,6 +162,7 @@ func TestEscapeSpecialChars(t *testing.T) { } for _, s := range scenarios { + s := s t.Run(s.testName, func(t *testing.T) { assert.EqualValues(t, s.expected, EscapeSpecialChars(s.input)) }) -- cgit v1.2.3