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

Support of generics #2649

Closed
13 tasks done
Tracked by #24
ldez opened this issue Mar 16, 2022 · 128 comments · Fixed by treeverse/lakeFS#4663
Closed
13 tasks done
Tracked by #24

Support of generics #2649

ldez opened this issue Mar 16, 2022 · 128 comments · Fixed by treeverse/lakeFS#4663
Assignees
Labels
enhancement New feature or improvement

Comments

@ldez
Copy link
Member

ldez commented Mar 16, 2022

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

@ipfans
Copy link

ipfans commented Mar 16, 2022

I think we can pin this issue and lists all issues related to Go 1.18 support.

@ldez
Copy link
Member Author

ldez commented Mar 16, 2022

If someone want to help, you can contribute to solving this issue golang/go#48525

@vmatyus
Copy link

vmatyus commented Mar 16, 2022

In our project after go version update to 1.18, the CI detected a lot of typecheck error. It is unable to load the types from ginkgo and also detects this module as unused:

"github.com/onsi/ginkgo" imported but not used (typecheck)
. "github.com/onsi/ginkgo"
undeclared name: `Describe` (typecheck)
var _ = Describe("Authenticator Unit Tests", func() {
        ^

fho added a commit to simplesurance/goordinator that referenced this issue Mar 16, 2022
This reverts commit c8e93d2.

golangci-lint does not support 1.18 yet
(golangci/golangci-lint#2649), postpone the upgrade.
fho added a commit to simplesurance/goordinator that referenced this issue Mar 16, 2022
This reverts commit ebb720d.

golangci-lint does not support 1.18 yet
(golangci/golangci-lint#2649), postpone the upgrade.
@gucio321
Copy link

gucio321 commented Mar 16, 2022

thats strange, I'm able to build golangci-lint with go1.18 without any issues however, I'm unable to run previously installed (before update to go 1.18) rpm 🤔

$ /usr/local/bin/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

after building linter by myself:

[giu (1) ]$ cd /tmp/golangci-lint/
[golangci-lint (0) ]$ go build -o golangci-lint cmd/golangci-lint/main.go 
[golangci-lint (0) ]$ cd ~/myproject
[myproject (0) ]$ /tmp/golangci-lint/golangci-lint run ./...
[myproject (0) ]$ 

@ldez
Copy link
Member Author

ldez commented Mar 16, 2022

@gucio321 take a look at #2438

@gucio321
Copy link

@gucio321 take a look at #2438

yah I swa it, but cannot understand what's going on... what is a difference between linter from here an this build with go-build?
and how to reproduce this issue?

@ldez
Copy link
Member Author

ldez commented Mar 16, 2022

Message for everyone

I'm working to find quick solutions (proposals and implementations), I will try to send a status update tomorrow.

I do my best, stay tuned.

corhere pushed a commit to corhere/docker-cli that referenced this issue Mar 1, 2023
Remove the "deadcode", "structcheck", and "varcheck" linters, as they are
deprecated:

    WARN [runner] The linter 'deadcode' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter.  Replaced by unused.
    WARN [runner] The linter 'structcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter.  Replaced by unused.
    WARN [runner] The linter 'varcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter.  Replaced by unused.
    WARN [linters context] structcheck is disabled because of generics. You can track the evolution of the generics support by following the golangci/golangci-lint#2649.

And ignore gosec G113, which only affects gp < 1.16.14. and go < 1.17.7

    opts/opts.go:398:13: G113: Potential uncontrolled memory consumption in Rat.SetString (CVE-2022-23772) (gosec)
        cpu, ok := new(big.Rat).SetString(value)
                   ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 0dd2c18)
Signed-off-by: Cory Snider <csnider@mirantis.com>
thaJeztah added a commit to thaJeztah/containerd that referenced this issue Mar 7, 2023
Remove nolint-comments that weren't hit by linters, and remove the "structcheck"
and "varcheck" linters, as they have been deprecated:

    WARN [runner] The linter 'structcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter.  Replaced by unused.
    WARN [runner] The linter 'varcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter.  Replaced by unused.
    WARN [linters context] structcheck is disabled because of generics. You can track the evolution of the generics support by following the golangci/golangci-lint#2649.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit f9c80be)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@ldez
Copy link
Member Author

ldez commented Mar 15, 2023

All the linters are now fixed 🎉, we create a release soon ⏲️.

@MichaelSnowden
Copy link

I'm using version 1.52.2 (golangci-lint has version 1.52.2 built with go1.20.2 from da04413 on 2023-03-23T16:18:48Z), and I'm not able to use structcheck. The error message refers me to this issue.

$ golangci-lint run --no-config --disable-all -E structcheck 
WARN [runner] The linter 'structcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter. Replaced by unused. 
WARN [linters_context] structcheck is disabled because of generics. You can track the evolution of the generics support by following the https://github.com/golangci/golangci-lint/issues/2649. 
$

Is there a way to analyze and fix maligned structs using golangci-lint?

@james-d-elliott
Copy link

govet's fieldalignment analyzer should do this per the docs: https://golangci-lint.run/usage/linters/

kulti added a commit that referenced this issue May 27, 2023
Issue #2649 is closed now. Suppose it works without limitations now.
michi-covalent pushed a commit to michi-covalent/cilium that referenced this issue May 30, 2023
Switch to run golangci-lint using `make check` in CI for now, using the
golangci-lint GH action with Go 1.18 is not yet fully
supported, see golangci/golangci-lint#2649

This approach was suggested by Robin.

Signed-off-by: Tobias Klauser <tobias@cilium.io>
jsturtevant pushed a commit to jsturtevant/containerd that referenced this issue Sep 21, 2023
Remove nolint-comments that weren't hit by linters, and remove the "structcheck"
and "varcheck" linters, as they have been deprecated:

    WARN [runner] The linter 'structcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter.  Replaced by unused.
    WARN [runner] The linter 'varcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter.  Replaced by unused.
    WARN [linters context] structcheck is disabled because of generics. You can track the evolution of the generics support by following the golangci/golangci-lint#2649.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
shahzadlone added a commit to shahzadlone/defradb that referenced this issue Feb 23, 2024
- Resolves sourcenetwork#720 

- Description
  > Bumps Go versions of GitHub Action environment setups.
  > Bumps Docker image Go version.
  > Bumps and resolves Linter issues.
  > Bumps and Updates `go.mod`.

- Limitation
>  A sub-linter was disabled because it lacked support with `v1.18` of Go. Can be easily turned back on if they bump up their support (golangci/golangci-lint#2649).
>  Despite us bumping to 1.18, we internally ban the use of generics until our benchmarks are fixed.
timvaillancourt pushed a commit to slackhq/vitess that referenced this issue Mar 15, 2024
There's a bunch of deprecated linters that don't work anymore, so let's
remove them:

```
WARN [runner] The linter 'deadcode' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter.  Replaced by unused.
WARN [runner] The linter 'structcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter.  Replaced by unused.
WARN [runner] The linter 'varcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter.  Replaced by unused.
WARN [linters context] structcheck is disabled because of generics. You can track the evolution of the generics support by following the golangci/golangci-lint#2649.
```

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
timvaillancourt added a commit to slackhq/vitess that referenced this issue Mar 15, 2024
* go1.20.14

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>

* more go-version: updates

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>

* make proto w/go1.20

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>

* Fix the golangci-lint config (vitessio#11812)

There's a bunch of deprecated linters that don't work anymore, so let's
remove them:

```
WARN [runner] The linter 'deadcode' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter.  Replaced by unused.
WARN [runner] The linter 'structcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter.  Replaced by unused.
WARN [runner] The linter 'varcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter.  Replaced by unused.
WARN [linters context] structcheck is disabled because of generics. You can track the evolution of the generics support by following the golangci/golangci-lint#2649.
```

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>

* update golangci-lint to 1.50.1 (vitessio#11873)

Signed-off-by: Andres Taylor <andres@planetscale.com>

Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>

* Add timeout to golangci-lint and bump its version (vitessio#12852) (vitessio#12853)

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>

* Upgrade `release-16.0` to `go1.20.1` (vitessio#12398)

* Upgrade release-16.0 to go1.19.6

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>

* upgrade to 1.20.1

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>

* bump the golangci-lint version

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>

* Apply linter suggestions

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>

* Apply linter suggestions

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>

* fix TestTLSClientVerifyIdentity

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>

* Switch to using new Go 1.19 CRL parser (vitessio#12315)

`x509.ParseCRL` is deprecated, we should use `x509.ParseRevocationList`
instead which is new in Go 1.19.

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>

* Skip TestFuzz for now

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>

---------

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
Co-authored-by: Dirkjan Bussink <d.bussink@gmail.com>

* Remove recent golangci-lint version bump (vitessio#12909)

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>

* Fix conflict resolution

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>

* make ensure_bootstrap_version

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>

* hardcode previous release

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>

* Add comment for hardcoded previous release

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>

---------

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Co-authored-by: Dirkjan Bussink <d.bussink@gmail.com>
Co-authored-by: Andres Taylor <andres@planetscale.com>
Co-authored-by: Florent Poinsard <35779988+frouioui@users.noreply.github.com>
kiashok pushed a commit to kiashok/containerd-containerd that referenced this issue Oct 23, 2024
Remove nolint-comments that weren't hit by linters, and remove the "structcheck"
and "varcheck" linters, as they have been deprecated:

    WARN [runner] The linter 'structcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter.  Replaced by unused.
    WARN [runner] The linter 'varcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter.  Replaced by unused.
    WARN [linters context] structcheck is disabled because of generics. You can track the evolution of the generics support by following the golangci/golangci-lint#2649.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
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

Successfully merging a pull request may close this issue.