imported but not used (typecheck) #2863
-
Welcome
Description of the problemtypecheck linter reports false positive errors on imports for packages which have name different from the module name. Version of golangci-lint$ golangci-lint --version
# Paste output here
1.41.1 Configuration file$ cat .golangci.yml
# paste output here
linters-settings:
govet:
check-shadowing: true
golint:
min-confidence: 0
gocyclo:
min-complexity: 10
maligned:
suggest-new: true
dupl:
threshold: 100
goconst:
min-len: 2
min-occurrences: 2
depguard:
list-type: blacklist
packages:
# logging is allowed only by logutils.Log, logrus
# is allowed to use only in logutils package
- github.com/sirupsen/logrus
misspell:
locale: US
lll:
line-length: 140
goimports:
local-prefixes: github.com/golangci/golangci-lint
gocritic:
enabled-tags:
- performance
- style
- experimental
disabled-checks:
- wrapperFunc
linters:
disable-all: true
enable:
- govet
- staticcheck
- ineffassign
- misspell
run:
skip-dirs:
- test/testdata_etc
- pkg/golinters/goanalysis/(checker|passes)
issues:
exclude-rules:
- text: "weak cryptographic primitive"
linters:
- gosec
- linters:
- staticcheck
text: "SA1019:"
# golangci.com configuration
# https://github.com/golangci/golangci/wiki/Configuration
service:
golangci-lint-version: 1.15.x # use the fixed version to not introduce new linters unexpectedly
prepare:
- echo "here I can run custom commands, but no preparation needed for this repo" Go environment$ go version && go env
# paste output here
1.13
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/runner/.cache/go-build"
GOENV="/home/runner/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/runner/go"
GOPRIVATE=""
GOPROXY="[https://proxy.golang.org,direct](https://proxy.golang.org%2Cdirect/)"
GOROOT="/opt/hostedtoolcache/go/1.13.15/x64"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/hostedtoolcache/go/1.13.15/x64/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS="" Verbose output of running$ golangci-lint cache clean
$ golangci-lint run -v
# paste output here
Run golangci-lint run --timeout=10m -v
level=info msg="[config_reader] Config search paths: [./ /home/runner/work/dubbo-go/dubbo-go /home/runner/work/dubbo-go /home/runner/work /home/runner /home /]"
level=info msg="[config_reader] Used config file .golangci.yml"
level=info msg="[lintersdb] Active 4 linters: [govet ineffassign misspell staticcheck]"
level=info msg="[loader] Go packages loading at mode 575 (deps|exports_file|name|types_sizes|compiled_files|files|imports) took 2m10.555005976s"
level=info msg="[runner/filename_unadjuster] Pre-built 0 adjustments in 56.346[8](https://github.com/apache/dubbo-go/runs/6475077184?check_suite_focus=true#step:8:8)18ms"
level=info msg="[linters context/goanalysis] analyzers took 1m50.437648188s with top 10 stages: buildir: 1m31.46[9](https://github.com/apache/dubbo-go/runs/6475077184?check_suite_focus=true#step:8:9)77433s, nilness: 7.131271175s, inspect: 2.552770752s, fact_deprecated: 1.464938398s, ctrlflow: 1.464382999s, printf: 1.128907497s, fact_purity: 987.689019ms, typedness: 947.686229ms, SA5012: 634.748186ms, misspell: 317.228465ms"
level=info msg="[runner/skip dirs] Skipped 15 issues from dir protocol/grpc/protoc-gen-dubbo/examples by pattern (^|/)examples($|/)"
Error: remoting/etcdv3/listener.go:[10](https://github.com/apache/dubbo-go/runs/6475077184?check_suite_focus=true#step:8:10)1:45: undeclared name: `clientv3` (typecheck)
level=info msg="[runner] Issues before processing: 238, after processing: 2"
level=info msg="[runner] Processors filtering stat (out/in): max_from_linter: 2/2, sort_results: 2/2, autogenerated_exclude: 208/223, exclude-rules: 199/208, max_per_file_from_linter: 2/2, path_prefixer: 2/2, skip_dirs: 223/238, nolint: 198/199, uniq_by_line: 2/198, diff: 2/2, source_code: 2/2, path_shortener: 2/2, path_prettifier: 238/238, skip_files: 238/238, identifier_marker: 208/208, exclude: 208/208, max_same_issues: 2/2, severity-rules: 2/2, cgo: 238/238, filename_unadjuster: 238/238"
level=info msg="[runner] processing took 15.32565ms with stages: exclude-rules: 7.847936ms, identifier_marker: 4.545552ms, nolint: 1.8004ms, path_prettifier: 413.823µs, autogenerated_exclude: 313.817µs, skip_dirs: 227.8[12](https://github.com/apache/dubbo-go/runs/6475077184?check_suite_focus=true#step:8:12)µs, filename_unadjuster: 54.403µs, source_code: 47.303µs, cgo: 46.003µs, uniq_by_line: 15.901µs, max_same_issues: 4.3µs, max_per_file_from_linter: 2.2µs, path_shortener: 2.1µs, max_from_linter: 1.9µs, exclude: 600ns, diff: 500ns, skip_files: 400ns, severity-rules: 300ns, sort_results: 300ns, path_prefixer: 100ns"
level=info msg="[runner] linters took 1m5.429969576s with stages: goanalysis_metalinter: 1m5.4[14](https://github.com/apache/dubbo-go/runs/6475077184?check_suite_focus=true#step:8:14)485817s"
level=info msg="File cache stats: 506 entries of total size 2.0MiB"
level=info msg="Memory: 1962 samples, avg is 396.8MB, max is 1491.6MB"
func (l *EventListener) handleEvents(event *clientv3.Event, listeners ...remoting.DataListener) bool {
^
level=info msg="Execution took 3m16.059640818s"
Error: remoting/etcdv3/listener.go:31:2: "go.etcd.io/etcd/client/v3" imported but not used (typecheck)
"go.etcd.io/etcd/client/v3"
^
Error: Process completed with exit code 1. Code example or link to a public repository |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 13 replies
-
Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors. |
Beta Was this translation helpful? Give feedback.
-
Hello, I don't reproduce your problem: $ go version
go version go1.17.10 linux/amd64
$ golangci-lint version
golangci-lint has version 1.46.1 built from 044f0a17 on 2022-05-12T09:23:45Z
$ git clone [email protected]:apache/dubbo-go.git
Cloning into 'dubbo-go'...
remote: Enumerating objects: 49874, done.
remote: Counting objects: 100% (46/46), done.
remote: Compressing objects: 100% (35/35), done.
remote: Total 49874 (delta 17), reused 22 (delta 10), pack-reused 49828
Receiving objects: 100% (49874/49874), 86.32 MiB | 14.69 MiB/s, done.
Resolving deltas: 100% (31473/31473), done.
$ cd ./dubbo-go
$ golangci-lint run -v --timeout=5m
INFO [config_reader] Config search paths: [./ /home/ldez/sources/experimental/dubbo-go /home/ldez/sources/experimental /home/ldez/sources /home/ldez /home /]
INFO [config_reader] Used config file .golangci.yml
INFO [lintersdb] Active 4 linters: [govet ineffassign misspell staticcheck]
INFO [loader] Go packages loading at mode 575 (exports_file|files|types_sizes|compiled_files|deps|imports|name) took 1.801636414s
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 41.27123ms
INFO [linters context/goanalysis] analyzers took 0s with no stages
INFO [runner] Issues before processing: 169, after processing: 0
INFO [runner] Processors filtering stat (out/in): skip_files: 169/169, identifier_marker: 88/88, filename_unadjuster: 169/169, path_prettifier: 169/169, cgo: 169/169, skip_dirs: 169/169, exclude-rules: 1/88, nolint: 0/1, autogenerated_exclude: 88/169, exclude: 88/88
INFO [runner] processing took 6.346761ms with stages: identifier_marker: 2.874326ms, autogenerated_exclude: 1.03393ms, path_prettifier: 774.345µs, nolint: 619µs, exclude-rules: 549.199µs, skip_dirs: 448.873µs, cgo: 34.563µs, filename_unadjuster: 7.77µs, max_same_issues: 1.485µs, uniq_by_line: 469ns, exclude: 379ns, skip_files: 356ns, diff: 353ns, max_from_linter: 327ns, source_code: 276ns, max_per_file_from_linter: 258ns, path_shortener: 244ns, sort_results: 231ns, severity-rules: 221ns, path_prefixer: 156ns
INFO [runner] linters took 254.429781ms with stages: goanalysis_metalinter: 247.923216ms
INFO File cache stats: 0 entries of total size 0B
INFO Memory: 22 samples, avg is 62.1MB, max is 135.8MB
INFO Execution took 2.103353669s
My recommendations:
|
Beta Was this translation helpful? Give feedback.
-
Hi, I have a similar problem. I use the container image
The lib contains import (
"context"
"database/sql"
....
"github.com/dedalus-cis4u/dockerutil/v6"
) If I execute the golangci-lint locally it works fine. markus@markus-pc:~/workspace/testutils (master *=)$ make golangci-lint
golangci-lint run --concurrency=24 Unfortunately, it is not possible to share the source code of the project publicly. If there are any questions, I may be able to answer them through individual snippets. |
Beta Was this translation helpful? Give feedback.
-
I'm also seeing this issue:
I really wouldn't expect any of the linters I have enabled to complain about the go standard library Additionally, even if I update the import path to appease the linter (e.g. Is there a way to know which one of the linters is reporting this Thanks. |
Beta Was this translation helpful? Give feedback.
This comment has been hidden.
This comment has been hidden.
-
I have the same issue: "net/url" imported and not used (typecheck) my code doesn't even redefine "url" to possibly confuse linter. Only 2 appearances of "url" in the package are mentioned above |
Beta Was this translation helpful? Give feedback.
-
Getting this now with golangci-lint v1.61.0. It reports |
Beta Was this translation helpful? Give feedback.
-
https://golangci-lint.run/welcome/faq/#why-do-you-have-typecheck-errors |
Beta Was this translation helpful? Give feedback.
https://golangci-lint.run/welcome/faq/#why-do-you-have-typecheck-errors