Skip to content

Support of generics #2649

@ldez

Description

@ldez

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:


Linter issues: (checked if the problems are solved)


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). ❤️

Metadata

Metadata

Assignees

Labels

enhancementNew feature or improvement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy