Repository: jesseduffield/lazygit (language: go)

Issue:
Upgrade to go 1.22
**Is your feature request related to a problem? Please describe.**
go 1.22 is [out](https://tip.golang.org/doc/go1.22) and notably it updates the way that loops are handled:
> Previously, the variables declared by a “for” loop were created once and updated by each iteration. In Go 1.22, each iteration of the loop creates new variables, to avoid accidental sharing bugs. The [transition support tooling](https://tip.golang.org/wiki/LoopvarExperiment#my-test-fails-with-the-change-how-can-i-debug-it) described in the proposal continues to work in the same way it did in Go 1.21.

This is a very good improvement: it means we don't need to say `x := x` on the first line of any loop in which `x` will be closed over by a function. The reason I'm raising this issue is because just now I had a bug because I forgot to add `x := x` myself!

**Describe the solution you'd like**
Let's upgrade to go 1.22 and go find all the places we're doing `x := x` in loops and delete those lines.
Upgrade to go 1.22
**Is your feature request related to a problem? Please describe.**
go 1.22 is [out](https://tip.golang.org/doc/go1.22) and notably it updates the way that loops are handled:
> Previously, the variables declared by a “for” loop were created once and updated by each iteration. In Go 1.22, each iteration of the loop creates new variables, to avoid accidental sharing bugs. The [transition support tooling](https://tip.golang.org/wiki/LoopvarExperiment#my-test-fails-with-the-change-how-can-i-debug-it) described in the proposal continues to work in the same way it did in Go 1.21.

This is a very good improvement: it means we don't need to say `x := x` on the first line of any loop in which `x` will be closed over by a function. The reason I'm raising this issue is because just now I had a bug because I forgot to add `x := x` myself!

**Describe the solution you'd like**
Let's upgrade to go 1.22 and go find all the places we're doing `x := x` in loops and delete those lines.


Discussion / hints:
As you may already know, by using a linter called [`copyloopvar`](https://github.com/karamaru-alpha/copyloopvar), you can detect unnecessary assignments. Once the update to Go 1.22 is complete, enabling this linter would reduce the effort of having to point out these issues during PR reviews.

To enable `copyloopvar`:

```diff
diff --git a/.golangci.yml b/.golangci.yml
index 85a95650..5b7c5e32 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -14,6 +14,7 @@ linters:
     - exhaustive
     - makezero
     - nakedret
+    - copyloopvar
     # - goconst # TODO: enable and fix issues
   fast: false
```

For example, if there was unnecessary assignment, output is like this:

```sh
$ golangci-lint run -c ./.golangci.yml  ./...
pkg/app/app.go:161:3: The copy of the 'for' variable "repoDir" can be deleted (Go 1.22+) (copyloopvar)
                repoDir := repoDir
                ^
```
Ah nice! Would you be up to raising a PR for that @kyu08 ?
Sure! I'd be happy to do that. 👍 
Awesome, thanks
As you may already know, by using a linter called [`copyloopvar`](https://github.com/karamaru-alpha/copyloopvar), you can detect unnecessary assignments. Once the update to Go 1.22 is complete, enabling this linter would reduce the effort of having to point out these issues during PR reviews.

To enable `copyloopvar`:

```diff
diff --git a/.golangci.yml b/.golangci.yml
index 85a95650..5b7c5e32 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -14,6 +14,7 @@ linters:
     - exhaustive
     - makezero
     - nakedret
+    - copyloopvar
     # - goconst # TODO: enable and fix issues
   fast: false
```

For example, if there was unnecessary assignment, output is like this:

```sh
$ golangci-lint run -c ./.golangci.yml  ./...
pkg/app/app.go:161:3: The copy of the 'for' variable "repoDir" can be deleted (Go 1.22+) (copyloopvar)
                repoDir := repoDir
                ^
```
Ah nice! Would you be up to raising a PR for that @kyu08 ?
Sure! I'd be happy to do that. 👍 
Awesome, thanks

Fix patch:
diff --git a/.golangci.yml b/.golangci.yml
index 85a956508ff..169150a5715 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -14,10 +14,16 @@ linters:
     - exhaustive
     - makezero
     - nakedret
+    - copyloopvar
     # - goconst # TODO: enable and fix issues
   fast: false
 
 linters-settings:
+  copyloopvar:
+    # Check all assigning the loop variable to another variable.
+    # Default: false
+    # If true, an assignment like `a := x` will be detected as an error.
+    check-alias: true
   exhaustive:
     default-signifies-exhaustive: true
   staticcheck:


Test patch: