Skip to content

Typecheck linter only working despite all others being disabled and a non-typechek linter specified #5191

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

Closed
6 of 7 tasks
huornlmj opened this issue Dec 5, 2024 · 6 comments
Labels
question Further information is requested

Comments

@huornlmj
Copy link

huornlmj commented Dec 5, 2024

Welcome

  • Yes, I'm using a binary release within 2 latest releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've read the typecheck section of the FAQ.
  • Yes, I've tried with the standalone linter if available (e.g., gocritic, go vet, etc.).
  • I agree to follow this project's Code of Conduct

Description of the problem

In multiple Go code repositories I run the following command:

$ golangci-lint run --disable-all -E cyclop

Expecting to disable all linters except cyclop. However the only results that are returned are all (typecheck). This happens if I change from cyclop to gosec or to any other linter.

Version of golangci-lint

$ golangci-lint version
golangci-lint has version 1.62.2 built with go1.23.3 from 89476e7a on 2024-11-25T14:16:01Z

Configuration

N/A- using the --no-config switch.

Go environment

$ go version && go env
go version go1.18.1 linux/amd64
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/user/.cache/go-build'
GOENV='/home/user/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/user/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/user/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go-1.18'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLDIR='/usr/lib/go-1.18/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.18.1'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/user/REDACTED/go.mod'
GOWORK=''
CGO_CFLAGS='-g -O2'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-g -O2'
CGO_FFLAGS='-g -O2'
CGO_LDFLAGS='-g -O2'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1076588450=/tmp/go-build -gno-record-gcc-switches'

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v
INFO golangci-lint has version 1.62.2 built with go1.23.3 from 89476e7a on 2024-11-25T14:16:01Z
INFO [config_reader] Config search paths: [./ //home/user/REDACTED /home/user/REDACTED/edge /home/user/REDACTED /home/user/source /home/user /home /]
INFO [config_reader] Used config file .golangci.yml
INFO [lintersdb] Active 14 linters: [bodyclose dupl errcheck gofmt gosec gosimple govet ineffassign misspell nilerr staticcheck unconvert unparam unused]
INFO [loader] Go packages loading at mode 8767 (imports|name|types_sizes|deps|files|compiled_files|exports_file) took 1.114102842s
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 8.106411ms
INFO [linters_context/goanalysis] analyzers took 14.278241068s with top 10 stages: buildir: 10.55132076s, inspect: 652.884735ms, fact_deprecated: 507.377865ms, ctrlflow: 362.757208ms, printf: 289.488978ms, fact_purity: 202.279602ms, nilness: 186.727009ms, SA5012: 159.573807ms, typedness: 125.17243ms, tokenfileanalyzer: 101.74781ms
INFO [runner] Issues before processing: 3960, after processing: 22
INFO [runner] Processors filtering stat (in/out): invalid_issue: 3960/3960, path_prettifier: 3960/3960, identifier_marker: 3960/3960, max_same_issues: 22/22, source_code: 22/22, path_prefixer: 22/22, cgo: 3960/3960, filename_unadjuster: 3960/3960, sort_results: 22/22, diff: 22/22, max_per_file_from_linter: 22/22, exclude: 3960/3960, exclude-rules: 3960/3960, fixer: 22/22, skip_files: 3960/3960, nolint: 3960/3960, uniq_by_line: 3960/22, max_from_linter: 22/22, path_shortener: 22/22, severity-rules: 22/22, skip_dirs: 3960/3960, autogenerated_exclude: 3960/3960
INFO [runner] processing took 125.382878ms with stages: identifier_marker: 119.595008ms, path_prettifier: 3.79551ms, nolint: 250.082µs, exclude-rules: 240.259µs, invalid_issue: 239.674µs, uniq_by_line: 230.311µs, skip_dirs: 228.345µs, cgo: 217.058µs, filename_unadjuster: 214.294µs, autogenerated_exclude: 209.86µs, source_code: 133.686µs, max_same_issues: 13.54µs, path_shortener: 6.461µs, max_from_linter: 3.559µs, max_per_file_from_linter: 3.038µs, diff: 462ns, fixer: 432ns, skip_files: 322ns, sort_results: 312ns, exclude: 271ns, path_prefixer: 205ns, severity-rules: 189ns
INFO [runner] linters took 5.580861626s with stages: goanalysis_metalinter: 5.455032745s
REDACTED strings.CutPrefix (typecheck)
        releaseServiceUrls, _ := strings.CutPrefix(urisValue, "URIs:")
                                         ^
REDACTED o.Execute undefined (type REDACTED has no field or method REDACTED) (typecheck)
        REDACTED
                    ^
REDACTED o.SetMetaUpdateInProgress undefined (type REDACTED has no field or method REDACTED) (typecheck)
        REDACTED
                    ^
REDACTED o.Execute undefined (type REDACTED has no field or method Execute) (typecheck)
        REDACTED
                       ^
REDACTED o.SetMetaUpdateInProgress undefined (type REDACTED has no field or method REDACTED) (typecheck)
        REDACTED
                    ^
REDACTED o.Execute undefined (type REDACTED has no field or method REDACTED) (typecheck)
        REDACTED
                    ^
REDACTED k.GetMetaUpdateSource undefined (type REDACTED has no field or method REDACTED) (typecheck)
        REDACTED
                                       ^
REDACTED k.Execute undefined (type REDACTED has no field or method REDACTED) (typecheck)
        REDACTED
                      ^
REDACTED p.GetMetaUpdateSource undefined (type REDACTED has no field or method REDACTED) (typecheck)
        REDACTED
                               ^
REDACTED p.IsDeprecatedFormat undefined (type REDACTED has no field or method REDACTED) (typecheck)
        REDACTED
                          ^
REDACTED p.ConfigureDeprecatedCustomAptRepos undefined (type REDACTED has no field or method REDACTED) (typecheck)
                REDACTED
                        ^
REDACTED p.UpdatePackages undefined (type REDACTED has no field or method REDACTED) (typecheck)
                REDACTED
                         ^
REDACTED p.CleanupCustomRepos undefined (type REDACTED has no field or method REDACTED) (typecheck)
        REDACTED
                ^
REDACTED p.ConfigureForwardProxy undefined (type REDACTED has no field or method REDACTED) (typecheck)
        REDACTED
                ^
REDACTED p.ConfigureCustomAptRepos undefined (type REDACTED has no field or method REDACTED) (typecheck)
        REDACTED
                ^
REDACTED p.UpdatePackages undefined (type REDACTED has no field or method REDACTED) (typecheck)
        REDACTED
                 ^
REDACTED s.SetMetaUpdateInProgress undefined (type REDACTED has no field or method REDACTED) (typecheck)
        REDACTED
                 ^
REDACTED s.Execute undefined (type REDACTED has no field or method REDACTED) (typecheck)
        REDACTED
                      ^
REDACTED i.SetMetaUpdateInProgress undefined (type REDACTED has no field or method REDACTED) (typecheck)
        REDACTED
                    ^
REDACTED i.GetInstallPackageList undefined (type REDACTED has no field or method REDACTED) (typecheck)
        REDACTED
                           ^
REDACTED e.GetMetaUpdateTime undefined (type REDACTED has no field or method REDACTED) (typecheck)
        REDACTED
                                  ^
REDACTED e.GetMetaUpdateDuration undefined (type REDACTED has no field or method REDACTED) (typecheck)
        REDACTED
                                 ^
INFO File cache stats: 3 entries of total size 25.3KiB
INFO Memory: 69 samples, avg is 300.5MB, max is 472.6MB
INFO Execution took 6.712384384s

A minimal reproducible example or link to a public repository

Not possible to share.

Validation

  • Yes, I've included all information above (version, config, etc.).

Supporter

@huornlmj huornlmj added the bug Something isn't working label Dec 5, 2024
@ldez ldez added question Further information is requested and removed bug Something isn't working labels Dec 5, 2024
@ldez
Copy link
Member

ldez commented Dec 5, 2024

Hello,

I recommend reading:

And providing a reproducible example.

FYI, typecheck is not linter but you already know that #3928

@ldez
Copy link
Member

ldez commented Dec 5, 2024

go version go1.18.1 linux/amd64

This is because you are using go1.18.

strings.CutPrefix has been introduced in go1.20: https://pkg.go.dev/strings#CutPrefix

$ go version       
go version go1.18.10 linux/amd64
$ golangci-lint version
golangci-lint has version 1.62.2 built with go1.23.3 from 89476e7a on 2024-11-25T14:16:01Z
$ golangci-lint run
foo.go:6:10: undefined: strings.CutPrefix (typecheck)
        strings.CutPrefix("", "")
                ^
go.mod
module github.com/golangci/sandbox

go 1.18
foo.go
package sandbox

import "strings"

func Foo() {
	strings.CutPrefix("", "")
}

Golangci-lint follows the same Go version policy than the Go team: https://golangci-lint.run/welcome/faq/#which-go-versions-are-supported

@ldez ldez closed this as completed Dec 5, 2024
@huornlmj
Copy link
Author

huornlmj commented Dec 5, 2024

Hi , please reopen this as it's still not answered. Thanks for un-earthing my old copy, the same problem is there, also unanswered. My issue is, why is golangci-lint insisting on only using the typecheck linter even though I'm specifically telling it not to? I don't care about typecheck. It seems unable to use the linter I'm asking it to use.

@bombsimon
Copy link
Member

bombsimon commented Dec 5, 2024

why is golangci-lint insisting on only using the typecheck linter even though I'm specifically telling it not to?

typecheck isn't a linter, it's a way of reporting compilation (and some other) issues in the same report framework as the linters does. It will be printed to the screen the same way and it will have the (typecheck) parenthesis like a linter, but it's not a linter.

You can see this as an API that returns users and their names in a key value format:

{
  "user1": "John Doe",
  "user2": "Jane Doe"
}

And if that API fails, it will use the same format:

{
  "error": "Something went wrong"
}

This doesn't mean that there's a user named "error" and you can't ask to skip the user with username "error". You also can't expect "user1" and "user2" to be returned because the API simply failed to resolve the usernames.

From the docs linked by @ldez:

typecheck is like a front-end for the Go compiler errors. Compilation errors are identified/labeled as reports of typecheck but they are not produced by a linter called typecheck.

typecheck is not a linter, it doesn't perform any analysis, it's just a way to identify, parse, and display compiling errors

The docs continue with a list of things to try to help troubleshoot why this happens.

So if the code fails to build in a way that is required for golangci-lint to work, we will report a best effort error reporting in the same framework as linters does, but it's not a linter.

Because of this, it's not possible to ever suppress reports labeled as typecheck. This also means that any other linter is never guaranteed to run or report issues if there are typecheck reports. It's like trying build any Go code that doesn't compile and hope for a binary that "kinda" works which will never happen.

What the docs and the above post is answer is how to figure out why your linter isn't running and why instead typecheck is being printed on your screen. A lot of times the easiest thing to figure out is to just run go build ./... since it's very common it will fail due to the same reason. Of course this is not always the case, hence the checklist and extensive docs linked above. There are other parameters involved such as which Go version goalngci-lint was built with to name one of them.

@ccoVeille
Copy link
Contributor

I think that I see @ldez lose his mental health by keep replying to questions about "typecheck issues".

658 so far
https://github.com/search?q=repo%3Agolangci%2Fgolangci-lint+typecheck&type=issues

The documentation is great. It can help to spot your issue.

The reply made by @bombsimon is great.

I'm a random Gopher, I actively follow what happen in this repository (and others) because I love golangci-lint. But even me is annoyed by the amount of messages/issues about typecheck.

I wish maintainers could have more interesting to do than keep replying about "typecheck issues"

For me,

if you have typecheck issues reported by golangci-lint, it means you have issues with your code, and golangci-lint cannot help you. The same way a doctor cannot apply a bandage on a wooden leg.

This sentence could be added in h1 on golangci-lint homepage and issue template, I think they will keep coming.

Please note, there is nothing wrong with you, or in reporting something issues, but please understand maintainers did their best to educate developers about what typecheck issues.

@ldez
Copy link
Member

ldez commented Dec 5, 2024

I think this issue is about 3 elements:

  • confusion between typecheck and a linter
  • confusion between the "label" typecheck and type-checking
  • the misunderstanding of the requirement of a linter

The label typecheck is used to flag errors related to syntax problems, linter unexpected errors, and type-checking errors, but it's not limited to pure type-checking.

But in the context of this issue, the report is related to type-checking because currently cyclop (like gosec) requires types.
If you run a linter that does not require types then this specific typecheck labeled report will not be produced.

For example, with the same previous code:

$ golangci-lint run --enable-only cyclop --show-stats
foo.go:6:10: undefined: strings.CutPrefix (typecheck)
        strings.CutPrefix("", "")
                ^
1 issues:
* typecheck: 1

$ golangci-lint run --enable-only wsl --show-stats
0 issues.

The linters that do not depend on types are flagged as "fast".

$ golangci-lint linters | grep "^[a-z0-9]*:" | grep "fast: true" | sed 's/:/ /g' | awk '{print $1}' | sort
asciicheck
bidichk
copyloopvar
decorder
depguard
dogsled
dupl
dupword
forcetypeassert
funlen
gci
gocheckcompilerdirectives
gochecknoinits
gocognit
goconst
gocyclo
godot
godox
gofmt
gofumpt
goheader
goimports
gomoddirectives
gomodguard
goprintffuncname
grouper
inamedparam
ineffassign
interfacebloat
lll
maintidx
misspell
mnd
nakedret
nestif
nlreturn
nolintlint
nosprintfhostport
prealloc
predeclared
promlinter
tagalign
tagliatelle
testableexamples
testpackage
usestdlibvars
whitespace
wsl

cyclop is not on this list.

@ldez ldez changed the title Typecheck linter only working despite all others being disabled and a non-typehcek linter specified Typecheck linter only working despite all others being disabled and a non-typechek linter specified Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants