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

go1.22 support #4273

Closed
ldez opened this issue Dec 19, 2023 · 10 comments
Closed

go1.22 support #4273

ldez opened this issue Dec 19, 2023 · 10 comments
Labels
enhancement New feature or improvement

Comments

@ldez
Copy link
Member

ldez commented Dec 19, 2023

EDIT: since v1.56.0 golangci supports go1.22 🎉


Is golangci-lint support go1.22?

No, and yes.

Basically, golangci-lint supports Go versions lower or equal to the Go version used to build it.

Go version (build) Supported Go versions (code) Not supported Go versions (code)
go1.21 <= go1.21 (go1.21, go1.20, etc.) > go1.21 (go1.22, go1.23, etc.)
go1.20 <= go1.20 (go1.20, go1.19, etc.) > go1.20 (go1.21, go1.22, etc.)

The current binaries from the releases page and the Docker images have been built with go1.21 and will be built with go1.21 as long as go1.22 is not GA.
So those binaries/images don't support go1.22 (new elements and internal Go changes).

https://golangci-lint.run/usage/faq/#which-go-versions-are-supported

In addition, of the Go version used to build it, some linters could need to be updated to support newer versions of Go, and internal pieces of golangci-lint could also need to be updated.

You can follow the PR #4272 to see the progress on this topic.


Sponsoring is a good way to sustain open source maintainers: sponsor me

@ldez ldez added the enhancement New feature or improvement label Dec 19, 2023
@ldez ldez mentioned this issue Dec 19, 2023
@ldez ldez pinned this issue Dec 19, 2023
@1366613
Copy link

1366613 commented Dec 26, 2023

@ldez Btw, I'm using golangci-lint with Go 1.22. Haven't seen any errors so far.

@ldez
Copy link
Member Author

ldez commented Dec 26, 2023

If you are not using any specific Go1.22 elements, yes it may work but we don't provide support on versions of golangci-lint, that are not compiled with go1.22, used with go1.22 code, because the behavior will depend on the code to analyze.

@skaji
Copy link

skaji commented Feb 8, 2024

@ldez Thank you for supporting go1.22!

It seems that golangci-lint 1.56.0 detects loopclosure error even when the golang version is 1.22.
Should we manually disable loopclosure in .golangci.yml?

module playground

go 1.22.0
package main

import (
	"fmt"
	"sync"
)

func main() {
	var wg sync.WaitGroup
	wg.Add(5)
	for i := 0; i < 5; i++ {
		go func() {
			defer wg.Done()
			fmt.Println(i)
		}()
	}
	wg.Wait()
}
go version
go version go1.22.0 darwin/arm64golangci-lint version
golangci-lint has version 1.56.0 built with go1.22.0 from 1a00b409 on 2024-02-07T14:39:45Zgolangci-lint run
main.go:14:16: loopclosure: loop variable i captured by func literal (govet)
			fmt.Println(i)
			            ^

I think the loopclosure checker itself is designed not to detect loopclosure as invalid in Go 1.22.
golang/tools@cd62b43

@ldez
Copy link
Member Author

ldez commented Feb 8, 2024

Hello,

this rule can be disabled:

linters-settings:
  govet:
    disable:
      - loopclosure

I will see if I can improve the default behavior.

@ldez
Copy link
Member Author

ldez commented Feb 8, 2024

A new version is available: https://github.com/golangci/golangci-lint/releases/tag/v1.56.1

@EldarKurbanov
Copy link

EldarKurbanov commented Feb 9, 2024

I think, we need to disable this "loopclosure" check in paralleltest too:

(deck@steamdeck telerix)$ ~/go/bin/golangci-lint run
common/pack_test.go:69:2: Range statement for test TestAddEventToHandlerInputs does not reinitialise the variable testCase (paralleltest)
        for _, testCase := range testCases {

@ldez
Copy link
Member Author

ldez commented Feb 9, 2024

paralleltest is not inside the default linters, and the false positive report is only one of the reports of the linter.
The linter should evolve to handle that.
kunwardeep/paralleltest#34

Before the modification of the linter itself, you can add the following configuration to ignore this report:

issues:
  exclude-rules:
    - text: Range statement for test TestName does not reinitialise the variable test
      linters:
        - paralleltest

@changkun
Copy link

changkun commented Feb 13, 2024

Hi @ldez, is GOEXPERIMENT=rangefunc supported by 1.56 release already?

I got some of the following errors when checking code with GOEXPERIMENT=rangefunc enabled:

ERRO [runner] Panic: S1029: package "location" (isInitialPkg: true, needAnalyzeSource: true): interface conversion: interface {} is nil, not *buildir.IR: goroutine 18565 [running]:
runtime/debug.Stack()
        runtime/debug/stack.go:24 +0x64
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1()
        github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:108 +0x214
panic({0x1013d3a60?, 0x14008aae240?})
        runtime/panic.go:770 +0x124
honnef.co/go/tools/internal/sharedcheck.CheckRangeStringRunes(0x14001884f70)
        honnef.co/go/tools@v0.4.6/internal/sharedcheck/lint.go:25 +0x17c
honnef.co/go/tools/simple.CheckRangeStringRunes(0x1013bd480?)
        honnef.co/go/tools@v0.4.6/simple/lint.go:1650 +0x1c
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0x1400253c0d0)
        github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:190 +0x8c4
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2()
        github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:112 +0x20
github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0x14001525090, {0x101052a8d, 0x5}, 0x14001b7d730)
        github.com/golangci/golangci-lint/pkg/timeutils/stopwatch.go:111 +0x44
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0x1400df76320?)
        github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:111 +0x78
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0x1400253c0d0)
        github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_loadingpackage.go:80 +0xb0
created by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze in goroutine 397
        github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_loadingpackage.go:75 +0x184

ERRO Running error: can't run linter goanalysis_metalinter
goanalysis_metalinter: S1029: package "location" (isInitialPkg: true, needAnalyzeSource: true): interface conversion: interface {} is nil, not *buildir.IR 
make: *** [lint] Error 3

@ldez
Copy link
Member Author

ldez commented Feb 13, 2024

Hi @changkun,
can you open a dedicated issue? thank you.

dominikh/go-tools#1494

@ldez ldez unpinned this issue Feb 13, 2024
@ldez
Copy link
Member Author

ldez commented Feb 13, 2024

I will close this issue as the global support of go1.22 is now done, if you have problems please consider opening a dedicated issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement
Projects
None yet
Development

No branches or pull requests

5 participants