-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Since the version v1.45.0 golangci-lint supports go1.18.
But some linters don't work with generics, golangci-lint disable those linters automatically with go1.18.
Since v1.45.1, golangci-lint can detect the Go version used by a project.
To get the Go version golangci-lint will use, in order:
- the Go version defined by the CLI flag, ex:
--go=1.18 - the Go version defined in the configuration file, ex:
run: go: '1.18'
- the Go version defined in the
go.mod, ex;module github.com/org/my-project go 1.18
- Go version defined by the env var
GOVERSION - fallback on go1.17.
Notes:
- some rules in go-critic (
externalErrorReassign) don't work with generics and must be disabled by hand - if you are not using generics (and your dependencies) you can use the following configuration:
run: go: '1.17'
The keyword any works well and produces no error (it's expected because it's just a type alias)
The problem with SSA is now fixed but some linters need to update their code base to handle generics.
About the linters:
- for
go-critic, there is an existing issue Support generics for Go 1.18 go-critic/go-critic#1193
Linter issues: (checked if the problems are solved)
- govet(nilness,unusedwrite)
- staticcheck, stylecheck, gosimple, unused
- bodyclose
- contextcheck
- nilerr
- noctx
- rowserrcheck
- sqlclosecheck
- tparallel
- wastedassign
- unparam
-
struccheck: Deprecated - go-critic(externalErrorReassign)
The binary compiled with go1.17 doesn't work when running on go1.18:
$ golangci-lint run
panic: load embedded ruleguard rules: rules/rules.go:13: can't load fmt
goroutine 1 [running]:
github.com/go-critic/go-critic/checkers.init.22()
github.com/go-critic/go-critic@v0.6.2/checkers/embedded_rules.go:46 +0x4b4
Compatibility table
🟢️: means that the linter seems to work, but it's not 100% sure, it needs to be tested on more go1.18 code.
🟠: means that the linter works partially.
🔴: means that the linter panic.
The current state:
| Linter | State | Problem |
|---|---|---|
| asciicheck | 🟢️ | |
| bidichk | 🟢️ | |
| bodyclose | 🟢️ | |
| containedctx | 🟢️ | |
| contextcheck | 🟢️ | |
| cyclop | 🟢️ | |
| deadcode | 🟢️ | |
| decorder | 🟢️ | |
| depguard | 🟢️ | |
| dogsled | 🟢️ | |
| dupl | 🟢️ | |
| durationcheck | 🟢️ | |
| errcheck | 🟢️ | |
| errchkjson | 🟢️ | |
| errname | 🟢️ | |
| errname | 🟢️ | |
| errorlint | 🟢️ | |
| exhaustive | 🟢️ | |
| exhaustivestruct | 🟢️ | |
| exportloopref | 🟢️ | |
| forbidigo | 🟢️ | |
| forcetypeassert | 🟢️ | |
| funlen | 🟢️ | |
| gci | 🟢️ | |
| gochecknoglobals | 🟢️ | |
| gochecknoinits | 🟢️ | |
| gocognit | 🟢️ | |
| goconst | 🟢️ | |
| gocritic | 🟠 | type assertion |
| gocyclo | 🟢️ | |
| godot | 🟢️ | |
| godox | 🟢️ | |
| goerr113 | 🟢️ | |
| gofmt | 🟢️ | |
| gofumpt | 🟢️ | |
| goheader | 🟢️ | |
| goimports | 🟢️ | |
| gomnd | 🟢️ | |
| gomoddirectives | 🟢️ | |
| gomodguard | 🟢️ | |
| goprintffuncname | 🟢️ | |
| gosec | 🟢️ | |
| gosimple | 🟢️ | |
| govet | 🟢️ | |
| grouper | 🟢️ | |
| ifshort | 🟢️ | |
| importas | 🟢️ | |
| ineffassign | 🟢️ | |
| ireturn | 🟢️ | |
| lll | 🟢️ | |
| maintidx | 🟢️ | |
| makezero | 🟢️ | |
| misspell | 🟢️ | |
| nakedret | 🟢️ | |
| nestif | 🟢️ | |
| nilerr | 🟢️ | |
| nilnil | 🟢️ | |
| nlreturn | 🟢️ | |
| noctx | 🟢️ | |
| nolintlint | 🟢️ | |
| paralleltest | 🟢️ | |
| prealloc | 🟢️ | |
| predeclared | 🟢️ | |
| promlinter | 🟢️ | |
| revive | 🟢️ | |
| rowserrcheck | 🟠 | some elements are not detected |
| sqlclosecheck | 🟠 | some elements are not detected |
| staticcheck | 🟢️ | |
| structcheck | 🟠 | false positives |
| stylecheck | 🟢️ | |
| tagliatelle | 🟢️ | |
| tenv | 🟢️ | |
| testpackage | 🟢️ | |
| thelper | 🟢️ | |
| tparallel | 🟢️ | |
| typecheck | 🟢️ | |
| unconvert | 🟢️ | |
| unparam | 🟢️ | |
| unused | 🟢️ | |
| varcheck | 🟢️ | |
| varnamelen | 🟢️ | |
| wastedassign | 🟠 | some elements are not detected |
| whitespace | 🟢️ | |
| wrapcheck | 🟢️ | |
| wsl | 🟢️ |
golangci-lint is a free and open-source project, built by people in their free time.
Also, the linter authors are an important part of golangci-lint.
If you use and appreciate golangci-lint please think to support us (golangci-lint maintainers and linters authors). ❤️