golangci / golangci-lint

Fast linters runner for Go
https://golangci-lint.run
GNU General Public License v3.0
15.45k stars 1.38k forks source link

macOS golangci-lint typecheck doesn't seem to understand some generics #3891

Closed aspin closed 6 months ago

aspin commented 1 year ago

Welcome

Description of the problem

On macOS, golangci-lint seems to not understand some part of generics (I think?). This same errors do not appear on an installation of golangci-lint that's run in CI, and the code compiles and runs without issue.

On closer inspection, the other errors raised here also make extremely little sense (unused imports, variables, etc.).

I can copy one file here:

import (
    "context"
    proto "github.com/bloXroute-Labs/bxproto-private/go/solana-geyser-broadcast/v1"
    "github.com/bloXroute-Labs/solana-trader-api/event"
    "github.com/bloXroute-Labs/solana-trader-api/trace"
    "github.com/gagliardetto/solana-go"
    solanarpc "github.com/gagliardetto/solana-go/rpc"
)

type StreamClient interface {
    SetRegisteredAccounts(accountPks []solana.PublicKey)
    RegisterAddressForTxUpdates(accountPk solana.PublicKey)

    SubscribeBlocks(ctx context.Context, blkCh chan event.FeedEvent[*proto.Block])
    SubscribeAccountUpdates(ctx context.Context, ch chan event.FeedEvent[*solanarpc.KeyedAccount])
    SubscribeTxUpdates(ctx context.Context, ch chan event.FeedEvent[*proto.TransactionSubscribeResponse])

    Connect() error
    IsHealthy() bool
    Close()
}

Yet golangci-lint:

solana/streamclient.go:5:2          typecheck  "github.com/bloXroute-Labs/bxproto-private/go/solana-geyser-broadcast/v1" imported as proto and not used
solana/streamclient.go:9:2          typecheck  "github.com/gagliardetto/solana-go/rpc" imported as solanarpc and not used

Version of golangci-lint

```console $ golangci-lint --version golangci-lint has version 1.53.2 built with go1.20.4 from 59a7aaf on 2023-06-03T10:44:21Z ```

Configuration file

```console $ cat .golangci.yml service: golangci-lint-version: 1.48.x # full list: https://golangci-lint.run/usage/linters/ linters: disable-all: true enable: - bodyclose - errcheck - gosec - gosimple - govet - ineffassign - revive - staticcheck - stylecheck - typecheck - unused # full list: https://golangci-lint.run/usage/configuration/ linters-settings: gosec: excludes: - G404 staticcheck: checks: [ "all" ] stylecheck: # ignore package comment and naming recommendations checks: [ "all", "-ST1000", "-ST1003", "-ST10016" ] run: skip-files: - ".*\\.pb\\.go$" # skip protobuf generated code output: format: tab ```

Go environment

```console $ go version && go env go version go1.20.4 darwin/arm64 GO111MODULE="" GOARCH="arm64" GOBIN="" GOCACHE="/Users/aspin/Library/Caches/go-build" GOENV="/Users/aspin/Library/Application Support/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="arm64" GOHOSTOS="darwin" GOINSECURE="" GOMODCACHE="/Users/aspin/go/pkg/mod" GONOPROXY="github.com/bloXroute-Labs" GONOSUMDB="github.com/bloXroute-Labs" GOOS="darwin" GOPATH="/Users/aspin/go" GOPRIVATE="github.com/bloXroute-Labs" GOPROXY="https://proxy.golang.org,direct" GOROOT="/opt/homebrew/Cellar/go/1.20.4/libexec" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/opt/homebrew/Cellar/go/1.20.4/libexec/pkg/tool/darwin_arm64" GOVCS="" GOVERSION="go1.20.4" GCCGO="gccgo" AR="ar" CC="cc" CXX="c++" CGO_ENABLED="1" GOMOD="/Users/aspin/workspace/sandbox/solana-trader-api/go.mod" GOWORK="" CGO_CFLAGS="-O2 -g" CGO_CPPFLAGS="" CGO_CXXFLAGS="-O2 -g" CGO_FFLAGS="-O2 -g" CGO_LDFLAGS="-O2 -g" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/2j/gphfwrxn2ks90rgn4_dgv5rh0000gn/T/go-build2335814987=/tmp/go-build -gno-record-gcc-switches -fno-common" ```

Verbose output of running

```console $ golangci-lint cache clean $ golangci-lint run -v INFO [config_reader] Config search paths: [./ /Users/aspin/workspace/sandbox/solana-trader-api /Users/aspin/workspace/sandbox /Users/aspin/workspace /Users/aspin /Users /] INFO [config_reader] Used config file .golangci.yml INFO [lintersdb] Active 11 linters: [bodyclose errcheck gosec gosimple govet ineffassign revive staticcheck stylecheck typecheck unused] INFO [loader] Go packages loading at mode 575 (types_sizes|exports_file|files|name|compiled_files|deps|imports) took 310.405417ms INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 14.245417ms INFO [linters_context/goanalysis] analyzers took 11.411757914s with top 10 stages: the_only_name: 2.583036161s, buildir: 1.039174577s, buildssa: 818.425376ms, gosec: 391.180329ms, unused: 201.256371ms, S1038: 194.982043ms, fact_deprecated: 190.13363ms, printf: 144.878237ms, errcheck: 138.26829ms, ST1020: 129.368872ms INFO [runner/max_same_issues] 2/5 issues with text "\"github.com/bloXroute-Labs/bxproto-private/go/solana-geyser-broadcast/v1\" imported as proto and not used" were hidden, use --max-same-issues INFO [runner] Issues before processing: 3003, after processing: 14 INFO [runner] Processors filtering stat (out/in): path_prefixer: 14/14, skip_files: 3003/3003, nolint: 2645/2666, max_per_file_from_linter: 16/16, fixer: 14/14, sort_results: 14/14, cgo: 3003/3003, path_prettifier: 3003/3003, autogenerated_exclude: 3003/3003, uniq_by_line: 16/2645, source_code: 14/14, path_shortener: 14/14, max_same_issues: 14/16, max_from_linter: 14/14, filename_unadjuster: 3003/3003, skip_dirs: 3003/3003, identifier_marker: 3003/3003, exclude: 3003/3003, exclude-rules: 2666/3003, diff: 16/16, severity-rules: 14/14 INFO [runner] processing took 118.146507ms with stages: exclude-rules: 73.428251ms, identifier_marker: 36.915459ms, nolint: 2.546376ms, path_prettifier: 1.530709ms, skip_files: 1.453209ms, autogenerated_exclude: 676.25µs, cgo: 615.208µs, filename_unadjuster: 564.583µs, skip_dirs: 218.917µs, source_code: 120.167µs, uniq_by_line: 43.583µs, max_same_issues: 27.417µs, path_shortener: 2.626µs, max_per_file_from_linter: 1.417µs, max_from_linter: 833ns, sort_results: 376ns, exclude: 292ns, fixer: 250ns, diff: 209ns, severity-rules: 208ns, path_prefixer: 167ns INFO [runner] linters took 3.371179583s with stages: goanalysis_metalinter: 3.252931542s solana/streamclient.go:5:2 typecheck "github.com/bloXroute-Labs/bxproto-private/go/solana-geyser-broadcast/v1" imported as proto and not used solana/streamclient.go:9:2 typecheck "github.com/gagliardetto/solana-go/rpc" imported as solanarpc and not used rpc/solana.go:7:2 typecheck "github.com/bloXroute-Labs/bxproto-private/go/solana-geyser-broadcast/v1" imported as proto and not used cmd/external/geyser/main.go:11:2 typecheck "github.com/bloXroute-Labs/bxproto-private/go/solana-geyser-broadcast/v1" imported as proto and not used cmd/external/geyser/main.go:18:2 typecheck "github.com/gagliardetto/solana-go/rpc" imported as solanarpc and not used service/accounts_manager.go:98:4 typecheck a.RequestAccount undefined (type *BDNAccountsManager has no field or method RequestAccount) service/accounts_manager.go:101:19 typecheck a.GetAccount undefined (type *BDNAccountsManager has no field or method GetAccount) service/feed_push.go:78:9 typecheck cannot infer R (service/feed_push.go:173:34) service/feed_push.go:86:9 typecheck cannot infer R (service/feed_push.go:182:36) service/feed_push.go:90:9 typecheck cannot infer R (service/feed_push.go:173:34) service/sdn.go:117:6 typecheck err declared and not used service/sdn.go:17:2 typecheck "reflect" imported and not used service/feed_test.go:22:2 typecheck "github.com/gagliardetto/solana-go/rpc" imported as solanarpc and not used INFO File cache stats: 8 entries of total size 47.5KiB INFO Memory: 39 samples, avg is 397.8MB, max is 506.1MB INFO Execution took 3.702809166s ```

Code example or link to a public repository

```go // not available ```
boring-cyborg[bot] commented 1 year ago

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

ldez commented 1 year ago

Hello,

I think it's related to some build tags and not to generics.

Can you try to create a minimal reproducible example (without private dependencies)?

FYI typecheck is not a real linter it's just a way to parse/display "compilation" and linters errors (linter reports are not errors).

aspin commented 1 year ago

The only build tag I have is //go:build integration for some integration test suites. Any ideas on where to look to try to reproduce this? I'm not sure how to start copying the code out. When I do so, I don't get any errors.

ldez commented 1 year ago

Any ideas on where to look to try to reproduce this? I'm not sure how to start copying the code out. When I do so, I don't get any errors.

So the problem is not related to generics but to your dependencies. I think you have some specific OS files.