diff --git a/Makefile b/Makefile index 5132211298c..38dc118cb82 100644 --- a/Makefile +++ b/Makefile @@ -34,11 +34,9 @@ test: unit-test integration-test-all generate: go generate ./... -# If you execute `gofumpt -l -w .`, it will format all Go files in the current directory, including `test/_results/*` files. -# We pass only Git-tracked Go files to gofumpt because we don't want to format the test results or get errors from it. .PHONY: format format: - git ls-files '*.go' ':!vendor' | xargs gofumpt -l -w + gofumpt -l -w . .PHONY: lint lint: diff --git a/go.mod b/go.mod index a425a279731..81f7d8df325 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,9 @@ module github.com/jesseduffield/lazygit go 1.25.0 +// This is necessary to ignore test files when executing gofumpt. +ignore ./test + require ( dario.cat/mergo v1.0.1 github.com/adrg/xdg v0.4.0 diff --git a/pkg/commands/oscommands/copy.go b/pkg/commands/oscommands/copy.go index c6d83e23b00..2df96d05729 100644 --- a/pkg/commands/oscommands/copy.go +++ b/pkg/commands/oscommands/copy.go @@ -35,16 +35,16 @@ import ( // destination file exists, all it's contents will be replaced by the contents // of the source file. The file mode will be copied from the source and // the copied data is synced/flushed to stable storage. -func CopyFile(src, dst string) (err error) { +func CopyFile(src, dst string) error { in, err := os.Open(src) if err != nil { - return //nolint: nakedret + return err } defer in.Close() out, err := os.Create(dst) if err != nil { - return //nolint: nakedret + return err } defer func() { if e := out.Close(); e != nil { @@ -54,30 +54,30 @@ func CopyFile(src, dst string) (err error) { _, err = io.Copy(out, in) if err != nil { - return //nolint: nakedret + return err } err = out.Sync() if err != nil { - return //nolint: nakedret + return err } si, err := os.Stat(src) if err != nil { - return //nolint: nakedret + return err } err = os.Chmod(dst, si.Mode()) if err != nil { - return //nolint: nakedret + return err } - return //nolint: nakedret + return err } // CopyDir recursively copies a directory tree, attempting to preserve permissions. // Source directory must exist. If destination already exists we'll clobber it. // Symlinks are ignored and skipped. -func CopyDir(src string, dst string) (err error) { +func CopyDir(src string, dst string) error { src = filepath.Clean(src) dst = filepath.Clean(dst) @@ -91,7 +91,7 @@ func CopyDir(src string, dst string) (err error) { _, err = os.Stat(dst) if err != nil && !os.IsNotExist(err) { - return //nolint: nakedret + return err } if err == nil { // it exists so let's remove it @@ -102,12 +102,12 @@ func CopyDir(src string, dst string) (err error) { err = os.MkdirAll(dst, si.Mode()) if err != nil { - return //nolint: nakedret + return err } entries, err := os.ReadDir(src) if err != nil { - return //nolint: nakedret + return err } for _, entry := range entries { @@ -117,13 +117,13 @@ func CopyDir(src string, dst string) (err error) { if entry.IsDir() { err = CopyDir(srcPath, dstPath) if err != nil { - return //nolint: nakedret + return err } } else { var info os.FileInfo info, err = entry.Info() if err != nil { - return //nolint: nakedret + return err } // Skip symlinks. @@ -133,10 +133,10 @@ func CopyDir(src string, dst string) (err error) { err = CopyFile(srcPath, dstPath) if err != nil { - return //nolint: nakedret + return err } } } - return //nolint: nakedret + return err } diff --git a/pkg/gui/presentation/branches_test.go b/pkg/gui/presentation/branches_test.go index 347802a6ee5..a73c7aa56dc 100644 --- a/pkg/gui/presentation/branches_test.go +++ b/pkg/gui/presentation/branches_test.go @@ -16,9 +16,10 @@ import ( "github.com/xo/terminfo" ) -func makeAtomic(v int32) (result atomic.Int32) { +func makeAtomic(v int32) *atomic.Int32 { + var result atomic.Int32 result.Store(v) - return //nolint: nakedret + return &result } func Test_getBranchDisplayStrings(t *testing.T) { @@ -109,7 +110,7 @@ func Test_getBranchDisplayStrings(t *testing.T) { branch: &models.Branch{ Name: "branch_name", Recency: "1m", - BehindBaseBranch: makeAtomic(2), + BehindBaseBranch: *makeAtomic(2), }, itemOperation: types.ItemOperationNone, fullDescription: false, @@ -126,7 +127,7 @@ func Test_getBranchDisplayStrings(t *testing.T) { UpstreamRemote: "origin", AheadForPull: "0", BehindForPull: "0", - BehindBaseBranch: makeAtomic(2), + BehindBaseBranch: *makeAtomic(2), }, itemOperation: types.ItemOperationNone, fullDescription: false, @@ -143,7 +144,7 @@ func Test_getBranchDisplayStrings(t *testing.T) { UpstreamRemote: "origin", AheadForPull: "3", BehindForPull: "5", - BehindBaseBranch: makeAtomic(2), + BehindBaseBranch: *makeAtomic(2), }, itemOperation: types.ItemOperationNone, fullDescription: false, @@ -247,7 +248,7 @@ func Test_getBranchDisplayStrings(t *testing.T) { UpstreamRemote: "origin", AheadForPull: "3", BehindForPull: "5", - BehindBaseBranch: makeAtomic(4), + BehindBaseBranch: *makeAtomic(4), }, itemOperation: types.ItemOperationNone, fullDescription: false,