diff options
69 files changed, 1510 insertions, 204 deletions
diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml index 4eaff9686..36d301e59 100644 --- a/.github/workflows/automerge.yml +++ b/.github/workflows/automerge.yml @@ -25,4 +25,4 @@ jobs: uses: "pascalgn/automerge-action@135f0bdb927d9807b5446f7ca9ecc2c51de03c4a" env: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - MERGE_METHOD: rebase
\ No newline at end of file + MERGE_METHOD: rebase diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index a07cf1154..8e720d96b 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -16,7 +16,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v1 with: - go-version: 1.16.x + go-version: 1.18.x - name: Run goreleaser uses: goreleaser/goreleaser-action@v1 env: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2176fef97..f933ddb1b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,8 @@ name: Continuous Integration +env: + GO_VERSION: 1.18 + on: push: branches: @@ -24,7 +27,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v1 with: - go-version: 1.16.x + go-version: 1.18.x - name: Cache build uses: actions/cache@v1 with: @@ -46,7 +49,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v1 with: - go-version: 1.16.x + go-version: 1.18.x - name: Cache build uses: actions/cache@v1 with: @@ -74,7 +77,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v1 with: - go-version: 1.16.x + go-version: 1.18.x - name: Cache build uses: actions/cache@v1 with: @@ -87,11 +90,24 @@ jobs: go run scripts/cheatsheet/main.go check lint: runs-on: ubuntu-latest + env: + GOFLAGS: -mod=vendor steps: - - name: Checkout + - name: Checkout code uses: actions/checkout@v2 + - name: Setup Go + uses: actions/setup-go@v1 + with: + go-version: 1.18.x + - name: Cache build + uses: actions/cache@v1 + with: + path: ~/.cache/go-build + key: ${{runner.os}}-go-${{hashFiles('**/go.sum')}}-test + restore-keys: | + ${{runner.os}}-go- - name: Lint - uses: golangci/golangci-lint-action@v2 + uses: golangci/golangci-lint-action@v3.1.0 with: version: latest - name: Format code diff --git a/.gitignore b/.gitignore index 84258eeee..ea0475b55 100644 --- a/.gitignore +++ b/.gitignore @@ -23,8 +23,10 @@ lazygit.exe # Exceptions !.gitignore !.goreleaser.yml +!.golangci.yml !.circleci/ !.github/ + # these are for our integration tests !.git_keep !.gitmodules_keep diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 000000000..358a5d12a --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,24 @@ +linters: + disable: + - structcheck # gives false positives + enable: + - gofumpt + - thelper + - goimports + - tparallel + - wastedassign + - exportloopref + - unparam + - prealloc + - unconvert + - exhaustive + - makezero + # - goconst # TODO: enable and fix issues + fast: false + +linters-settings: + exhaustive: + default-signifies-exhaustive: true + +run: + go: 1.18 @@ -30,6 +30,7 @@ require ( github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad github.com/stretchr/testify v1.7.0 github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 + golang.org/x/exp v0.0.0-20220318154914-8dddf5d87bd8 gopkg.in/ozeidan/fuzzy-patricia.v3 v3.0.0 ) @@ -63,5 +64,5 @@ require ( golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect golang.org/x/text v0.3.7 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect - gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect + gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) @@ -157,6 +157,8 @@ golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0 h1:hb9wdF1z5waM+dSIICn1l0DkLVDT3hqhhQsDNUmHPRE= golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/exp v0.0.0-20220318154914-8dddf5d87bd8 h1:s/+U+w0teGzcoH2mdIlFQ6KfVKGaYpgyGdUefZrn9TU= +golang.org/x/exp v0.0.0-20220318154914-8dddf5d87bd8/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -205,5 +207,6 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/app/app.go b/pkg/app/app.go index 0ee7e4adf..2d279936f 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -65,7 +65,7 @@ func newDevelopmentLogger() *logrus.Logger { if err != nil { log.Fatal(err) } - file, err := os.OpenFile(logPath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) + file, err := os.OpenFile(logPath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o666) if err != nil { log.Fatalf("Unable to log to log file: %v", err) } @@ -269,10 +269,9 @@ func (app *App) Rebase() error { app.Log.Info("args: ", os.Args) if strings.HasSuffix(os.Args[1], "git-rebase-todo") { - if err := ioutil.WriteFile(os.Args[1], []byte(os.Getenv("LAZYGIT_REBASE_TODO")), 0644); err != nil { + if err := ioutil.WriteFile(os.Args[1], []byte(os.Getenv("LAZYGIT_REBASE_TODO")), 0o644); err != nil { return err } - } else if strings.HasSuffix(os.Args[1], filepath.Join(gitDir(), "COMMIT_EDITMSG")) { // TODO: test // if we are rebasing and squashing, we'll see a COMMIT_EDITMSG // but in this case we don't need to edit it, so we'll just return diff --git a/pkg/app/logging_windows.go b/pkg/app/logging_windows.go index f8b3d4990..efbdfbbe1 100644 --- a/pkg/app/logging_windows.go +++ b/pkg/app/logging_windows.go @@ -5,11 +5,12 @@ package app import ( "bufio" - "github.com/aybabtme/humanlog" "log" "os" "strings" "time" + + "github.com/aybabtme/humanlog" ) func TailLogsForPlatform(logFilePath string, opts *humanlog.HandlerOptions) { diff --git a/pkg/cheatsheet/check.go b/pkg/cheatsheet/check.go index 03f65d910..ebcd0629f 100644 --- a/pkg/cheatsheet/check.go +++ b/pkg/cheatsheet/check.go @@ -19,7 +19,7 @@ func Check() { if err != nil { log.Fatalf("Error occured while checking if cheatsheets are up to date: %v", err) } - err = os.Mkdir(tmpDir, 0700) + err = os.Mkdir(tmpDir, 0o700) if err != nil { log.Fatalf("Error occured while checking if cheatsheets are up to date: %v", err) } @@ -70,7 +70,6 @@ func obtainContent(dir string) string { return nil }) - if err != nil { log.Fatalf("Error occured while checking if cheatsheets are up to date: %v", err) } diff --git a/pkg/cheatsheet/generate.go b/pkg/cheatsheet/generate.go index 804cb6b45..c7c2b0d37 100644 --- a/pkg/cheatsheet/generate.go +++ b/pkg/cheatsheet/generate.go @@ -174,7 +174,7 @@ outer: bindings []*types.Binding } - groupedBindings := make([]groupedBindingsType, len(contextAndViewBindingMap)) + groupedBindings := make([]groupedBindingsType, 0, len(contextAndViewBindingMap)) for contextAndView, contextBindings := range contextAndViewBindingMap { groupedBindings = append(groupedBindings, groupedBindingsType{contextAndView: contextAndView, bindings: contextBindings}) diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 3880e0dfc..6c6a3ac7c 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -223,7 +223,6 @@ func setupRepository(openGitRepository func(string) (*gogit.Repository, error), } repository, err := openGitRepository(path) - if err != nil { if strings.Contains(err.Error(), `unquoted '\' must be followed by new line`) { return nil, errors.New(gitConfigParseErrorStr) diff --git a/pkg/commands/git_commands/rebase.go b/pkg/commands/git_commands/rebase.go index c726cad7e..71c8b0e63 100644 --- a/pkg/commands/git_commands/rebase.go +++ b/pkg/commands/git_commands/rebase.go @@ -185,7 +185,7 @@ func (self *RebaseCommands) EditRebaseTodo(index int, action string) error { content[contentIndex] = action + " " + strings.Join(splitLine[1:], " ") result := strings.Join(content, "\n") - return ioutil.WriteFile(fileName, []byte(result), 0644) + return ioutil.WriteFile(fileName, []byte(result), 0o644) } func (self *RebaseCommands) getTodoCommitCount(content []string) int { @@ -215,7 +215,7 @@ func (self *RebaseCommands) MoveTodoDown(index int) error { rearrangedContent = append(rearrangedContent, content[contentIndex+1:]...) result := strings.Join(rearrangedContent, "\n") - return ioutil.WriteFile(fileName, []byte(result), 0644) + return ioutil.WriteFile(fileName, []byte(result), 0o644) } // SquashAllAboveFixupCommits squashes all fixup! commits above the given one diff --git a/pkg/commands/hosting_service/hosting_service.go b/pkg/commands/hosting_service/hosting_service.go index 4a0a49681..b448e3925 100644 --- a/pkg/commands/hosting_service/hosting_service.go +++ b/pkg/commands/hosting_service/hosting_service.go @@ -9,6 +9,8 @@ import ( "github.com/jesseduffield/lazygit/pkg/i18n" "github.com/jesseduffield/lazygit/pkg/utils" "github.com/sirupsen/logrus" + + "golang.org/x/exp/slices" ) // This package is for handling logic specific to a git hosting service like github, gitlab, bitbucket, etc. @@ -94,8 +96,7 @@ func (self *HostingServiceMgr) getCandidateServiceDomains() []ServiceDomain { serviceDefinitionByProvider[serviceDefinition.provider] = serviceDefinition } - var serviceDomains = make([]ServiceDomain, len(defaultServiceDomains)) - copy(serviceDomains, defaultServiceDomains) + serviceDomains := slices.Clone(defaultServiceDomains) if len(self.configServiceDomains) > 0 { for gitDomain, typeAndDomain := range self.configServiceDomains { diff --git a/pkg/commands/oscommands/cmd_obj_runner_win.go b/pkg/commands/oscommands/cmd_obj_runner_win.go index 9e3d1fd02..9a64dfa77 100644 --- a/pkg/commands/oscommands/cmd_obj_runner_win.go +++ b/pkg/commands/oscommands/cmd_obj_runner_win.go @@ -20,6 +20,7 @@ func (b *Buffer) Read(p []byte) (n int, err error) { defer b.m.Unlock() return b.b.Read(p) } + func (b *Buffer) Write(p []byte) (n int, err error) { b.m.Lock() defer b.m.Unlock() diff --git a/pkg/commands/oscommands/fake_cmd_obj_runner.go b/pkg/commands/oscommands/fake_cmd_obj_runner.go index b542bfee3..d06861251 100644 --- a/pkg/commands/oscommands/fake_cmd_obj_runner.go +++ b/pkg/commands/oscommands/fake_cmd_obj_runner.go @@ -21,7 +21,7 @@ type FakeCmdObjRunner struct { var _ ICmdObjRunner = &FakeCmdObjRunner{} -func NewFakeRunner(t *testing.T) *FakeCmdObjRunner { +func NewFakeRunner(t *testing.T) *FakeCmdObjRunner { //nolint:thelper return &FakeCmdObjRunner{t: t} } diff --git a/pkg/commands/oscommands/os.go b/pkg/commands/oscommands/os.go index 1c4f5bf28..f3df3956f 100644 --- a/pkg/commands/oscommands/os.go +++ b/pkg/commands/oscommands/os.go @@ -103,7 +103,7 @@ func (c *OSCommand) Quote(message string) string { // AppendLineToFile adds a new line in file func (c *OSCommand) AppendLineToFile(filename, line string) error { c.LogCommand(fmt.Sprintf("Appending '%s' to file '%s'", line, filename), false) - f, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600) + f, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0o600) if err != nil { return ut |